Jump to content

Update attribute with actual $FILENAME$ lisp


Recommended Posts

Posted

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

  • Replies 23
  • Created
  • Last Reply

Top Posters In This Topic

  • Lee Mac

    11

  • kam1967

    8

  • uddfl

    3

  • dbroada

    1

Popular Days

Top Posters In This Topic

Posted

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?

Posted

Yes, Lee. I need the actual filename (whatever it's named) to be used by the DRAWINGNAME attribute. Thank you.

Posted

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))

Posted

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!

Posted
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 :P

Posted

Ahh yes, I didn't put a regen in there... just add this at the very end (just before the last (princ):

 

(command "_regenall")

Posted

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))

Posted

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")

)

Posted

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.

Posted
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?
Posted

How would you write entupd into the routine that you've written then, Lee? I am intrigued.

Posted
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.
Posted

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))

Posted
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 :thumbsup:

Posted

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.

Posted

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! :)

Posted
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.

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...