blockRefObj.HasAttributes可以判断块引用对象中是否包含属性。
- Sub test()
- ' 获取块引用对象的属性集合
- Dim varAttributes As Variant
- varAttributes = blockRefObj.GetAttributes
-
- ' 枚举集合,根据属性的标签得到其值或者对象
- Dim strAttributes1 As String
- Dim strAttributes2 As String
- Dim objAttributes As AcadAttributeReference
- Dim I As Integer
- For I = LBound(varAttributes) To UBound(varAttributes)
- If varAttributes(I).TagString = "单重" Then
- strAttributes1 = varAttributes(I).TextString
- ElseIf varAttributes(I).TagString = "数量" Then
- strAttributes2 = varAttributes(I).TextString
- ElseIf varAttributes(I).TagString = "总重" Then
- Set objAttributes = varAttributes(I)
- End If
- Next
-
- ' 判断属性值是否是数字,如果是的话相乘并赋值
- If IsNumeric(strAttributes1) And IsNumeric(strAttributes2) Then
- objAttributes.TextString = strAttributes1 * strAttributes2
- End If
-
- ' 更新块
- blockRefObj.Update
- End Sub
|