[分享]获取块属性标记的值和修改块属性标记的值
<p>我是VBA初学者。最近在学习块属性时让我相当头痛。上网也没有查到太多这方面的资料,通过东拉西扯总算有所心得,我把学到的跟大家分享一下。</p><p>Public Function GetArrTagVar(ArrName As String, TagCH As String) As String<br/>'ArrName是块属性名称;TagCH是标记;<br/>'返回块属性标签对应的值;<br/> Dim attributeObj As AcadEntity<br/> Dim ArrayCH As Variant<br/> Dim Count As Integer<br/> GetArrTagVar = "" '设置返回值"空",未找到块属性或未找到标记<br/> On Error Resume Next<br/> For Each attributeObj In ThisDrawing.ModelSpace<br/> With attributeObj<br/> If .Name = ArrName Then<br/> If .HasAttributes Then<br/> ArrayCH = .GetAttributes<br/> For Count = LBound(ArrayCH) To UBound(ArrayCH)<br/> If ArrayCH(Count).TagString = TagCH Then<br/> GetArrTagVar = ArrayCH(Count).TextString<br/> End If<br/> Next Count<br/> End If<br/> End If<br/> End With<br/> Next attributeObj<br/>End Function</p><p>Public Function SetArrTagVar(ArrName As String, TagCH As String, ValueCH As String) As Boolean 'ArrName是块属性名称;TagCH是标签;<br/>'修改块属性标签对应的值;返回值是Boolean,Ture为修改成功,False为修改不成功;<br/> Dim attributeObj As AcadEntity<br/> Dim ArrayCH As Variant<br/> Dim Count As Integer<br/> SetArrTagVar = False '设置返回值"空",未找到块属必和未找到标签<br/> On Error Resume Next<br/> For Each attributeObj In ThisDrawing.ModelSpace<br/> With attributeObj<br/> If .Name = ArrName Then<br/> If .HasAttributes Then<br/> ArrayCH = .GetAttributes<br/> For Count = LBound(ArrayCH) To UBound(ArrayCH)<br/> If ArrayCH(Count).TagString = TagCH Then<br/> ArrayCH(Count).TextString = ValueCH<br/> SetArrTagVar = True<br/> End If<br/> Next Count<br/> End If<br/> End If<br/> End With<br/> Next attributeObj<br/>End Function</p>
页:
[1]