Can i directly change attributes?

Can i directly change attributes?

Anonymous
Not applicable
470 Views
3 Replies
Message 1 of 4

Can i directly change attributes?

Anonymous
Not applicable

I'm trying to do the following:

 

Directly access with Excel VBA the attributes of some specific blocks inside a drawing.

 

For example, assume that there are 3 blocks named myBlock1, myBlock2, byBlock3 defined in the drawing.

 

Each of the blocks contains 3 texts e.g. myText1, myText2, myText3 with the respective attributes (Tag, Prompt, Value, etc).

 

To my undestanding, when i insert a block inside the drawing an instance of this block is created, called block reference.

 

How can i point to a specific block reference and change its attributes given the fact that i already know the block name?

 

My final target is to create one drawing with a predefined number of specific blocks and then through Excel VBA create copies of this drawing filled with data from Excel.

 

Unfortunatelly every code example i've seen selects  blocks and entities, and then loops around each one of them  by comparing texts. What i would like to see is a code example(if possible!) that could change directly some attributes...

 

e.g. blockReference("MyBlock1").myText1 = "NewText"

 

Is this possible?

 

 

0 Likes
471 Views
3 Replies
Replies (3)
Message 2 of 4

Alfred.NESWADBA
Consultant
Consultant

Hi,

 

>> How can i point to a specific block reference and change its attributes given the fact that i already know the block name?

First you are right, the inserted Symbol is call BlockReference. And that makes your answer not easy, because the BlockName does not be an inidcator for being unique. E.g. a block-definition is made called "WINDOW", you inserted that multiple times so you have multiple BlockReferences of type "WINDOW" inserted.

Within a drawing AutoCAD uses the property HANDLE as a unique ID. However, copying BlockReferences from one drawing to another one does not keep the HANDLEs! In the new drawing the blockreferenced get new HANDLEs.

 

If you have to interact 2 applications (AutoCAD and Excel) and there has to be worked on more than one drawing or more than one Excel-file you should have your own handling of unique IDs and for BlockReferences you can add an AttriuteReference where you store YOUR unique ID.

 

HTH, - alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2026
------------------------------------------------------------------------------------

(not an Autodesk consultant)
0 Likes
Message 3 of 4

Anonymous
Not applicable

Alfred,

 

thank you for your fast response.

 

I would like to clarify that i copied and "Saved As" a lot of times the same block inside the block editor with different name in order to make seperate references in VBA with the name of each block...

 

My intention is to find out the name or ID or whatever of the block references of one drawing which will be used a a template. Then this drawing will be "saved as" with a different name and i will edit the existing block attributes by directly acessing the block reference's attributes by name. My Excel data will fill in the desired fields-attributes...

 

Up to this time i have seen filtering or looping tactics to edit attributes. Is there any way to have a direct access if the ID or a kind of name is known on the block reference?

 

Any sample code is welcome...

 

Thank you very much for your time... 

 

 

0 Likes
Message 4 of 4

Alfred.NESWADBA
Consultant
Consultant

Hi,

 

>> I would like to clarify that i copied and "Saved As" a lot of times the same block inside the block editor

>> with different name in order to make seperate references in VBA with the name of each block..

Well, that's not a usual way, but as long as I don't have more knowledge about your complete task I can't say it's bad.

I would be afraid of users, who do copy BlockReferences and than your uniqueness is gone.

 

>> Up to this time i have seen filtering or looping tactics to edit attributes.

>> Is there any way to have a direct access if the ID or a kind of name is known on the block reference?

A global way would be to built a selectionset (with filter to "BlockReference" and "<YourBlockName>"). That will give you the BlockReferences with your Name and if there are more then 1 in the drawing, you have to react (in your case). If you have found only one you are on your way.

If you know the handle of the BlockReference you can select the object by it's handle (HandleToObject).

 

The Attributes also have a handle, if you know the handle, you can also access this object directly. If not, you have to scan through all AttributeReferences within you BlockReference and look the the AttRef that has the TAG (Attributename) you search for.

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2026
------------------------------------------------------------------------------------

(not an Autodesk consultant)
0 Likes