Creating Blocks with VBA

Creating Blocks with VBA

Anonymous
Not applicable
2,707 Views
1 Reply
Message 1 of 2

Creating Blocks with VBA

Anonymous
Not applicable

Hi. I'm trying to create blocks in VBA. Each block will contain various objects (circles, polylines, mleader) representing trees - a TreeBlock. The size of the various objects in the block will vary for each tree. (I read the dimensions for each tree from an excel file).

 

I want to use an mleader as the label for each TreeBlock I create, BUT need to be able to move the mleader around without moving the block as a whole. So I created a dynamic block called "TLabel" using an mleader with a point parameter and a stretch action. So now when I create a TreeBlock I wish to add my existing "TLABEL" block to this and exit the textstring of the mleader. But, how do I add my "TLabel" block to my "TreeBlock" - there is no addblock method for the block object! And when I do, how will I edit the textstring property of the mleader, without exploding the block and losing its dynamic property - I suspect using attributes?

 

Any help gratefully received.

0 Likes
Accepted solutions (1)
2,708 Views
1 Reply
Reply (1)
Message 2 of 2

norman.yuan
Mentor
Mentor
Accepted solution

My understanding is that you want to programmatically create block defeinition, which has block nested (BLOCK REFERENCE!) in it.

 

You add block (block reference) into block definition with InsertBlock() method (as you already know there is no AddBlock() among all of the AddXXXXX() methods of AcadBlock).

 

However, since the nested block you want to use is dynamic block, any reference of the dynamic block definition you want to added to your new block definition is actually a STATIC block reference (either to its original block definition, or an anonymous block definition AutoCAD generated according to the dynamic property variations). That means, the block reference itself loses its "dynamic changeability" once you add it into a new block definition.

 

Since I guess you want the new block to still be dynamic (i.e. the nested block's leader can still be drag-able), this will not work for you. Any dynamic stuff must be defined in the new block definition, not the nested block (because it is a block reference). However, there is no API available to programmatically define block's dynamic properties. 

 

Norman Yuan

Drive CAD With Code

EESignature