hollgod 发表于 2003-11-14 22:29:00

求教一个关于VBA编程提取属性块里头的数值的问题

我的材料表是用属性做的块
计算材料的重量时很麻烦,我想利用程序实现(偷懒^_^)对材料规格的计算,得出单重,并将单重与数量相乘得到总重
问题:如何从属性块里头提取其中的一个属性并取值或附值
请教各位大侠
谢谢

efan2000 发表于 2003-11-15 10:13:00

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

hollgod 发表于 2003-11-19 15:01:00

Thanks! You are very kind!
页: [1]
查看完整版本: 求教一个关于VBA编程提取属性块里头的数值的问题