Jump to content

Title block attributes


Recommended Posts

Hi all,


I'm trying to access title block attributes from VBA so that I can standarise them across drawing sets. I'm very experienced with Excel VBA but I'm afraid I'm a total noob with AutoCAD. My drawing contains a block called A3BORDER, I can read the items from it and by looking for the right ObjectName I can ignore static text and graphic objects. Here's the code:


Sub foo()
   Set myblk = ThisDrawing.Blocks("*PAPER_SPACE").Item(2)
   For i = 0 To ThisDrawing.Blocks("A3BORDER").Count - 1
       Set myobj = ThisDrawing.Blocks("A3BORDER").Item(i)
       If myobj.ObjectName = "AcDbAttributeDefinition" Then
           Debug.Print myobj.StyleName, myobj.TextString
       End If
End Sub

The problem is I get the attributes from the template not the layout, for example SHEET_NO comes back with value 'XX OF YY' instead of '8 OF 8'. 'XX OF YY' is the default value I see if I edit the title block in the Block Editor.

I've tried looking through the items in PAPER_SPACE and one has EffectiveName = "A3BORDER", is that the instance I need? If so how do I get it's items?




Link to comment
Share on other sites

Well there's a productive first response. Pardon my ignorance of etiquette on this board but I felt it may be useful to show that I am comfortable with VBA but not the AutoCAD object structure. Ho hum.

Link to comment
Share on other sites

Not sure exactly about your code, but maybe the object you need to be looking for is


myobj.ObjectName = "AcDbAttribute"


instead of


myobj.ObjectName = "AcDbAttributeDefinition"

Link to comment
Share on other sites

Hi Spiff,


Thanks but the block has no AcDbAttribute items, just AcDbAttributeDefinition, AcDbText for the fixed test and other graphical items such as lines etc. You've set me on the right path though. I had already tried this


Which fails so I'd not bothered with GetAttributes. What I had not done is the HasAttributes test on myblk for some reason. That returns True and GetAttributes returns the the text I'm after. The clue should have been that the above code fails to the debug prompt, if it was a valid test it would have returned False. By testing myblk instead I'm effectively this instead doing this (this is not valid code, just illustration)


Which obviously is the instance on paper not the one I see in the block editor.


Thanks again Spiff88


Link to comment
Share on other sites

There is posts here about using VBA and title block attributes I use them every day so I have posted code will try to find posts for you


Couldn't find pre posted code so here it is again may be helpfull


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"
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
Next Cntr

End Sub

Edited by BIGAL
Link to comment
Share on other sites

  • 2 weeks later...

I'm not sure if you got your question answered, but the object you might be looking for is not att definition, but Att Value. I'm still trying to learn the methods and such in AutoCAD so I can't be a great deal of help, but I have come across this in other situations. Not sure, but worth a try.:)

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.

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...