@jamaine.murphy wrote:
... the text would be changed to either IE or CS depending on what is already in the attribute text field....
Not knowing what or how many possibilities there may be for "already" values, here's a suggested approach [untested]:
(defun C:ATTCHANGE (/ blkss attchanges n blk val)
(if (setq blkss (ssget '((0 . "INSERT"))))
(progn ; then
(setq attchanges '(("I.E." "C.S.") ("Manny" "Moe") ("blue" "green") ("27" "28")))
;; list of possible current values paired with what to change them to
(repeat (setq n (sslength blkss))
(setq blk (ssname blkss (setq n (1- n))))
(foreach tag '("SGL" "DBL")
(if ;; does an Attribute with that tag exist in the Block?
(not
(vl-catch-all-error-p (vl-catch-all-apply 'getpropertyvalue (list blk tag)))
;; [returns nil if Attribute exists, T if not]
); not
(progn ; then -- check/change its value
(setq val (getpropertyvalue blk tag)); current value
(if (assoc val attchanges) ; current value is in list of those to be changed
(setpropertyvalue blk tag (cadr (assoc val attchanges))); then -- change it
;;; [... set it to something else if current value is not in the list? ...] ; else
); if [change value]
); progn
); if [Attribute exists]
); foreach
); repeat
); progn
); if [selection]
(prin1)
)
From your description, I suspect maybe all the second items in the pairing sublists within the 'attchanges' list should be either "I.E." or "C.S.".
Note the commented-out something-else place-holder, in case you have a fallback value you want them set to if their current value is not in the list. As written, it would leave any such Attributes alone.
The selection filter at the top could include a Block name or names, if that can limit the selection to only Blocks that you know will always contain those two Attribute tags, eliminating the need to check whether an Attribute is present.
As written, it's case-sensitive about the current value, but it could be made to not have that limitation.
Kent Cooper, AIA