VBA
Discuss AutoCAD ActiveX and VBA (Visual Basic for Applications) questions here.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Updating a block reference after making changes to the definition

2 REPLIES 2
Reply
Message 1 of 3
nrdev
1424 Views, 2 Replies

Updating a block reference after making changes to the definition

Hi,

 

I searched and saw a lot of topics on this matter but none had the right answer for me.

 

I have a small vba sub wich changes the color and layer of all entities inside a block. It seems to work pretty well for the majority of blocks, but then if I try that on a dynamic block, the definition is correctly altered, but the references aren't updated...

 

I know for a fact that the definition has been correctly modified because if I type bedit, I can see the definition is modified. Then, in the block editor, if I save the block, the references are correctly updated.

 

Do you have an idea on how to force references to update after I made the modifications inside the definition ?

I searched for methods within the VBA Reference and I tried blockRef.Update but it doesn't seem to have any effect.

 

Thanks.

Regards.

2 REPLIES 2
Message 2 of 3
norman.yuan
in reply to: nrdev

You need to understand how a dynamic block's block reference is created. A dynamic block's block reference is not be a diect reference to the dynamic block definition, when one of its dynamic property is set to a value that is dirrerent from the value in the dynamic block definition (this is mostly the case when using a dynamic block). In this case, AutoCAD created a unanymous block definition with based on the dynamic block definition and the dynamic property value. In essence, there could be many unamymous block definitions are ddefined for the block references that refer to the same dynamic block definition.

 

Therefore, in your coase, only modifying dynamic block defition will not update all corresponding dynamic block references. You need to update the unamymous block defitions, which would be very difficult to do in AutoCAD VBA, if not completely impossible. The simple way, IMO, would be:

 

  • Update the dynamic block definition, as you need to do;
  • find all block references of the dynamic block, using "EffectiveName" property;
  • retrieve the block reference's information (insertion point, insertion scale, attributes....and its dynamic properties and save in varaibles
  • erase the block reference and reinsert the block at the same location/sane scale, attribute...
  • set its dynamic properties to previous values.

Yes, it needs quite some code. Have fun.

 

Norman Yuan

Drive CAD With Code

EESignature

Message 3 of 3
gizmowiebe
in reply to: nrdev

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost