Attribute value editor?

Attribute value editor?

Anonymous
Not applicable
2,723 Views
5 Replies
Message 1 of 6

Attribute value editor?

Anonymous
Not applicable

Okay here goes.  I've been working with vba for years and think it is a great system but I am new to Autocad and customizing it via VBA.

 

I have a drawing(s) that have a series of blocks.  These blocks (approximately 13 of them per drawing) contain drawing numbers, revision levels and so forth.  I need to update the value of the revision level, or "tag", in each block.  Is it possible to write a sub that would update all of them at once instead of having to eattedit each individual block?  Is it even possible or am I trying to divide by zero?  I don't want to waste anymore time on this if what I'm asking for is pie in the sky.  If it is possible could anyone point me in the right direction?

 

I've been looking all over the web for more than a week now and I'm close to banging my head against a wall.  There's a lot of material out there but it's either cryptic in the details or overwhelmingly complex.  So much so that I can't pick through it to get what I'm after.

 

Thanks for any help you may be able to give me.

 

 

0 Likes
Accepted solutions (1)
2,724 Views
5 Replies
Replies (5)
Message 2 of 6

Anonymous
Not applicable
Dim ss As AcadSelectionSet
Dim dataType(2) As Integer
Dim dataVal(2) As Variant dataType(0) = 0 dataVal(0) = "INSERT" dataType(1) = 66 '' has attributes dataVal(1) = 1 dataType(2) = 2 ss.Clear '' select all blocks("INSERT") with attributes ss.Select acSelectionSetAll, , , dataType, dataVal ' get all attributes of the first block AllAttr = ss(0).GetAttributes 'if tag of first attribute is "MyTag" If AllAttr(0).TagString = "MyTag" Then 'then change its value to "MyValue" AllAttr(0).TextString = "MyValue" End If
0 Likes
Message 3 of 6

norman.yuan
Mentor
Mentor

When you say "working with VBA for years", you must have good understanding of "A" in "VBA": it is VB integrated inside of certain Application (MS Word, MS Excel, or AutoCAD). In order to be good at VBA, therefore, one needs also to very well understand the Application (i.e. its COM object model). In your case, while you may be good at generic VBA code, but it seems you are not in the position of knowing AutoCAD and its COM Object Model good enough, judging by your question. Sorry, no offence meant, I only want to emphasize that one can only write workable AutoCAD VBA code with good understanding of its object model.

 

When you say "Editor", do you mean you want to create an UI for user to edit/update block's attributes? It is surely rather easy to create something similar to Acad's built-in one (when user double-clicks an attribute, the attribute editing UI pops up). 

 

The process of updating Block's attributes would include following steps:

 

1. Identify target block, and its attribute. you can ask user to manually select a block; or you can programmatically select one or more blocks with filters (layer, block name, space/layout...)

 

2. Collect data to be used to update attribute. The data can be from external source (data file, database..., of course certain identifying logic may be required), or you can present an UI (dialog form, usually) to get user input.

 

3. Once the data is collected, the target blocks are identified, then you need code to programmatically update the blocks' attribute, similar to the code shown in the other post.

 

So, yes, while your question lacks concrete details, AutoCAD VBA certainly can do what you may want to. If you have question on any of the steps afore-mentioned, it might be easier to discuss.

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 4 of 6

Anonymous
Not applicable

No offense taken.  I'll be the first to admit that I do not have a good understanding of AutoCAD nor its Object Model.  I suppose when I say "editor" I want to run a VBA macro, an input box pops up prompting the user to enter in a new value to update the tag/blocks with and then it changes them.  Nothing fancy. 

 

I've been trying the code in the other earlier post (thank you MetroVancoverDrafting).  I think I understand what it's trying to do but as it stands it wont compile.  I'm working with it.

 

I think I can handle step 1 in your process.  I'll start there.  I think the problem I was having was how to move on from step 1.  I taught myself VBA and how it applies to MS Access, this seems to be less intuitive but I'll keep at it.

 

Thank you all.

0 Likes
Message 5 of 6

norman.yuan
Mentor
Mentor
Accepted solution

I have quickly put together some VBA code that does the following:

 

1. Ask user to pick a block that has attributes in it

2. Gather all the attribute data (tags and values)

3. Show the attribute data in a dialog box for user to edit

4. Update the block with updated attribute data

 

The VBA project and a test drawing is attached. Also see the video clip showing how it works. As you can see, it is really easy to create your own attribute editor.

 

In order to simplify the UI, I intentionally limited the block can only have up to 4 attributes. However, if you want a more generic editor, you need to handle the case that a block can have many more attributes, so design your UI accordingly.

 

A warning: if your UI want to handle user input with different type of data for attribute value. like numbers, date/time, values from predefined list, you may want to use much enhanced controls, which are hardly available in 64-bit VBA. So, do not wast your time in VBA in that case, you'd be better off develop your solution with AutoCAD .NET API.

Norman Yuan

Drive CAD With Code

EESignature

Message 6 of 6

Anonymous
Not applicable

Awesome.  Thank you.  I've been able to modify the code you provided to suit our needs.  The last thing though is being able to change all of the blocks (of a certain name) at once.  I assume I would do that with a acadselctionset, then cycle through each block, then update the tag in each block that I want to update.  You've gotten me much closer to my goal.  I'll keep working on this.  Thank you again.

0 Likes