Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations IDS on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA and AutoCAD objects

Status
Not open for further replies.

djs

Electrical
Mar 21, 2001
719
I am writing a VBA porgram in AutoCAD to modify some existing drawings. In particular the program is updating the attribute data for some block references. I have found out how to access the text data and update it once I have the block reference.
The problem is that the block references are in the ModelSpace collection which is a collection of all of the entities in the drawing. This includes text, lines etc. As I go through these entities, I need a way to determine if it is a block reference. As I go through the ModelSpace collection I reference each entity as an object. I need a way to determine if an object is of type AcadBlockReference. Does anyone have any ideas?
 
Replies continue below

Recommended for you

Select the AcadBlockReference in SelectionSet is best. Then cycle through SelectionSet doing your stuff.
 
I found a way to determine what an object is. There is a function call TypeName which returns the class name of the function argumnet. Using this I can only process the Block References.
I looked up the SelectionSet object in the help, and you have to add objects to the collection first. Not very helpful in my case.
 
zimgirl is right, you need to get a selection set of only blockreferences, the following should help to start...




Dim sSSname as String
Dim iCode As Integer
Dim iMode As Integer
Dim iAcadCodes(0) As Integer
Dim vAcadValues(0) As Variant
Dim vFilterType As Variant
Dim vFilterData As Variant
Dim acSelSet As AcadSelectionSet
Dim acSelSets As AcadSelectionSets
'''''''''''''''''''''''''''''''''''''''

iCode = 0 'object type
iMode = 5 'acSelectionSetAll
sSSname = "SSET"
Set acSelSets = ThisDrawing.SelectionSets

For Each acSelSet In acSelSets
If acSelSet.Name = sSSname Then
ThisDrawing.SelectionSets.Item(sSSname).Delete
Exit For
End If
Next

Set acSelSet = ThisDrawing.SelectionSets.Add(sSSname)

iAcadCodes(0) = iCode 'dxf code for block name
vAcadValues(0) = "INSERT"
vFilterType = iAcadCodes
vFilterData = vAcadValues

acSelSet.Select iMode, , , vFilterType, vFilterData

"Everybody is ignorant, only on different subjects." — Will Rogers
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor