kam1967 Posted February 5, 2009 Posted February 5, 2009 Hi, I wonder if anyone could tell me how I could write a script or a lisp to update an attribute called DRAWINGNAME within a titleblock called TITLE.DWG with an actual $FILENAME$. I am trying to update old titleblocks - ones that were not created with a FIELD concept in mind. Thank you in advance, Kameron Quote
Lee Mac Posted February 5, 2009 Posted February 5, 2009 I may be way off the mark here, but how I understand it is that you want to update titleblocks within old drawings so that the attribute named "DRAWINGNAME" contains the filename of the drawing. Am I correct? Quote
kam1967 Posted February 5, 2009 Author Posted February 5, 2009 Yes, Lee. I need the actual filename (whatever it's named) to be used by the DRAWINGNAME attribute. Thank you. Quote
Lee Mac Posted February 5, 2009 Posted February 5, 2009 Give this a shot {Untested} (defun c:dwgupd (/ ss eLst dNme aEnt aEntLst) (vl-load-com) (if (setq ss (ssget "X" (list (cons 0 "INSERT") (cons 2 "TITLE") (cons 66 1) (if (getvar "CTAB") (cons 410 (getvar "CTAB")) (cons 67 (- 1 (getvar "TILEMODE"))))))) (progn (setq eLst (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss))) dNme (vl-filename-base (getvar "DWGNAME"))) (foreach e eLst (setq aEnt (entnext e)) (while (not (eq "SEQEND" (cdadr (setq aEntLst (entget aEnt))))) (if (= "DRAWINGNAME" (cdr (assoc 2 aEntLst))) (entmod (subst (cons 1 dNme)(assoc 1 aEntLst) aEntLst))) (setq aEnt (entnext aEnt))))) (princ "\n<!> No Title Blocks Found <!> ")) (princ)) Quote
dbroada Posted February 5, 2009 Posted February 5, 2009 this sounds very familiar doesn't it Lee. Quote
kam1967 Posted February 5, 2009 Author Posted February 5, 2009 Excellent, Lee! You are so knowledgeable. Thank you! I just need it to regen now so that I will know the change has taken place. I will try to figure that out. Thanks again! Quote
Lee Mac Posted February 5, 2009 Posted February 5, 2009 this sounds very familiar doesn't it Lee. I've had so much practice writing routines for Block Attribute Updating that I could probably do it with my eyes shut now Dave Quote
Lee Mac Posted February 5, 2009 Posted February 5, 2009 Ahh yes, I didn't put a regen in there... just add this at the very end (just before the last (princ): (command "_regenall") Quote
Lee Mac Posted February 5, 2009 Posted February 5, 2009 i.e (defun c:dwgupd (/ ss eLst dNme aEnt aEntLst) (vl-load-com) (if (setq ss (ssget "X" (list (cons 0 "INSERT") (cons 2 "TITLE") (cons 66 1) (if (getvar "CTAB") (cons 410 (getvar "CTAB")) (cons 67 (- 1 (getvar "TILEMODE"))))))) (progn (setq eLst (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss))) dNme (vl-filename-base (getvar "DWGNAME"))) (foreach e eLst (setq aEnt (entnext e)) (while (not (eq "SEQEND" (cdadr (setq aEntLst (entget aEnt))))) (if (= "DRAWINGNAME" (cdr (assoc 2 aEntLst))) (entmod (subst (cons 1 dNme)(assoc 1 aEntLst) aEntLst))) (setq aEnt (entnext aEnt))))) (princ "\n<!> No Title Blocks Found <!> ")) (command "_regenall") (princ)) Quote
kam1967 Posted February 5, 2009 Author Posted February 5, 2009 Thank you! I finally figured out also, with this command in the location you suggested. Seems to do the trick also, but I think I'll use yours...more professional that way! (princ "\n No Title Blocks Found ")) (princ) (COMMAND "REGEN") ) Quote
Lee Mac Posted February 5, 2009 Posted February 5, 2009 No worries Glad it will save some time Cheers Lee Quote
CarlB Posted February 5, 2009 Posted February 5, 2009 Lee- Common practice is to follow up an "entmod" of an attribute with an "entupd" of the block name; this usually updates the changes without need for a regen. Although I've read even with an "entupd" in some cases a regen is still needed. Quote
uddfl Posted February 5, 2009 Posted February 5, 2009 Lee- Common practice is to follow up an "entmod" of an attribute with an "entupd" of the block name; this usually updates the changes without need for a regen. Although I've read even with an "entupd" in some cases a regen is still needed. If I understand Lee's code correctly, the reason why he's not using entupd is because he is not stopping to get the block entity name, he is going right to the attribute(s). That's how concise his routine is. Is this correct, Lee? Quote
kam1967 Posted February 5, 2009 Author Posted February 5, 2009 How would you write entupd into the routine that you've written then, Lee? I am intrigued. Quote
uddfl Posted February 5, 2009 Posted February 5, 2009 How would you write entupd into the routine that you've written then, Lee? I am intrigued.Try adding (entupd aEnt) after the entmod function and see if it works. Quote
Lee Mac Posted February 5, 2009 Posted February 5, 2009 I must admit, I don't normally use "entupd" to update atts, as it seems to cause an error sometimes, but try this: (defun c:dwgupd (/ ss eLst dNme aEnt aEntLst) (vl-load-com) (if (setq ss (ssget "X" (list (cons 0 "INSERT") (cons 2 "TITLE") (cons 66 1) (if (getvar "CTAB") (cons 410 (getvar "CTAB")) (cons 67 (- 1 (getvar "TILEMODE"))))))) (progn (setq eLst (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss))) dNme (vl-filename-base (getvar "DWGNAME"))) (foreach e eLst (setq aEnt (entnext e)) (while (not (eq "SEQEND" (cdadr (setq aEntLst (entget aEnt))))) (if (= "DRAWINGNAME" (cdr (assoc 2 aEntLst))) (progn (entmod (subst (cons 1 dNme)(assoc 1 aEntLst) aEntLst)) (entupd e))) (setq aEnt (entnext aEnt))))) (princ "\n<!> No Title Blocks Found <!> ")) (princ)) Quote
Lee Mac Posted February 5, 2009 Posted February 5, 2009 Try adding (entupd aEnt) after the entmod function and see if it works. You would also need a "progn" wrapper, as the IF will then contain more than one statement to be evaluated Quote
Lee Mac Posted February 5, 2009 Posted February 5, 2009 As quoted from ACAD Help file: Note If entupd is used on a nested entity (an entity within a block) or on a block that contains nested entities, some of the entities might not be regenerated. To ensure complete regeneration, you must invoke the REGEN command. Quote
kam1967 Posted February 5, 2009 Author Posted February 5, 2009 Thanks, Lee. I tested your routine and I got an extra right parenthesis error. I took away the other two on the right and it works fine now. (entmod (subst (cons 1 dNme)(assoc 1 aEntLst) aEntLst))) (entupd e) (setq aEnt (entnext aEnt))))) (princ "\n No Title Blocks Found ")) ;(command "_regenall") (princ)) Well, this has been most educational. Thanks for the input, everyone! Have a wonderful day, okay? Grab some zZzZ too! Quote
uddfl Posted February 5, 2009 Posted February 5, 2009 As quoted from ACAD Help file: Note If entupd is used on a nested entity (an entity within a block) or on a block that contains nested entities, some of the entities might not be regenerated. To ensure complete regeneration, you must invoke the REGEN command. Huh. I didn't know that. I've never had a problem using entupd on attributes, but I'll keep this in mind. Thanks. 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.