Sub dd() Dim pBlockRef As AcadBlockReference '块参照 Dim pntPickPoint As Variant '返回的PICKPOINT Dim pAttributeRef As AcadAttributeReference '属性参考 Dim aAttributeRefArray As Variant '属性参考数组 Dim strAttributeRefText As String '属性值 Dim nIndex As Integer '索引
On Error GoTo errHandle
ThisDrawing.Utility.GetEntity pBlockRef, pntPickPoint, "选择一个块参照:" '用户选择,具体参数的含义参照AUTOCAD帮助 '下面判断用户选择的是否是一个块参照对象 If pBlockRef.ObjectName <> "AcDbBlockReference" Then MsgBox "你选择的不是块参照!" Exit Sub '选择的不是块参照,退出 End If '选择了一个块参照 '创建一个文件等待写入“c:\123.txt” Open "c:\123.txt" For Output As #1 aAttributeRefArray = pBlockRef.GetAttributes() '获得该块中所有的属性参考 For nIndex = LBound(aAttributeRefArray) To UBound(aAttributeRefArray) Set pAttributeRef = aAttributeRefArray(nIndex) strAttributeRefText = pAttributeRef.TextString Write #1, strAttributeRefText Next Close #1 '关闭文件 Exit Sub errHandle: '错误处理 MsgBox Err.Description End Sub