Jump to content

help with macro


atb1984

Recommended Posts

I've got a block that's used for titleblock information with attributes including drawing title, date, drawn by, checked by, etc. Is there a macro or a lisp routine that can be used to automatically change one attribute in a drawing. I need to change the "Approved By" attribute with the same initials in about 100 drawings, and I'm trying to find the quickest way to do this without actually having to type the initials in every drawing. I'm familiar with writing lisp routines, but not at all with visual basic and macros.

 

I'm running autocad 2004

 

Thanks in advance for any help.

Link to comment
Share on other sites

In LISP, could be done like this:

 

(defun c:upd (/ ss att aLst)
 (if (setq ss (ssget "X" (list (cons 0 "INSERT") (cons 2 "[b][color=Red]BLOCKNAME[/color][/b]")
   (cons 66 1) (if (getvar "CTAB")(cons 410 (getvar "CTAB"))
      (cons 67 (- 1 (getvar "TILEMODE")))))))
   (progn
     (foreach x (mapcar 'cadr (ssnamex ss))
   (setq att (entnext x))
   (while (not (eq "SEQEND" (cdadr (setq aLst (entget att)))))
     (if (= "[color=Red][b]APPROVED_BY[/b][/color]" (cdr (assoc 2 aLst)))
       (entmod (subst (cons 1 "[b][color=Red]ABC[/color][/b]") (assoc 1 aLst) aLst)))
     (setq att (entnext att)))))
   (princ "\n<!> No Block Found <!>"))
 (command "_regenall")
 (princ))

 

Change the highlighted parts to suit.

 

I assume you mean "approved_by" instead of "approved by" as tags can't contain spaces. :thumbsup:

Link to comment
Share on other sites

Thanks for the reply, this routine works well and is a great starting point.

 

If I wanted to edit several attributes using this command, what part of the routine would change?

 

For example, to edit "checked_by" and "approved_by" fields.

 

Or would I have to create a second routine and use two commands to execute it in a dwg?

Link to comment
Share on other sites

Just change the IF to a COND like this:

 

(defun c:upd (/ ss att aLst)
 (if (setq ss (ssget "X" (list (cons 0 "INSERT") (cons 2 "[color=Red][b]BLOCKNAME[/b][/color]")
   (cons 66 1) (if (getvar "CTAB")(cons 410 (getvar "CTAB"))
      (cons 67 (- 1 (getvar "TILEMODE")))))))
   (progn
     (foreach x (mapcar 'cadr (ssnamex ss))
   (setq att (entnext x))
   (while (not (eq "SEQEND" (cdadr (setq aLst (entget att)))))
     (cond ((= "[b][color=Red]APPROVED_BY[/color][/b]" (cdr (assoc 2 aLst)))
        (entmod (subst (cons 1 "[color=Red][b]ABC[/b][/color]") (assoc 1 aLst) aLst)))
       ((= "[b][color=Red]CHECKED_BY[/color][/b]" (cdr (assoc 2 aLst)))
        (entmod (subst (cons 1 "[color=Red][b]DEF[/b][/color]") (assoc 1 aLst) aLst))))
     (setq att (entnext att)))))
   (princ "\n<!> No Block Found <!>"))
 (command "_regenall")
 (princ))

Link to comment
Share on other sites

A couple of extra helps, you mention 100 dwgs you can create a script to open the dwgs and run automaticaly. You will be suprised how quick this happens.

 

open dwg1 (load "upd") upd close Y

open dwg2 (load "upd") upd close Y

 

if you put the upd.lsp in your startups then

open dwg1 upd close Y

 

Also if you need to vary the names or details to be changed maybe get it to read a data file this way you dont alter the lisp code all the time.

approved_by FRED

checked_by george

Revision 1

 

txt file

FRED

George

1

 

just add the read file before the if in lee's code

Link to comment
Share on other sites

A couple of extra helps, you mention 100 dwgs you can create a script to open the dwgs and run automaticaly. You will be suprised how quick this happens.

 

open dwg1 (load "upd") upd close Y

open dwg2 (load "upd") upd close Y

 

if you put the upd.lsp in your startups then

open dwg1 upd close Y

 

Also if you need to vary the names or details to be changed maybe get it to read a data file this way you dont alter the lisp code all the time.

approved_by FRED

checked_by george

Revision 1

 

txt file

FRED

George

1

 

just add the read file before the if in lee's code

 

Nice one BiGAl, some great advice. :thumbsup:

Link to comment
Share on other sites

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