Jump to content

Update title block attributes in multiple drawings


t357

Recommended Posts

  • Replies 144
  • Created
  • Last Reply

Top Posters In This Topic

  • Lee Mac

    58

  • au-s

    23

  • JeepMaster

    9

  • wakibd

    7

You have the option to enter a Block Name, type Name when it prompts you to select a block :)

 

 

yes Sir!

 

I noticed :)

Allthough if I have several blocks and I can call them with different commands :)

I thouight it could be possible.. :)

 

 

 

Number2 is:

 

If I want to batch-run this lisp on several files it is cool to have this previous solution with the taglist which I edit the attributes once with attedit, then the edited attributes are applied to the

same blockname in several selected drawings... :)

 

I have a batch-lisp but I if I use your lisp which is working great on one drawing it will open attribute selection each time a file is opening.

 

I have a batch-lisp from afralisp that writes a scr file and executes it :)

Link to comment
Share on other sites

I suppose you could use this, if the Block Name section at the top is nil, it will revert back to the LISP as previously posted, else it will use the block name supplied:

 

[i][color=#990099];;; =============== AttChg.lsp ===============[/color][/i]
[i][color=#990099];;; [/color][/i]
[i][color=#990099];;;   FUNCTION: AttChg[/color][/i]
[i][color=#990099];;;   Will synchronise Attributes in Multiple[/color][/i]
[i][color=#990099];;;   Block Instances.[/color][/i]
[i][color=#990099];;; [/color][/i]
[i][color=#990099];;;   AUTHOR:[/color][/i]
[i][color=#990099];;;   Lee McDonnell (Lee Mac)[/color][/i]
[i][color=#990099];;;   (Contact at CADTutor.net, TheSwamp.org)[/color][/i]
[i][color=#990099];;;   10th June 2009[/color][/i]
[i][color=#990099];;; [/color][/i]
[i][color=#990099];;; ==========================================[/color][/i]

[b][color=RED]([/color][/b][b][color=BLUE]defun[/color][/b] c:AttChg [b][color=RED]([/color][/b][b][color=BLUE]/[/color][/b] *error* blkNme tdef bTest attlst[b][color=RED])[/color][/b]
 [b][color=RED]([/color][/b][b][color=BLUE]vl-load-com[/color][/b][b][color=RED])[/color][/b]

 [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] blkNme [b][color=#ff00ff]"TEST BLOCK"[/color][/b][b][color=RED])[/color][/b]  [i][color=#990099]; <<--- Optional Block Name Entry[/color][/i]

 [b][color=RED]([/color][/b][b][color=BLUE]defun[/color][/b] *error* [b][color=RED]([/color][/b]e[b][color=RED])[/color][/b]
   [b][color=RED]([/color][/b][b][color=BLUE]if[/color][/b] ocm [b][color=RED]([/color][/b][b][color=BLUE]setvar[/color][/b] [b][color=#ff00ff]"CMDECHO"[/color][/b] ocm[b][color=RED])[/color][/b][b][color=RED])[/color][/b]
   [b][color=RED]([/color][/b][b][color=BLUE]if[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]not[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]wcmatch[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]strcase[/color][/b] e[b][color=RED])[/color][/b] [b][color=#ff00ff]"*CANCEL*,*EXIT*"[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
     [b][color=RED]([/color][/b][b][color=BLUE]princ[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]strcat[/color][/b] [b][color=#ff00ff]"\n<< Error: "[/color][/b] e [b][color=#ff00ff]" >>"[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
   [b][color=RED]([/color][/b][b][color=BLUE]princ[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
 [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] ocm [b][color=RED]([/color][/b][b][color=BLUE]getvar[/color][/b] [b][color=#ff00ff]"CMDECHO"[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
 [b][color=RED]([/color][/b][b][color=BLUE]setvar[/color][/b] [b][color=#ff00ff]"CMDECHO"[/color][/b] [b][color=#009900]0[/color][/b][b][color=RED])[/color][/b]
 
 [b][color=RED]([/color][/b][b][color=BLUE]if[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]not[/color][/b] blkNme[b][color=RED])[/color][/b]
   [b][color=RED]([/color][/b][b][color=BLUE]while[/color][/b]
     [b][color=RED]([/color][/b][b][color=BLUE]progn[/color][/b]
       [b][color=RED]([/color][/b][b][color=BLUE]initget[/color][/b] [b][color=#ff00ff]"Name"[/color][/b][b][color=RED])[/color][/b]
       [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] blkNme
              [b][color=RED]([/color][/b][b][color=BLUE]entsel[/color][/b] [b][color=#ff00ff]"\nSelect Block or [Name]: "[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
       [b][color=RED]([/color][/b][b][color=BLUE]cond[/color][/b]
         [b][color=RED]([/color][/b][b][color=RED]([/color][/b][b][color=BLUE]and[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vl-consp[/color][/b] blkNme[b][color=RED])[/color][/b]
               [b][color=RED]([/color][/b][b][color=BLUE]eq[/color][/b] [b][color=#ff00ff]"INSERT"[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]cdr[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]assoc[/color][/b] [b][color=#009900]0[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]entget[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]car[/color][/b] blkNme[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
               [b][color=RED]([/color][/b][b][color=BLUE]eq[/color][/b] [b][color=#009900]1[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]cdr[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]assoc[/color][/b] [b][color=#009900]66[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]entget[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]car[/color][/b] blkNme[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
          [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] blkNme [b][color=RED]([/color][/b][b][color=BLUE]cdr[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]assoc[/color][/b] [b][color=#009900]2[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]entget[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]car[/color][/b] blkNme[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
          [b][color=BLUE]nil[/color][/b][b][color=RED])[/color][/b] [i][color=#990099]; Exit Loop[/color][/i]
         [b][color=RED]([/color][/b][b][color=RED]([/color][/b][b][color=BLUE]eq[/color][/b] [b][color=DARKRED]'[/color][/b]STR [b][color=RED]([/color][/b][b][color=BLUE]type[/color][/b] blkNme[b][color=RED])[/color][/b][b][color=RED])[/color][/b]
          [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] blkNme [b][color=RED]([/color][/b][b][color=BLUE]getstring[/color][/b] [b][color=BLUE]t[/color][/b] [b][color=#ff00ff]"\nSpecify Block Name: "[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
          [b][color=RED]([/color][/b][b][color=BLUE]cond[/color][/b] [b][color=RED]([/color][/b][b][color=RED]([/color][/b][b][color=BLUE]and[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] tdef [b][color=RED]([/color][/b][b][color=BLUE]tblsearch[/color][/b] [b][color=#ff00ff]"BLOCK"[/color][/b] blkNme[b][color=RED])[/color][/b][b][color=RED])[/color][/b]
                      [b][color=RED]([/color][/b][b][color=BLUE]eq[/color][/b] [b][color=#009900]2[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]logand[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]cdr[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]assoc[/color][/b] [b][color=#009900]70[/color][/b] tdef[b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=#009900]2[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
                 [b][color=BLUE]nil[/color][/b][b][color=RED])[/color][/b] [i][color=#990099]; Exit Loop[/color][/i]
                [b][color=RED]([/color][/b][b][color=RED]([/color][/b][b][color=BLUE]tblsearch[/color][/b] [b][color=#ff00ff]"BLOCK"[/color][/b] blkNme[b][color=RED])[/color][/b]
                 [b][color=RED]([/color][/b][b][color=BLUE]princ[/color][/b] [b][color=#ff00ff]"\n<< Block Contains No Attributes >>"[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
                [b][color=RED]([/color][/b][b][color=BLUE]t[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]princ[/color][/b] [b][color=#ff00ff]"\n<< Block Not Found >>"[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] [i][color=#990099]; Keep in Loop[/color][/i]
         [b][color=RED]([/color][/b][b][color=BLUE]t[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]princ[/color][/b] [b][color=#ff00ff]"\nMissed, Try Again..."[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
 
 [b][color=RED]([/color][/b][b][color=BLUE]if[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] ss
       [b][color=RED]([/color][/b][b][color=BLUE]ssget[/color][/b] [b][color=#ff00ff]"_X"[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]list[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]cons[/color][/b] [b][color=#009900]0[/color][/b] [b][color=#ff00ff]"INSERT"[/color][/b][b][color=RED])[/color][/b]
                         [b][color=RED]([/color][/b][b][color=BLUE]cons[/color][/b] [b][color=#009900]2[/color][/b] blkNme[b][color=RED])[/color][/b]
                         [b][color=RED]([/color][/b][b][color=BLUE]cons[/color][/b] [b][color=#009900]66[/color][/b] [b][color=#009900]1[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
   [b][color=RED]([/color][/b][b][color=BLUE]progn[/color][/b]
     [b][color=RED]([/color][/b][b][color=BLUE]initdia[/color][/b] [b][color=#009900]1[/color][/b][b][color=RED])[/color][/b]
     [b][color=RED]([/color][/b][b][color=BLUE]vl-cmdf[/color][/b] [b][color=#ff00ff]"_.attedit"[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] bTest [b][color=RED]([/color][/b][b][color=BLUE]ssname[/color][/b] ss [b][color=#009900]0[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
     [b][color=RED]([/color][/b][b][color=BLUE]foreach[/color][/b] att [b][color=RED]([/color][/b][b][color=BLUE]vlax-safearray->list[/color][/b]
                    [b][color=RED]([/color][/b][b][color=BLUE]vlax-variant-value[/color][/b]
                      [b][color=RED]([/color][/b][b][color=BLUE]vla-getAttributes[/color][/b]
                        [b][color=RED]([/color][/b][b][color=BLUE]vlax-ename->vla-object[/color][/b] bTest[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
       [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] attlst
         [b][color=RED]([/color][/b][b][color=BLUE]cons[/color][/b]
           [b][color=RED]([/color][/b][b][color=BLUE]cons[/color][/b]
             [b][color=RED]([/color][/b][b][color=BLUE]vla-get-TagString[/color][/b] att[b][color=RED])[/color][/b]
               [b][color=RED]([/color][/b][b][color=BLUE]vla-get-TextString[/color][/b] att[b][color=RED])[/color][/b][b][color=RED])[/color][/b] attlst[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
     [b][color=RED]([/color][/b][b][color=BLUE]foreach[/color][/b] Obj [b][color=RED]([/color][/b][b][color=BLUE]mapcar[/color][/b] [b][color=DARKRED]'[/color][/b][b][color=BLUE]vlax-ename->vla-object[/color][/b]
                    [b][color=RED]([/color][/b][b][color=BLUE]mapcar[/color][/b] [b][color=DARKRED]'[/color][/b][b][color=BLUE]cadr[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]ssnamex[/color][/b] ss[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
       [b][color=RED]([/color][/b][b][color=BLUE]foreach[/color][/b] Att [b][color=RED]([/color][/b][b][color=BLUE]vlax-safearray->list[/color][/b]
                      [b][color=RED]([/color][/b][b][color=BLUE]vlax-variant-value[/color][/b]
                        [b][color=RED]([/color][/b][b][color=BLUE]vla-getAttributes[/color][/b] Obj[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
         [b][color=RED]([/color][/b][b][color=BLUE]if[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] Tag [b][color=RED]([/color][/b][b][color=BLUE]assoc[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vla-get-TagString[/color][/b] Att[b][color=RED])[/color][/b] attlst[b][color=RED])[/color][/b][b][color=RED])[/color][/b]
           [b][color=RED]([/color][/b][b][color=BLUE]vla-put-TextString[/color][/b] Att [b][color=RED]([/color][/b][b][color=BLUE]cdr[/color][/b] Tag[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
     [b][color=RED]([/color][/b][b][color=BLUE]princ[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]strcat[/color][/b] [b][color=#ff00ff]"\n<< "[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]rtos[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]sslength[/color][/b] ss[b][color=RED])[/color][/b] [b][color=#009900]2[/color][/b] [b][color=#009900]0[/color][/b][b][color=RED])[/color][/b]
                    [b][color=#ff00ff]" Block Instances Updated >>"[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
   [b][color=RED]([/color][/b][b][color=BLUE]princ[/color][/b] [b][color=#ff00ff]"\n<< No Block Instances Found in Drawing >>"[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
 [b][color=RED]([/color][/b][b][color=BLUE]setvar[/color][/b] [b][color=#ff00ff]"CMDECHO"[/color][/b] ocm[b][color=RED])[/color][/b]
 [b][color=RED]([/color][/b][b][color=BLUE]princ[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]

Link to comment
Share on other sites

That's great sir!

Thank you...

 

Can you maybe enlight my path here and tell me some tip regarding batch process.

If I run this lisp with batchlisp (see below) I need to fill the new values each time a new drawing opens.

 

How can I change attributes in one drawing which then, is applied on all chosen drawings I choose with the batch lisp.

Shall I take a closer look at the write-line output and manipulate it? Is it the easiest way?

 

This is my batch-lisp from afralisp:

 

(defun c:AtchgMulti  (/ flag thelist thedir nfiles thefile fn ctr dname)
;set the flag
(setq flag T)
;check Doslib is loaded
(if (not (member "doslib17.arx" (arx)))
 (progn
   (if (findfile "doslib17.arx")
     (arxload "doslib17")
   (progn
     (alert "DosLib not installed")
     (setq flag nil)
   );progn
  );if
 );progn
);if
;if DosLib is installed and loaded
(if flag 
;do the following


 (progn
 (setq thelist (dos_getfilem "Choose Files:"  "" "DWG Files (*.dwg)|*.dwg"))
;retrieve the directory
 (setq thedir (car thelist))
;retrieve the file names
 (setq thelist (cdr thelist))
;get the number of files
 (setq nfiles (length thelist))
 (setq thefile (strcat (dos_tempdir) "temp.scr"))

     (setq fn (open thefile "w"))
      (setq ctr 0)
       (repeat nfiles
   (setq dname (nth ctr thelist))
       (write-line
         (strcat "open \"" thedir dname "\" (load \"K:/Attchg.lsp\") (c:Attchg) close \"Y\"")
         fn)
  (setq ctr (1+ ctr))
 );end repeat


     (close fn)
 (setvar "cmdecho" 0)
     (command "_script" thefile)
   (princ "\n<!> Done <!>")
 );; end progn
 );; end if

 (princ)
 );;; end defun

 

Therefor I fell for your first version that can be used to batch update in chosen drawings.

I could for example write-lines and make "new tag-list" as you had in your previous example?

Is that a way to go?

Link to comment
Share on other sites

That's great sir!

Thank you...

 

Can you maybe enlight my path here and tell me some tip regarding batch process.

If I run this lisp with batchlisp (see below) I need to fill the new values each time a new drawing opens.

 

How can I change attributes in one drawing which then, is applied on all chosen drawings I choose with the batch lisp.

Shall I take a closer look at the write-line output and manipulate it? Is it the easiest way?

 

This is my batch-lisp from afralisp:

 

(defun c:AtchgMulti  (/ flag thelist thedir nfiles thefile fn ctr dname)
;set the flag
(setq flag T)
;check Doslib is loaded
(if (not (member "doslib17.arx" (arx)))
 (progn
   (if (findfile "doslib17.arx")
     (arxload "doslib17")
   (progn
     (alert "DosLib not installed")
     (setq flag nil)
   );progn
  );if
 );progn
);if
;if DosLib is installed and loaded
(if flag 
;do the following


 (progn
 (setq thelist (dos_getfilem "Choose Files:"  "" "DWG Files (*.dwg)|*.dwg"))
;retrieve the directory
 (setq thedir (car thelist))
;retrieve the file names
 (setq thelist (cdr thelist))
;get the number of files
 (setq nfiles (length thelist))
 (setq thefile (strcat (dos_tempdir) "temp.scr"))

     (setq fn (open thefile "w"))
      (setq ctr 0)
       (repeat nfiles
   (setq dname (nth ctr thelist))
       (write-line
         (strcat "open \"" thedir dname "\" (load \"K:/Attchg.lsp\") (c:Attchg) close \"Y\"")
         fn)
  (setq ctr (1+ ctr))
 );end repeat


     (close fn)
 (setvar "cmdecho" 0)
     (command "_script" thefile)
   (princ "\n<!> Done <!>")
 );; end progn
 );; end if

 (princ)
 );;; end defun

Therefor I fell for your first version that can be used to batch update in chosen drawings.

I could for example write-lines and make "new tag-list" as you had in your previous example?

Is that a way to go?

 

Are you looking to update multiple blocks, or just one block with multiple attributes? Because my old LISP as posted should accomplish the task.

Link to comment
Share on other sites

Are you looking to update multiple blocks, or just one block with multiple attributes? Because my old LISP as posted should accomplish the task.

 

One block with multiple attributes. The thing is that it works allright but when I run the batch lisp the AttChg command needs to be done each time a drawing opens. It can be left as it is beacause it is working perfectly on one drawing.

The problems accours when I batch-run it. When I batch-run it I would like the lisp to change attributes in one block and then apply it to chosen drawings which I choose with my batch lisp.

 

Therefore I was looking at previous solution with command atest there you have taglist. I was wondering if it was possible to create a lisp which writes to a text file the values changed and then apply only changed values to the same block in drawings chosen by a batch process.

 

Do you understand more or less what Im after?

Thanx Sir!

Link to comment
Share on other sites

I'm not sure what you are getting at with the Text File, but if you are listing all the attribute changes in the Text File, why not just list them in the LISP and make life easier:

 

(defun c:AttChg2 (/ Taglist BlkNme ss Tag)
 (vl-load-com)

 (setq Taglist '(("TAG1" . "VAL1")
                 ("TAG2" . "VAL2"))
       BlkNme "TEST BLOCK")

 (if (setq ss (ssget "_X" (list (cons 0 "INSERT")
                                (cons 2 BlkNme)
                                (cons 66 1))))
   (foreach Blk (mapcar 'vlax-ename->vla-object
                  (mapcar 'cadr (ssnamex ss)))
     (foreach Att (vlax-safearray->list
                    (vlax-variant-value
                      (vla-getAttributes Blk)))
       (if (setq Tag (assoc (vla-get-TagString Att) Taglist))
         (vla-put-TextString Att (cdr Tag))))))
 (princ))

 

^^ this should be quicker than the atest.lsp

Link to comment
Share on other sites

Exactly what I was looking for ...

But here the user can't change the values of attributes him/herself.

It needs to be done via lisp, you need to enter the lisp and specify what you need to change and then run it.

 

The little thing I want is for the user to change the values himself (maybe with attedit or DCl-box as I asked before and thats fine :) ) and then run this lisp on multiple drawings.

 

I can do it with this lisp above but here the user needs to access the lisp and fill out the tags etc ...

I want the user at my office to fill the tags etc him/herself (as I wanted with attedit) and then apply it to, say 50 drawings with a batch-process.

The problem is that when I run batch-lisp it opens attedit for each drawing.

The lisp above that you wrote is good cause it doesnt open attedit and can be ran throughout 50 drawings. The trick is that it needs to be prepared and I want the user to change attribute values and apply those to let say 50 drawings

Link to comment
Share on other sites

(defun c:changeatt ()
 (if ATTribute    (progn
     (setq tempdir (dos_tempdir)
    file   (open (strcat tempdir "changeattributes.att") "w")
    index  0
     )
     (repeat (length ATTribute)
(write-line (nth index ATTribute) file)
(write-line (nth index value) file)
(setq index (+ 1 index))
     )
     (close file)
   )
 )
 (princ)
)

 

I dont kniow .. I waas trying earlier with somethibng like this ...

Just the beginning...

Here I write a lisp that writes a file changeattributes.att which stores every changed attribute.

 

Then I was thinking of a lisp that reads that file and put the attribute values to let say 50 drawings...

 

But please, dont bother with that code ... it can be done otherwise as you are the expart :)

 

 

if its too much I dont know :) ... then you can just advise me

Link to comment
Share on other sites

Try this, I am new to ObjectDBX so this may not work, but its worth a shot anyway.

 

Try it first on copies of drawings if you know what I mean. Also, save the initial drawing before running the LISP.

 

With this LISP, you can Select a BLOCK in the initial drawing, then select a folder of drawings to iterate through.

 

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

(defun c:MacAtt (/ *error* *acad vl ov blkNme tdef
                  ss bTest attlst Shell  fDir Dir
                  acVer dbx dwLst)
 (vl-load-com)

 ;; Error Handler

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

 (setq vl '("CMDECHO")
       ov (mapcar 'getvar vl))
 (setvar "CMDECHO" 0)        

 ;; Get Block

 (while
     (progn
       (not (initget "Name"))
       (setq blkNme
              (entsel "\nSelect Block or [Name]: "))
       (cond
         ((and (vl-consp blkNme)
               (eq "INSERT" (cdr (assoc 0 (entget (car blkNme)))))
               (eq 1 (cdr (assoc 66 (entget (car blkNme))))))
          (setq blkNme (cdr (assoc 2 (entget (car blkNme)))))
          nil) ; Exit Loop
         ((eq 'STR (type blkNme))
          (setq blkNme (getstring t "\nSpecify Block Name: "))
          (cond ((and (setq tdef (tblsearch "BLOCK" blkNme))
                      (eq 2 (logand (cdr (assoc 70 tdef)) 2)))
                 nil) ; Exit Loop
                ((tblsearch "BLOCK" blkNme)
                 (princ "\n<< Block Contains No Attributes >>"))
                (t (princ "\n<< Block Not Found >>")))) ; Keep in Loop
         (t (princ "\nMissed, Try Again...")))))

 ;; Get Attribute Values

 (if (setq ss
       (ssget "_X" (list (cons 0 "INSERT")
                         (cons 2 blkNme)
                         (cons 66 1))))
   (progn
     (initdia 1)
     (vl-cmdf "_.attedit" (setq bTest (ssname ss 0)))
     (foreach att (vlax-safearray->list
                    (vlax-variant-value
                      (vla-getAttributes
                        (vlax-ename->vla-object bTest))))
       (setq attlst
         (cons
           (cons
             (vla-get-TagString att)
               (vla-get-TextString att)) attlst)))

 ;; 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 "\\")))
     (if (< (atoi (setq acVer (substr (getvar "ACADVER") 1 2))) 16)
       (setq acVer "") (setq acVer (strcat (chr 46) acVer)))
     (setq dbx (vla-getInterfaceObject
                 *acad (strcat "ObjectDBX.AxDbDocument" acVer)))
     (princ "\nProcessing...")

     ;; Iterate Drawings
     
     (foreach dwg (setq dwLst
                    (mapcar
                      (function
                        (lambda (x)
                          (strcat Dir x)))
                      (vl-directory-files Dir "*.dwg" 1)))
       (vla-open dbx dwg)

       (vlax-for lay (vla-get-Layouts dbx)
         (vlax-for Obj (vla-get-Block lay)
           (if (and (eq (vla-get-ObjectName Obj) "AcDbBlockReference")
                    (eq (vla-get-Name Obj) blkNme))
               (foreach Att (vlax-safearray->list
                              (vlax-variant-value
                                (vla-getAttributes Obj)))
                 (if (setq Tag (assoc (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 Blocks Found >>"))

 ;; Garbage Collection
 
 (ObjRel (list Shell dbx *acad))
 (gc)
 (mapcar 'setvar vl ov)
 (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))


Link to comment
Share on other sites

Gave me that output

 

>

 

Anyways man ... I dont want you to sit and help me for too long ...

I will try to take a look at that and maybe come up with something.

 

I will try something to do with the lattest you gave me ... the attchg2 for batch processing.

Link to comment
Share on other sites

Gave me that output

 

>

 

Anyways man ... I dont want you to sit and help me for too long ...

I will try to take a look at that and maybe come up with something.

 

I will try something to do with the lattest you gave me ... the attchg2 for batch processing.

 

What did it get to before you received that error?

Link to comment
Share on other sites

Command: macatt

Select Block or [Name]:

Processing................

>

 

But that lisp let you choose a folder not files in a folder which is more safe I think for the office.

Some changes might aplly to some drawings .. maybe like a date.

Link to comment
Share on other sites

Command: macatt

Select Block or [Name]:

Processing................

>

 

But that lisp let you choose a folder not files in a folder which is more safe I think for the office.

Some changes might aplly to some drawings .. maybe like a date.

 

Just move the drawings you want to change into another folder, then back when finished - this process is much quicker than using a script. (if I can get it to work that is...)

Link to comment
Share on other sites

Just tested the above posted code, all seems to work for me - so it must be a compatibility issue with the ODBX part and your software version... I'm too new to ODBX to know what to do :oops:

Link to comment
Share on other sites

True its quicker .. :)

Thanx for helping me out

I will check the ODBX

 

Just out of interest, what do you get in Architecture when you type

 

(getvar "ACADVER")

 

at the command line?

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