要创建属性引用,首先必须使用该方法在块上创建属性定义。AddAttribute 此方法需要六个值作为输入:属性文本的高度、模式、提示字符串、插入点、标记字符串和默认属性值。模式值是可选的。您可以输入五个常量来指定属性模式:Attribute
您可以输入任何选项、任意组合或所有选项。若要指定选项组合,请将常量相加。例如,您可以输入 。acAttributeModeInvisible + acAttributeModeConstant 插入包含该属性的块时,将出现提示字符串。此字符串的默认值为 Tag 字符串。用于禁用提示的模式的输入。acAttributeModeConstant 标记字符串标识属性的每次匹配项。您可以使用除空格或感叹号以外的任何字符。AutoCAD 将小写字母更改为大写字母。 在块中定义属性定义后,每当使用该方法插入块时,都可以为属性引用指定不同的值。InsertBlock 属性定义与创建属性定义的块相关联。在模型空间或图纸空间上创建的属性定义不被视为附加到任何给定块。 定义属性定义此示例创建一个块,然后向该块添加一个属性。然后将块插入到图形中。 Sub Ch10_CreatingAnAttribute() ' Define 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, "BlockWithAttribute") ' Add an attribute to the block 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 = "New Prompt" insertionPoint(0) = 5 insertionPoint(1) = 5 insertionPoint(2) = 0 tag = "New Tag" value = "New Value" Set attributeObj = blockObj.AddAttribute(height, mode, _ prompt, insertionPoint, tag, value) ' Insert the block, creating a block reference ' and an attribute reference Dim blockRefObj As AcadBlockReference insertionPnt(0) = 2 insertionPnt(1) = 2 insertionPnt(2) = 0 Set blockRefObj = ThisDrawing.ModelSpace.InsertBlock _ (insertionPnt, "BlockWithAttribute", 1#, 1#, 1#, 0) End Sub 父主题: |
|Archiver|CAD开发者社区 ( 苏ICP备2022047690号-1 苏公网安备32011402011833)
GMT+8, 2025-1-8 19:34
Powered by Discuz! X3.4
Copyright © 2001-2021, Tencent Cloud.