Author Topic: change block Attributes in all OPEN drawings..  (Read 3783 times)

0 Members and 1 Guest are viewing this topic.

ArgV

  • Guest
change block Attributes in all OPEN drawings..
« on: September 16, 2009, 08:43:42 PM »
I'm trying to do this, thinking it can be done through the documents collection, but the values are changing, however the pages do not. I.e. after I test it a few times, I see that the textstring I want to put is actually there inside the object, however the page does not reflect it.

I have tried using all sorts of update this, update that. anyways.. if someone could point a finger, my brain will thank you.

Code: [Select]

(defun updateAttsAll (/ block en el date person doc blocks titleObject item)


 
(vl-load-com)

(setq date (getstring "\nDate: ")
      person (getstring "\nApproved by: "))

 
(vlax-for doc (vla-get-documents (vlax-get-acad-object))
  (changeStuff date person doc)
  )
  )
   
(defun changestuff (date person doc)
(vlax-for block (vla-get-blocks doc)

  (cond
    ((and
       (vlax-property-available-p block "name")
       (= (vla-get-name block) "TITLEBLOCK"))(vlax-for item block
                                               (if
                                                 (and
                                                   (= (vla-get-objectname item) "AcDbAttributedefinition")
                                                   (= (vla-get-tagstring item) "APPD"))
                                                 (progn
                                                   (vla-put-textstring item person)
                                                   (vla-update item)
                                                   (vla-update block)
                                                   )
                                                 )
                                               )
     )
    )
  )
  )

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: change block Attributes in all OPEN drawings..
« Reply #1 on: September 16, 2009, 10:20:07 PM »
You'll find the answer in one of these post.

Note that the block does not contain the attribute, only the attribute definition.
The INSERT contains the attribute & it's data.

HTH
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Lee Mac

  • Seagull
  • Posts: 12924
  • London, England
Re: change block Attributes in all OPEN drawings..
« Reply #2 on: September 17, 2009, 05:45:03 AM »
ArgV,

Look into iterating through the Objects in each drawing using something like this:

Code: [Select]
(vlax-for lay (vla-get-layouts doc)
  (vlax-for Obj (vla-get-Block lay)
    (if (eq "AcDbBlockReference"...


The vla-get-Block function will get the Layout Space block definition, containing all the objects.  ;-)

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Lee Mac

  • Seagull
  • Posts: 12924
  • London, England
Re: change block Attributes in all OPEN drawings..
« Reply #4 on: September 17, 2009, 06:24:23 AM »
Alan,

I didn't know if it was possible to use a SelectionSet method in documents other than the ActiveDocument - am I wrong?

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: change block Attributes in all OPEN drawings..
« Reply #5 on: September 17, 2009, 06:33:39 AM »
Oh you're quite right. Still on my first cup of the day & should read the title again. :)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Lee Mac

  • Seagull
  • Posts: 12924
  • London, England
Re: change block Attributes in all OPEN drawings..
« Reply #6 on: September 17, 2009, 06:42:15 AM »
 ;-)

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

ArgV

  • Guest
Re: change block Attributes in all OPEN drawings..
« Reply #8 on: September 18, 2009, 01:33:05 AM »
You'll find the answer in one of these post.

Note that the block does not contain the attribute, only the attribute definition.
The INSERT contains the attribute & it's data.

HTH


I have never understood the difference between a block and an insert? A block is basically a selection set of objects grouped together by name that have ONE insertion point. But what is an insert? Is that just an inserted version of a block? From the code I've read so far, it looks like it's done as an item OF the block (once it's inserted).

Thanks,

-ArgV

ArgV

  • Guest
Re: change block Attributes in all OPEN drawings..
« Reply #9 on: September 18, 2009, 01:34:51 AM »
ArgV,

Look into iterating through the Objects in each drawing using something like this:

Code: [Select]
(vlax-for lay (vla-get-layouts doc)
  (vlax-for Obj (vla-get-Block lay)
    (if (eq "AcDbBlockReference"...


The vla-get-Block function will get the Layout Space block definition, containing all the objects.  ;-)

From the layout collection eh? Ok. I'll give that a whirl. thanks.

-ArgV

hermanm

  • Guest
Re: change block Attributes in all OPEN drawings..
« Reply #10 on: September 18, 2009, 08:49:19 PM »
Quote
I have never understood the difference between a block and an insert?

A block is an entry in the block table, i.e. the definition of what needs to be drawn.

An INSERT is an inserted instance of a block.

A "programmer analogy" might be that the block table entry is like a "class," whereas an INSERT is an instance of the class.

Unfortunately, people tend to refer to INSERT entities as "blocks," when in fact INSERTs are instances of blocks.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: change block Attributes in all OPEN drawings..
« Reply #11 on: September 18, 2009, 09:05:05 PM »

Herman,
I'd forgo the analogy.
The First 2 lines of your description are perfectly adequate :)
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

ArgV

  • Guest
Re: change block Attributes in all OPEN drawings..
« Reply #12 on: September 18, 2009, 09:14:31 PM »
Quote
I have never understood the difference between a block and an insert?

A block is an entry in the block table, i.e. the definition of what needs to be drawn.

An INSERT is an inserted instance of a block.

A "programmer analogy" might be that the block table entry is like a "class," whereas an INSERT is an instance of the class.

Unfortunately, people tend to refer to INSERT entities as "blocks," when in fact INSERTs are instances of blocks.

Ah. that makes sense now. :) So I guess thats why you use "BLOCK" with tblsearch, and "INSERT" with SSget. That always kinda tripped me up. But now, CAB says to look to the insert for an attribute definition. How do you scour the drawing for inserts, just using SSGET?

thanks!

-ArgV

ArgV

  • Guest
Re: change block Attributes in all OPEN drawings..
« Reply #13 on: September 18, 2009, 10:41:04 PM »
ArgV,

Look into iterating through the Objects in each drawing using something like this:

Code: [Select]
(vlax-for lay (vla-get-layouts doc)
  (vlax-for Obj (vla-get-Block lay)
    (if (eq "AcDbBlockReference"...


The vla-get-Block function will get the Layout Space block definition, containing all the objects.  ;-)


Thank you again, Lee. That worked like a charm. :) :)

Code: [Select]
(defun updateAttsAll (/ block en el date person doc blocks titleObject item)

(vl-load-com)

(setq date (getstring "\nDate: ")
      person (getstring "\nApproved by: "))

 
(vlax-for doc (vla-get-documents (vlax-get-acad-object))
  (setq layouts (vla-get-layouts doc))
  (changeStuff layouts date person)

  )
  )


(defun changestuff (layouts date person / block att atts person)

(vlax-for lay layouts
  (vlax-for block (vla-get-block lay)


    (cond
      ((and

         (vlax-property-available-p block "name")
         (= (vla-get-name block) "TITLEBLOCK")
         (eq "AcDbBlockReference" (vla-get-objectname block)))
       
       (foreach att (setq atts (vlax-safearray->list (vlax-variant-value (vla-getattributes block))))

         (cond
           ((= (vla-get-tagstring att) "APPD")(vla-put-textstring att person))
           ((= (vla-get-tagstring att) "DATE_APPD")(vla-put-textstring att date)))
           )
         )
       )
    (vla-update block)
      )
    )
  )
« Last Edit: September 18, 2009, 11:06:08 PM by ArgV »

Lee Mac

  • Seagull
  • Posts: 12924
  • London, England
Re: change block Attributes in all OPEN drawings..
« Reply #14 on: September 19, 2009, 07:27:34 AM »
ArgV, little pointer - in your AND statement - put the check for the ObjectName first, then you won't need to use the Property-Available-P...  :-)