You are on page 1of 2

(defun c:attchange ( / i l s x

)
;; Define function, declare local variable symbols.
;; To understand why variable declaration is important, see http://bit.ly/15
Qw104
(if ;; If we can retrieve a set of attributed blocks
(setq s ;; Assign the selection set pointer to variable 's'
(ssget "_X" ;; Search entire database (see http://bit.ly/137NmOJ for
more info)
'(
(0 . "INSERT") ;; Block References
(66 . 1) ;; Attributed
(2 . "*") ;; with name WD_MLRH (this assumes block is non-dy
namic)
)
) ;; end SSGET
) ;; end SETQ
(progn
;; Evaluate the following expressions and return the result
;; of the last expression evaluated. PROGN is used as a
;; wrapper function so that we can pass multiple expressions
;; to the IF function as a single argument constituting the
;; 'then' parameter.
(initget 6) ;; (+ 2 4): 2=prevent zero, 4=prevent negative
(if (setq x (getint "\nEnter first rung number: ")) ;; Prompt user f
or rung number > 0
(progn
;; See above explanation for PROGN
;; Construct an association list of attribute tags & values
;; to pass to the LM:setattributevalues function
(setq l
(cons
(cons "RUNGFIRST" (itoa x)) ;; => e.g. ("RUNGFIRST"
. "2")
;; Use a quoted literal list for the remaining tags/
values
;; as there are no expressions to be evaluated.
;; For an explanation of the apostrophe, see http://
bit.ly/1bW3rQK
'(
("RUNGCNT" . "20")
("RUNGDIST" . "1")
)
) ;; end CONS
) ;; end SETQ
;; The resulting list might look like this:
;; l = (("RUNGFIRST" . "2") ("RUNGCNT" . "20") ("RUNGDIST"
. "1"))
;;
;;
;;
;;

Repeat the following expressions a number of times
equal to the number of items in the selection set.
Note that the numerical argument for the repeat function
is only evaluated once and hence the integer index variab

le 'i'
;; will only be assigned a value once.
(repeat (setq i (sslength s))

[lst] Association list of ((<TAG> .. end PROGN ... (LM:SetAttributeValues (ssname s (setq i (1. Arguments: blk . <Value>) ..Lee Mac Sets the block attributes whose tags are found in the supplied assocation list to their associated values. ....... end REPEAT ) ... (princ "\nNo \"WD_MLRH\" blocks were found.. . . and association list of attribute tags/values to be s et. end IF ) .. ) Returns: nil (defun LM:SetAttributeValues ( blk lst / enx itm ) (if (= "ATTRIB" (cdr (assoc 0 (setq enx (entget (setq blk (entnext blk)))))) ) (if (setq itm (assoc (strcase (cdr (assoc 2 enx))) lst)) (progn (if (entmod (subst (cons 1 (cdr itm)) (assoc 1 enx) enx)) (entupd blk) ) (LM:SetAttributeValues blk lst) ) (LM:SetAttributeValues blk lst) ) ) ) (princ) . Call the LM:setattributevalues function with the bloc k entity name . Else no blocks were found.. Supress the return of the last evaluated expression ) ... .i))) l) ) .") ) .. end IF (princ) .. Set Attribute Values .....[ent] Block (Insert) Entity Name lst . end PROGN ) . end DEFUN . . . Suppress the return of any loading expressions .