Author Topic: ObjectDBX and attributes: Doesn't work?  (Read 8307 times)

0 Members and 1 Guest are viewing this topic.

ArgV

  • Guest
ObjectDBX and attributes: Doesn't work?
« on: March 20, 2010, 03:13:55 PM »
I see there is a post right below this one about the same topic, but I'm still wondering because I'm doing the same thing.... trying to update attributes in several (thousand) drawings with ODBX. It changes the textstring, but if you go in to the drawing after saving it, and double click the block containing the attribute, it's still the same name. However, if you go INTO the block, the textstring for the attribute is correct. ??

I'm gonna google it, but I thought maybe someone had some super special inside info that I'm not aware of.  :?

Lee Mac

  • Seagull
  • Posts: 12920
  • London, England
Re: ObjectDBX and attributes: Doesn't work?
« Reply #1 on: March 20, 2010, 08:08:32 PM »
What are you trying to change? The attribute in each INSERT or the attribute definition in the block table? For the latter you will need a regen at least. For the former, I created a program here. :-)
« Last Edit: March 20, 2010, 08:17:21 PM by Lee Mac »

ArgV

  • Guest
Re: ObjectDBX and attributes: Doesn't work?
« Reply #2 on: March 20, 2010, 08:52:24 PM »
What are you trying to change? The attribute in each INSERT or the attribute definition in the block table? For the latter you will need a regen at least. For the former, I created a program here. :-)

both. :)

I seen the one you wrote there, but I can't really use it, as I don't know the names of all the attributes, and there are many thousands.

So, what do you have to do to get it to work right? I guess something to do with the block table definition. I'll look into that I suppose.


MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: ObjectDBX and attributes: Doesn't work?
« Reply #3 on: March 20, 2010, 08:57:01 PM »
Consider posting a drawing c/w with typical list of search and replace operations you want to execute, or a complete before | after sample.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Lee Mac

  • Seagull
  • Posts: 12920
  • London, England
Re: ObjectDBX and attributes: Doesn't work?
« Reply #4 on: March 21, 2010, 09:25:01 AM »
What are you trying to change? The attribute in each INSERT or the attribute definition in the block table? For the latter you will need a regen at least. For the former, I created a program here. :-)

both. :)

I seen the one you wrote there, but I can't really use it, as I don't know the names of all the attributes, and there are many thousands.

So, what do you have to do to get it to work right? I guess something to do with the block table definition. I'll look into that I suppose.



As you don't know the names of all the attributes, I assume you want to perform the same change on all of them. If you are just changing the attribute values within the INSERTS, then you would just need to cycle through each object in each layout in the dbx document, and for every attibuted block you come across, cycle through its attributes and make your changes.

For the attribute definitions, you would need to cycle through the objects in the block definition, and make your changes there. And make sure you perform a save on the drawing to save changes.

Lee

ArgV

  • Guest
Re: ObjectDBX and attributes: Doesn't work?
« Reply #5 on: March 22, 2010, 07:04:38 PM »
What are you trying to change? The attribute in each INSERT or the attribute definition in the block table? For the latter you will need a regen at least. For the former, I created a program here. :-)

both. :)

I seen the one you wrote there, but I can't really use it, as I don't know the names of all the attributes, and there are many thousands.

So, what do you have to do to get it to work right? I guess something to do with the block table definition. I'll look into that I suppose.



As you don't know the names of all the attributes, I assume you want to perform the same change on all of them. If you are just changing the attribute values within the INSERTS, then you would just need to cycle through each object in each layout in the dbx document, and for every attibuted block you come across, cycle through its attributes and make your changes.

For the attribute definitions, you would need to cycle through the objects in the block definition, and make your changes there. And make sure you perform a save on the drawing to save changes.

Lee

Yes, there is, depending on the name of the folder the drawings are in, the attribute and block name will change, so I have the nomenclature, but not the knowhow. :)

Uhm.. I went through the block and changed the "textString" property, is that not enough? There is no paperspace objects to worry about, only the entities that reside in modelspace.

thanks again, Lee.

Lee Mac

  • Seagull
  • Posts: 12920
  • London, England
Re: ObjectDBX and attributes: Doesn't work?
« Reply #6 on: March 22, 2010, 09:23:10 PM »
If you want to change the attributes in the INSERTs in ModelSpace, you will have to iterate through every object in the ModelSpace 'block', and change each INSERT's attributes.

e.g.

Code: [Select]
(defun c:test (/ obj)
  (vl-load-com)

  (vlax-for obj (vla-get-ModelSpace
                  (vla-get-ActiveDocument
                    (vlax-get-acad-object)))
   
    (if (eq "AcDbBlockReference"
            (vla-get-ObjectName obj))
     
      (vla-put-layer obj "0")))

  (princ))

ArgV

  • Guest
Re: ObjectDBX and attributes: Doesn't work?
« Reply #7 on: March 23, 2010, 10:25:43 AM »
If you want to change the attributes in the INSERTs in ModelSpace, you will have to iterate through every object in the ModelSpace 'block', and change each INSERT's attributes.

e.g.

Code: [Select]
(defun c:test (/ obj)
  (vl-load-com)

  (vlax-for obj (vla-get-ModelSpace
                  (vla-get-ActiveDocument
                    (vlax-get-acad-object)))
   
    (if (eq "AcDbBlockReference"
            (vla-get-ObjectName obj))
     
      (vla-put-layer obj "0")))

  (princ))

ok, so I use something like this:

Code: [Select]
(defun editModelSpaceAttribute (/ doc ms item)
  (vl-load-com)
  (setq doc (vla-get-activedocument (vlax-get-acad-object))
ms (vla-get-modelspace doc))

  (vlax-for item ms
    (if
      (= (vla-get-objectname item) "AcDbBlockReference")
      (progn
      (setq item (apply 'vla-item (list (vla-get-blocks doc) (vla-get-name item))))
      (vlax-for i item
(if
  (= (vla-get-objectname i) "AcDbAttributeDefinition")
  (progn
    (vla-put-textstring i "Test")
    (vla-update i)
    )
  )
  )
)
      )
    )
  )

but this only updates the string when you open the block.. the attribute definition seems to not change at all. ???









Lee Mac

  • Seagull
  • Posts: 12920
  • London, England
Re: ObjectDBX and attributes: Doesn't work?
« Reply #8 on: March 23, 2010, 10:36:16 AM »
You are editing the attribute definition within the block definition, not the attribute within the insert.

You would need to use something like this:

Code: [Select]
(vlax-for obj (vla-get-ModelSpace
                (vla-get-ActiveDocument (vlax-get-acad-object)))

  (if (and (eq "AcDbBlockReference" (vla-get-ObjectName obj))
           (eq :vlax-true (vla-get-hasAttributes obj)))

    (foreach att (vlax-invoke obj 'GetAttributes)
      (vla-put-TextString att "test"))))

Of course, this is only working on the ActiveDocument, and only in ModelSpace. If you were using ODBX, you would use the ObjectDBX Document, and perhaps iterate through all the layouts.

Lee
« Last Edit: March 23, 2010, 11:09:33 AM by Lee Mac »

ArgV

  • Guest
Re: ObjectDBX and attributes: Doesn't work?
« Reply #9 on: March 23, 2010, 11:18:39 AM »
You are editing the attribute definition within the block definition, not the attribute within the insert.

You would need to use something like this:

Code: [Select]
(vlax-for obj (vla-get-ModelSpace
                (vla-get-ActiveDocument (vlax-get-acad-object)))

  (if (and (eq "AcDbBlockReference" (vla-get-ObjectName obj))
           (eq :vlax-true (vla-get-hasAttributes obj)))

    (foreach att (vlax-invoke obj 'GetAttributes)
      (vla-put-TextString att "test"))))

Of course, this is only working on the ActiveDocument, and only in ModelSpace. If you were using ODBX, you would use the ObjectDBX Document, and perhaps iterate through all the layouts.

Lee

well that worked. Thank you! I was about to pull out what little hair I have left on my head.

I'd tried using "vla-getattributes" but it wasn't working??? wel, thanks again.








Lee Mac

  • Seagull
  • Posts: 12920
  • London, England
Re: ObjectDBX and attributes: Doesn't work?
« Reply #10 on: March 23, 2010, 11:30:16 AM »
You're welcome :-)

I'd tried using "vla-getattributes" but it wasn't working??? wel, thanks again.

If you really wanted to use vla-getAttributes:

Code: [Select]
(vlax-for obj (vla-get-ModelSpace
                (vla-get-ActiveDocument (vlax-get-acad-object)))

  (if (and (eq "AcDbBlockReference" (vla-get-ObjectName obj))
           (eq :vlax-true (vla-get-hasAttributes obj)))

    (foreach att (vlax-safearray->list
                   (vlax-variant-value
                     (vla-getAttributes obj)))
     
      (vla-put-TextString att "test"))))

ArgV

  • Guest
Re: ObjectDBX and attributes: Doesn't work?
« Reply #11 on: March 23, 2010, 11:42:54 AM »
You're welcome :-)

I'd tried using "vla-getattributes" but it wasn't working??? wel, thanks again.

If you really wanted to use vla-getAttributes:

Code: [Select]
(vlax-for obj (vla-get-ModelSpace
                (vla-get-ActiveDocument (vlax-get-acad-object)))

  (if (and (eq "AcDbBlockReference" (vla-get-ObjectName obj))
           (eq :vlax-true (vla-get-hasAttributes obj)))

    (foreach att (vlax-safearray->list
                   (vlax-variant-value
                     (vla-getAttributes obj)))
     
      (vla-put-TextString att "test"))))


ok, so now I'm a little confused. why is there a difference between the vlax-invoke method and the vla-getattributes method?

I realize it's just a return type, but it seems strange to me that they would be so different.  They must have done attributes on a monday. haha.


Lee Mac

  • Seagull
  • Posts: 12920
  • London, England
Re: ObjectDBX and attributes: Doesn't work?
« Reply #12 on: March 23, 2010, 11:51:53 AM »
Its the same for all the VL methods / properties,

vlax-invoke / vlax-get will return lists.
vlax-invoke-method / vlax-get-property will return variants.


ArgV

  • Guest
Re: ObjectDBX and attributes: Doesn't work?
« Reply #13 on: March 23, 2010, 02:53:40 PM »
Its the same for all the VL methods / properties,

vlax-invoke / vlax-get will return lists.
vlax-invoke-method / vlax-get-property will return variants.


So I see. And I guess the attribute definitions are saved within the modelspace block, and the attribute within the insert means almost nothing. Hmm.. I'm sure after a few years of using autocad I'll figure it all out. :)

thanks for the lesson.

Lee Mac

  • Seagull
  • Posts: 12920
  • London, England
Re: ObjectDBX and attributes: Doesn't work?
« Reply #14 on: March 23, 2010, 03:01:33 PM »
So I see. And I guess the attribute definitions are saved within the modelspace block, and the attribute within the insert means almost nothing. Hmm.. I'm sure after a few years of using autocad I'll figure it all out. :)

thanks for the lesson.

You're welcome.

The attribute definitions are contained in the Block Definition (within the block table), and each block reference or 'insert' holds the attribute object containing the Tag and Value for that attribute.

Lee