pmxcad Posted August 5, 2017 Posted August 5, 2017 Hello, I found a lisp (lee Mac) that can edit the attributes in nested blocks. Only this routine updates all the nested blocks in the drawing. I just want to update the nested blocks in one selected block. How can the code be modified so that only the attributes of nested blocks in a selected block are modified? (defun c:nAttEdit ( / _UpdateNestedAttributes data ent ) (setq data '( ("TAG1" . "A") ("ID" . "01/12/2011") ("ADRESS" . "FOR REVIEW") ("CODE" . "MAL") ("ROOMNR" . "01/12/2011") ) ) (defun _UpdateNestedAttributes ( parent data / obj ) (if (setq obj (tblobjname "BLOCK" parent)) (while (setq obj (entnext obj)) (if (and (eq "INSERT" (cdr (assoc 0 (entget obj)))) (= 1 (cdr (assoc 66 (entget obj)))) ) (LM:SetAttributeValues obj data) ) ) ) ) (while (progn (setvar 'ERRNO 0) (setq ent (car (entsel "\nSelect Block: "))) (cond ( (= 7 (getvar 'ERRNO)) (princ "\nMissed, try again.") ) ( (eq 'ENAME (type ent)) (if (eq "INSERT" (cdr (assoc 0 (entget ent)))) (_UpdateNestedAttributes (cdr (assoc 2 (entget ent))) data) (princ "\nSelected Object is not a Block.") ) ) ) ) ) (command "_.regen") (princ) ) ;; Set Attribute Values - Lee Mac ;; Sets the block attributes whose tags are found in the supplied ;; association list to their associated values. (defun LM:SetAttributeValues ( block lst / elist item ) (if (eq "ATTRIB" (cdr (assoc 0 (setq elist (entget (setq block (entnext block))) ) ) ) ) (if (setq item (assoc (strcase (cdr (assoc 2 elist))) lst)) (progn (if (setq elist (entmod (subst (cons 1 (cdr item)) (assoc 1 elist) elist))) (entupd (cdr (assoc -1 elist))) ) (LM:SetAttributeValues block lst) ) (LM:SetAttributeValues block lst) ) ) ) Thanks in advance test2.dwg Quote
Lee Mac Posted August 5, 2017 Posted August 5, 2017 Assuming you mean that you wish to update the nested attribute values for a single selected block reference, this is not possible. Any changes to the block definition will be automatically reflected across all references of the block definition. To achieve your request you would need to duplicate the block definition and change the nested attribute values in the duplicate before assigning the duplicated block definition to the selected reference. Quote
pmxcad Posted August 6, 2017 Author Posted August 6, 2017 Of course. The block is adjusted so that applies to all blocks with the same name. Or you must explode the block. Then this routine works fine. Thanks Lee Quote
Emmanuel Delay Posted June 13, 2022 Posted June 13, 2022 Is this still impossible? Same question. If anyone happened to solve this or find a solution somewhere... Quote
exceed Posted June 14, 2022 Posted June 14, 2022 15 hours ago, Emmanuel Delay said: Is this still impossible? Same question. If anyone happened to solve this or find a solution somewhere... that nAttEdit code works. what's your problem. Quote
Emmanuel Delay Posted June 14, 2022 Posted June 14, 2022 Now I think of it; this is not a LISP issue; you just can't do it in Autocad. Unless I'm missing something. So, block "myblock" contains a block "B". B has attributes. The question is: can you change the attributes of block B, but just for 1 instance of myblock? What nAttEdit does, is change the attributes of B for all instances of myblock. Again ... as you would expect from Autocad attedit.dwg Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.