Jump to content

Write to attributes...


durbdk

Recommended Posts

Hi All,

 

I am new to VBA for ACAD, and have struggled to come to terms with it, but I think I need a hand getting started. I am working on a tool now that will allow me to edit the attribute fields in a title block from a VBA userform, 32 fields in all. My understanding of what needs to happen is the I need to:

 

1. Select the title block

2. Get the attribute information

3. Enter data into the tag value

 

I'm not slow, usually can wrap my head around technical topics pretty well, but this is escaping me. I know it is simple code, so any help would be appreciated, I have to get my head around this before biting off my next starter project.

 

Any help/links/code would be appreciated.

Link to comment
Share on other sites

Here is a vba example, you can use two methods either the order the attributes are in as per this example or using TAG names. There has been lots of suggestion to move away from VBA to either VL/lisp or .Net

 

Public Sub add_project_number()
' This Updates the project number
Dim SS As AcadSelectionSet
Dim Count As Integer
Dim FilterDXFCode(1) As Integer
Dim FilterDXFVal(1) As Variant
Dim attribs, newtext As Variant
Dim BLOCK_NAME As String
'On Error Resume Next
Dim startCH As Double
newtext = ThisDrawing.Utility.GetString(True, "Enter new project code : ")
FilterDXFCode(0) = 0
FilterDXFVal(0) = "INSERT"
FilterDXFCode(1) = 2
FilterDXFVal(1) = "DA1DRTXT"
BLOCK_NAME = "DA1DRTXT"
Set SS = ThisDrawing.SelectionSets.Add("issued")
SS.Select acSelectionSetAll, , , FilterDXFCode, FilterDXFVal

For Cntr = 0 To SS.Count - 1
  attribs = SS.Item(Cntr).GetAttributes
       
       
       attribs(1).TextString = newtext
               attribs(1).Update
        
Next Cntr
ThisDrawing.SelectionSets.Item("issued").Delete

End Sub

Link to comment
Share on other sites

Thanks BIGAL, I appreciate you taking the time to lend a hand, and I will definately take a look at this code. My company uses proprietary tools which have been created in VBA over the last 15 years, so even though we have started trans-coding our tools to .net, it's a large job and will take time; in the mean time I am developing a couple simple tools to "cut my teeth" and learn some basic programming so that there are at least two people in our office that can support. Being a CAD drafter/3D guy means I have a good head for tech, but programming is an alltogether different kind of beast.

 

Again, thanks for your help, I'm sure after i get this tool up and running I will be back looking for help with my next planned tool.;)

Link to comment
Share on other sites

The block attributes are the attribs(X) where x is the number of the attribute in its creation order not position. Ie Block 4 attributes attrib(0-3) yes starts at 0

 

The dxfcode is from the std Autocad DXF codes for entities (0 . Insert) means a block (2 . "da1txt") name of block (0 . "line") would mean a line (8 . "layer1") would mean the layer name. Examples shown as dotted pairs.

 

Try this tagname=attribs(1).TagString you can then check this against your Tagname.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...