依据块名作选择集; 然后用下面方法得到属性:
' Get the attributes for the block reference Dim varAttributes As Variant varAttributes = blockRefObj.GetAttributes
Dim strAttributes As String Dim I As Integer For I = LBound(varAttributes) To UBound(varAttributes) strAttributes = strAttributes & " Tag: " & varAttributes(I).TagString & _ " Value: " & varAttributes(I).textString & " " Next
作选择集:
Public Sub test() ' Create the selection set Dim ssetObj As AcadSelectionSet Set ssetObj = ThisDrawing.SelectionSets.Add("SSET")
Dim mode As Integer
mode = acSelectionSetAll
' Add all the Circles to the selection set that lie within the crossing of (28,17,0) and ' (-3.3, -3.6,0) by filtering from the current drawing Dim gpCode(0 To 1) As Integer Dim dataValue(0 To 1) As Variant gpCode(0) = 0 dataValue(0) = "Insert" gpCode(1) = 2 dataValue(1) = "a" '块名
Dim groupCode As Variant, dataCode As Variant groupCode = gpCode dataCode = dataValue
ssetObj.Select mode, , , groupCode, dataCode
MsgBox ssetObj.Count
'然后你循环ssetObj中的每个块实体...
End Sub
这样吧:
Sub test() Dim blks As AcadBlocks Dim blk As AcadBlock
Set blks = ThisDrawing.Blocks
Set blk = blks.Item("a")
Dim i As Integer
For i = 0 To blk.Count - 1 Dim obj As AcadObject Set obj = blk.Item(i) Dim str As String str = obj.ObjectName If obj.ObjectName = "AcDbAttributeDefinition" Then Dim attrObj As AcadAttribute Set attrObj = obj Dim tag, prompt, value As String tag = attrObj.TagString prompt = attrObj.PromptString value = attrObj.TextString MsgBox "Tag: " & tag & vbCr & "Value: " & value & vbCr & "Value: " & value & vbCr End If Next