Deel 5: Uitleg complexere LISP-routine

;; (c)2018 NedCAD(defun attinc (/ number ent-name att-name att-data); Function NOT preceded with c:(princ"\nThis utility numbers selected blocks with increments of one by changing the first attribute value."); What it does, printed on the command line(setq number (getint"\nStarting number: ")); Ask for an integer, set variable number.(princ"\nSelect first block to number: "); After that, ask for a block.(while(setq ent-name (car(entsel""))); Select something, while, as long as something is selected.(if; Condition...(=(cdr(assoc0(entget ent-name)))"INSERT"); Is it a block?(if; If yes, next round.(and; Both conditions should be met(setq att-name (entnext ent-name)); Is there a next entity?(=(cdr(assoc0(entget att-name)))"ATTRIB"); Is that next entity an attribute?)(progn; Good! Then do the next...(setq att-data (entget att-name)); Retrieve all specs of that attribute...(setq att-data
(subst(cons1(itoa number))(assoc1 att-data) att-data); and replace attribute value with value of variable number.); A list with new attribute data,(entmod att-data); modify the entity and(entupd att-name); update it.(setq number (1+ number)); Ready and creating next new attribute value, number plus one.)(princ"\nThis block does not contain an attribute! "); Not good. If conditions are not met, print on the command line what went wrong...)(princ"\nThis entity is not a block! "); ditto)(princ"\nSelect a block or <Empty click or enter to finish>: "); What to select or what to do to get out of the while loop.)(princ); Finally suppressing LISP messages.);; For on_doc_load.lsp:; (defun c:attinc (/ attinc) (load "attinc") (attinc) (princ))

;; (c)2018 NedCAD
(defun attinc ( / number ent-name att-name att-data) ; Function NOT preceded with c:
(princ "\nThis utility numbers selected blocks with increments of one by changing the first attribute value.") ; What it does, printed on the command line
(setq number (getint "\nStarting number: ")) ; Ask for an integer, set variable number.
(princ "\nSelect first block to number: ") ; After that, ask for a block.
(while (setq ent-name (car (entsel ""))) ; Select something, while, as long as something is selected.
(if ; Condition...
(= (cdr (assoc 0 (entget ent-name))) "INSERT") ; Is it a block?
(if ; If yes, next round.
(and ; Both conditions should be met
(setq att-name (entnext ent-name)) ; Is there a next entity?
(= (cdr (assoc 0 (entget att-name))) "ATTRIB") ; Is that next entity an attribute?
)
(progn ; Good! Then do the next...
(setq att-data (entget att-name)) ; Retrieve all specs of that attribute...
(setq att-data
(subst (cons 1 (itoa number)) (assoc 1 att-data) att-data) ; and replace attribute value with value of variable number.
) ; A list with new attribute data,
(entmod att-data) ; modify the entity and
(entupd att-name) ; update it.
(setq number (1+ number)) ; Ready and creating next new attribute value, number plus one.
)
(princ "\nThis block does not contain an attribute! ") ; Not good. If conditions are not met, print on the command line what went wrong...
)
(princ "\nThis entity is not a block! ") ; ditto
)
(princ "\nSelect a block or <Empty click or enter to finish>: ") ; What to select or what to do to get out of the while loop.
)
(princ) ; Finally suppressing LISP messages.
)
;; For on_doc_load.lsp:
; (defun c:attinc (/ attinc) (load "attinc") (attinc) (princ))