vba for editing block text

vba for editing block text

Anonymous
Not applicable
1,813 Views
2 Replies
Message 1 of 3

vba for editing block text

Anonymous
Not applicable

Good afternoon.

I'm using autoCAD 2016, and while I've been using VBA in Excel for years, doing it in AutoCAD is a new experience for me. 

I've created a user form to input text values into a block, using combo-boxes. I'm looking to create a macro which will allow me to edit the block, based on the values selected in the combo boxes. 

As I've read through some of the discussions, I've come to realize that I may not entirely understand what I'm specifically wanting to have edited.

Below are two images of the block, and the properties window, of that block. 

 

 

Block.png

 

This is the block, activated, on a layout tab. 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

This is the property window of that block. 

BlkAttributeProp.pngWhat I'm curious about here is which are the attributes, and what are the final, editable values/text. My goal is to edit the items on the right side of the property window--- in the block, using my user form. 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

The user form to edit this particular block is just trhe first of many which I'll be creating. So, my goal is to have a generic enough set of code which will edit the values-- which are in the block, based on the values defined in the combo-boxes I'll be using. 

 

If any of this is not clear--- please let me know, and I'll respond as soon as I am able. 

 

TYIA. 

 

0 Likes
1,814 Views
2 Replies
Replies (2)
Message 2 of 3

norman.yuan
Mentor
Mentor

It looks like your issue is mailyon the side of lack of enough knowledge on AutoCAD itself (that is, its COM object model, which you can learn easily via VBA's Object Browser, just like you learn Excel object model).

 

In order to edit Block's attribute, you need to be able to:

 

1. Identiy the target blck(s) (that is, AcadBlockReference in the drawing). You can ask user to select, or you can use code to select (first filter, if necessary), or you can simply use code to loop through Model/PaperSpace to find the one(s) in interest.

 

2. Then, you can retieve attributes (AcadBlockReference.GetAttributes()) and present them on the form;

 

3. On the form level, you collect corresponding user input for the attributes

 

4. Apply user input to the attributes. And eventually, you would call AcadBlockrefernce.Update() as last line of code

 

So, it is really a simple work, coming down to find/identify the AcadBlockReference.

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 3 of 3

Anonymous
Not applicable

@norman.yuan wrote:

It looks like your issue is mailyon the side of lack of enough knowledge on AutoCAD itself (that is, its COM object model, which you can learn easily via VBA's Object Browser, just like you learn Excel object model).

 

In order to edit Block's attribute, you need to be able to:

 

1. Identiy the target blck(s) (that is, AcadBlockReference in the drawing). You can ask user to select, or you can use code to select (first filter, if necessary), or you can simply use code to loop through Model/PaperSpace to find the one(s) in interest.

 

2. Then, you can retieve attributes (AcadBlockReference.GetAttributes()) and present them on the form;

 

3. On the form level, you collect corresponding user input for the attributes

 

4. Apply user input to the attributes. And eventually, you would call AcadBlockrefernce.Update() as last line of code

 

So, it is really a simple work, coming down to find/identify the AcadBlockReference.


Hi Norman.

For item one, I'm going to be making a user form for each block we have, so I'd be focusing on specific blocks, with each form.

For item two, I'm not looking to show the components on the form, just to edit/set text values in the respective fields of the particular blocks.

For item three, if I'm understanding correctly, that's the combo-box drop-down selections. 

And for item four, that's the part I'm looking for input on. 

 

Where might I find a tutorial for this? 

It appears that the step through process is to activate the particular block I'm calling to, make my combo-box-selections, and then apply my selections to update the block 

Again, thank you for your help and time. 

0 Likes