可以使用 和 方法从图形中提取属性信息。GetAttributesGetConstantAttributes 该方法返回附加到块的属性引用的数组及其当前值。该方法返回附加到模块或外部引用的常量属性数组。此方法返回的属性是常量属性定义,而不是属性引用。GetAttributesGetConstantAttributes 您不需要模板文件来提取属性信息,也不会创建任何属性信息文件。只需迭代属性引用数组,使用属性 -reference 的 and 属性来检查属性信息。TagStringTextString 该属性表示属性引用的单个标记。该属性包含属性引用的值。TagStringTextString 获取属性参考信息此示例创建一个块,然后向该块添加一个属性。然后将块插入到图形中。然后,使用消息框返回并显示属性数据。然后更新块引用的属性数据,并再次返回并显示属性数据。 Sub Ch10_GettingAttributes() ' Create the block Dim blockObj As AcadBlock Dim insertionPnt(0 To 2) As Double insertionPnt(0) = 0 insertionPnt(1) = 0 insertionPnt(2) = 0 Set blockObj = ThisDrawing.Blocks.Add _ (insertionPnt, "TESTBLOCK") ' Define the attribute definition Dim attributeObj As AcadAttribute Dim height As Double Dim mode As Long Dim prompt As String Dim insertionPoint(0 To 2) As Double Dim tag As String Dim value As String height = 1# mode = acAttributeModeVerify prompt = "Attribute Prompt" insertionPoint(0) = 5 insertionPoint(1) = 5 insertionPoint(2) = 0 tag = "Attribute Tag" value = "Attribute Value" ' Create the attribute definition object on the block Set attributeObj = blockObj.AddAttribute _ (height, mode, prompt, _ insertionPoint, tag, value) ' Insert the block Dim blockRefObj As AcadBlockReference insertionPnt(0) = 2 insertionPnt(1) = 2 insertionPnt(2) = 0 Set blockRefObj = ThisDrawing.ModelSpace.InsertBlock _ (insertionPnt, "TESTBLOCK", 1, 1, 1, 0) ZoomAll ' Get the attributes for the block reference Dim varAttributes As Variant varAttributes = blockRefObj.GetAttributes ' Move the attribute tags and values into a ' string to be displayed in a Msgbox Dim strAttributes As String strAttributes = "" Dim I As Integer For I = LBound(varAttributes) To UBound(varAttributes) strAttributes = strAttributes + " Tag: " + _ varAttributes(I).TagString + vbCrLf + _ " Value: " + varAttributes(I).textString Next MsgBox "The attributes for blockReference " + _ blockRefObj.Name & " are: " & vbCrLf _ & strAttributes ' Change the value of the attribute ' Note: There is no SetAttributes. Once you have the ' variant array, you have the objects. ' Changing them changes the objects in the drawing. varAttributes(0).textString = "NEW VALUE!" ' Get the attributes again Dim newvarAttributes As Variant newvarAttributes = blockRefObj.GetAttributes ' Again, display the tags and values strAttributes = "" For I = LBound(varAttributes) To UBound(varAttributes) strAttributes = strAttributes + " Tag: " + _ newvarAttributes(I).TagString + vbCrLf + _ " Value: " + newvarAttributes(I).textString Next MsgBox "The attributes for blockReference " & _ blockRefObj.Name & " are: " & vbCrLf _ & strAttributes End Sub 父主题: |
|Archiver|CAD开发者社区 ( 苏ICP备2022047690号-1 苏公网安备32011402011833)
GMT+8, 2025-1-8 19:51
Powered by Discuz! X3.4
Copyright © 2001-2021, Tencent Cloud.