Jump to content

Multiple Attribute change


Recommended Posts

I have about 500 drawings that I need to edit one part of.

 

There is a block in paperspace that is basically two seperate lines of text and a boarder. I need to edit one of the lines of text to say Jacobs Engineering. The block that it is on is Original-ESIZE and the tag for that specifc text is ORIGINAL.

 

I have tried to write a script to change all this and have not been successful is actually selecting the attribute (ORIGINAL). This is my script so far.

Open "specific drawing"

-attedit

y

Original-ESIZE

*

 

That is the part that I am stuck at. I don't know how to select anything by only using the command line. Is it possible? Or is there any other way of going about this. I don't want to have to open 500 drawings and make a single change.

 

I have tried looking everywhere and no one is asking this exact question. Please help.

Link to comment
Share on other sites

  • Replies 41
  • Created
  • Last Reply

Top Posters In This Topic

  • ReMark

    10

  • Lee Mac

    10

  • Bennymac777

    9

  • dbroada

    4

oh dear, I didn't spot this thread earlier.

 

Is you text "text" or is it an attribute? If it is text you should make the changes and save the changed block to a new file. This can then be inserted into all your drawings relatively easily with a script to update all the blocks.

 

If it is an attribute you are on the way but I won't be able to check until I'm back here tomorrow - I'm sorry but the sun beckons right now! 8)

Link to comment
Share on other sites

Hi Bennymac,

 

Try this - but try it first on copies of drawings - I don't want to be held responsible if you know what I mean.

 

It uses ObjectDBX, which can be temperamental from time to time, depending on the version that you are using.

 

;; Global Attribute Changer
;; Copyright (c) Lee McDonnell 11.06.2009
;; Credit to Tony Tanzillo, Tim Willey.

(defun c:MacAtt  (/ *error* Blk Att Attlst Val Shell fDir Dir acVer dbx dwLst Tag)
 (vl-load-com)

 ;; Error Handler

 (defun *error*  (e)
   (ObjRel (list Shell dbx *acad))
   (if (not (wcmatch (strcase e) "*BREAK,*CANCEL*,*EXIT*"))
     (princ (strcat "\n<< Error: " e " >>")))
   (princ))

 ;; Get Block

 (while
   (progn
     (setq Blk (getstring t "\nSpecify Block Name: "))
     (cond ((eq "" Blk) t)
           ((snvalid Blk) nil)
           (t (princ "\n** Invalid Block Name **")))))

 ;; Get Attribute List

 (if Blk
   (progn
     (setq blk (strcase blk))

 ; get Att

     (while
       (progn
         (setq Att (getstring
                     (strcat "\nSpecify Tag in Block: " Blk
                             " for Att Change [* to List] <Exit>: ")))
         (cond ((eq "" Att) nil)
               ((eq (chr 42) Att)
                (princ (strcat "\n   " (Pad "Tag" 46 30) "Value"))
                (if Attlst
                  (foreach x  Attlst
                    (princ (strcat "\n" (Pad (car x) 46 30) (cdr x))))
                  (princ "\n   -- None --")))
               ((snvalid Att)
                (setq  Val (getstring t
                             (strcat "\nSpecify New Attribute Value for Tag: " Att " : ")))
                (setq Attlst (cons (cons (strcase Att) Val) Attlst)))
               (t (princ "\n** Invalid Attribute Tag **")))))

     (if Attlst
       (progn

         ;; Get Directory

         (setq *acad (vlax-get-acad-object)
               Shell (vla-getInterfaceObject *acad "Shell.Application")
               fDir  (vlax-invoke-method Shell 'BrowseForFolder
                       (vla-get-HWND *acad) "Select Directory: " 0))
         (if fDir
           (progn
             (setq Dir
                    (vlax-get-property
                      (vlax-get-property fDir 'Self) 'Path))
             (if (not (eq "\\" (substr Dir (strlen Dir))))
               (setq Dir (strcat Dir "\\")))
             (princ "\nProcessing...")

             ;; Iterate Drawings

             (foreach dwg  (setq dwLst
                                  (mapcar
                                    (function
                                      (lambda (x)
                                        (strcat Dir x)))
                                    (vl-directory-files Dir "*.dwg" 1)))

               (vlax-for doc (vla-get-Documents *acad)
                 (and (eq (strcase (vla-get-fullname doc)) (strcase dwg))
                      (setq dbx doc)))

               (and (not dbx)
                    (setq dbx
                      (vlax-create-object
                        (if (< (setq acVer (atoi (getvar "ACADVER"))) 16)
                          "ObjectDBX.AxDbDocument"
                          (strcat "ObjectDBX.AxDbDocument." (itoa acVer))))))

               (if (not (vl-catch-all-error-p
                          (vl-catch-all-apply 'vla-open (list dbx dwg))))

                 (progn

               (vlax-for lay  (vla-get-Layouts dbx)
                 (vlax-for Obj  (vla-get-Block lay)
                   (if (and (eq (vla-get-ObjectName Obj) "AcDbBlockReference")
                            (eq (strcase (vla-get-Name Obj)) blk))
                     (foreach Att  (vlax-safearray->list
                                     (vlax-variant-value
                                       (vla-getAttributes Obj)))
                       (if (setq Tag (assoc (strcase (vla-get-TagString Att)) attlst))
                         (vla-put-TextString Att (cdr Tag)))))))

               (vla-saveas dbx dwg)))
               (princ (chr 46)))
             (princ (strcat "\n<< " (rtos (length dwLst) 2 0) " Drawings Processed >>")))
           (princ "*Cancel*")))
       (princ "\n<< No Attributes Specified >>")))
   (princ "\n<< No Block Specified >>"))

 ;; Garbage Collection

 (ObjRel (list Shell dbx *acad))
 (gc)
 (princ))

;; Release Objects ~ Requires List of Variables

(defun ObjRel  (lst)
 (mapcar
   (function
     (lambda (x)
       (if (and (eq (type x) 'VLA-OBJECT)
                (not (vlax-object-released-p x)))
         (vl-catch-all-apply
           'vlax-release-object
           (list x)))))
   lst))

;; Text Padder

(defun Pad  (Str Chc Len)
 (while (< (strlen Str) Len)
   (setq Str (strcat Str (chr Chc))))
 Str)

Link to comment
Share on other sites

Your script file would have to include the following:

 

-attedit

n

n

(blank space to mimic hitting the Enter key)

(second blank space)

(third blank space)

specify text string to change on this line

specify new text string

 

Now all you have to do is add the ability to open the drawing at the front end and save/close the drawing at the back end. There's your script file.

Link to comment
Share on other sites

Yes, you're quite right. Kind of like a macro vs. LISP. Both can get the job done but one is more elegant than the other.

Link to comment
Share on other sites

How do I go about running the lisp. I copied it into notepad and saved it as a lsp file. I loaded it into autocad. Am I going to have to open each drawing and run this. I am a little bit confused on how to run the lisp file.

Link to comment
Share on other sites

I am using this method because it is going to be easier right now. I ran this script on a drawing and in AutoCAD2006 FullVersion it found 74 attributes so it was able to find the attribute that I needed. Then I tried it on my AutoCAD2009LT and it only found 31 attributes so it was not able to find the attribute that I needed. Is there a system variable that I need to change? Do you know what is going on?

 

Your script file would have to include the following:

 

-attedit

n

n

(blank space to mimic hitting the Enter key)

(second blank space)

(third blank space)

specify text string to change on this line

specify new text string

 

Now all you have to do is add the ability to open the drawing at the front end and save/close the drawing at the back end. There's your script file.

Link to comment
Share on other sites

How do I go about running the lisp. I copied it into notepad and saved it as a lsp file. I loaded it into autocad. Am I going to have to open each drawing and run this. I am a little bit confused on how to run the lisp file.

 

Sorry, I should have explained more.

 

Save and load the LISP as normal.

 

Open a new drawing (doesn't have to be one of the drawings that needs editing).

 

Run the LISP by typing MacAtt.

 

the rest should follow :)

Link to comment
Share on other sites

I would think that finding the attribute you're looking to change would be easy since the script calls for the exact text string to change.

Link to comment
Share on other sites

if you are using plain LT you won't be able to run a LISP.

 

If you answer my previous question I should be able to point you the right way.

Link to comment
Share on other sites

I'm confused. Did the OP use the LISP program or a script? If he tried the LISP program in LT it would have/should have bombed. He reports finding 31 attributes. That makes me think he used a script. Someone please unconfuse me. Thank you. And have a pleasent day.

Link to comment
Share on other sites

I'm confused. Did the OP use the LISP program or a script? If he tried the LISP program in LT it would have/should have bombed. He reports finding 31 attributes. That makes me think he used a script. Someone please unconfuse me. Thank you. And have a pleasent day.

 

I was under the impression he had access to the full version to try the LISP...

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