CAD开发者社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

AutoCAD 2019 开发者帮助

GetConstantAttributes 方法 (ActiveX)

2024-5-18 17:51| 发布者: admin| 查看: 76| 评论: 0|原作者: admin|来自: AutoCAD

GetConstantAttributes 方法 (ActiveX)

获取块或外部引用中的常量属性。

支持的平台:仅限 Windows

签名

VBA:

RetVal = object.GetConstantAttributes
对象

类型:BlockReferenceExternalReferenceMInsertBlock

此方法应用到的对象。

返回值 (RetVal)

类型:Variant(Attribute 对象数组)

块引用的常量对象数组。Attribute

言论

此方法返回附加到模块或外部引用的常量属性数组。返回的属性是常量属性定义,而不是属性引用。

例子

VBA:

Sub Example_GetConstantAttributes()
    ' This example creates a constant attribute definition on a block.
    ' It then queries the block to return the attribute.
    
    ' Create the block to hold the attribute
    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, "New_Block")
    
    ' Define the attribute definition
    Dim attributeObj As AcadAttribute
    Dim height As Double
    Dim mode As Long
    Dim prompt As String
    Dim tag As String
    Dim value As String
    height = 1#
    mode = acAttributeModeConstant
    prompt = "Constant Prompt"
    insertionPnt(0) = 5#: insertionPnt(1) = 5#: insertionPnt(2) = 0#
    tag = "Constant_Tag"
    value = "Constant Value"
    
    ' Create the attribute definition object on the block
    Set attributeObj = blockObj.AddAttribute(height, mode, prompt, insertionPnt, tag, value)
    ZoomAll
    
    ' Insert the block into the drawing
    Dim blockRefObj As AcadBlockReference
    insertionPnt(0) = 2#: insertionPnt(1) = 2#: insertionPnt(2) = 0
    Set blockRefObj = ThisDrawing.ModelSpace.InsertBlock(insertionPnt, "New_Block", 1#, 1#, 1#, 0)
    
    ' Get the constant attribute definition from the block
    Dim queryAttribute As Variant
    queryAttribute = blockRefObj.GetConstantAttributes
    
    Dim count As Integer
    count = UBound(queryAttribute) - LBound(queryAttribute)
    MsgBox "The block reference has " & count & " constant attributes."
End Sub

可视化 LISP:

(vl-load-com)
(defun c:Example_GetConstantAttributes()
    ;; This example creates a constant attribute definition on a block.
    ;; It then queries the block to return the attribute.
    (setq acadObj (vlax-get-acad-object))
    (setq doc (vla-get-ActiveDocument acadObj))
  
    ;; Create the block to hold the attribute
    (setq insertionPnt (vlax-3d-point 0 0 0))
    (setq blockObj (vla-Add (vla-get-Blocks doc) insertionPnt "New_Block"))
    
    ;; Define the attribute definition
    (setq insertionPnt (vlax-3d-point 5 5 0)
          attHeight 1
          attMode acAttributeModeConstant
          attPrompt "Constant Prompt"
          attTag "Constant_Tag"
          attValue "Constant Value")
    
    ;; Create the attribute definition object on the block
    (setq attributeObj (vla-AddAttribute blockObj attHeight attMode attPrompt insertionPnt attTag attValue))
    
    ;; Insert the block into the drawing
    (setq insertionPnt (vlax-3d-point 2 2 0))
    (setq modelSpace (vla-get-ModelSpace doc))
    (setq blockRefObj (vla-InsertBlock modelSpace insertionPnt "New_Block" 1 1 1 0))
    (vla-ZoomAll acadObj)

    ;; Get the constant attribute definition from the block
    (setq queryAttribute (vlax-variant-value (vla-GetConstantAttributes blockRefObj)))
    
    (setq count (1+ (vlax-safearray-get-u-bound queryAttribute 1)))
    (alert (strcat "The block reference has " (itoa count) " constant attributes."))
)

路过

雷人

握手

鲜花

鸡蛋

最新评论

QQ|Archiver|CAD开发者社区 ( 苏ICP备2022047690号-1   苏公网安备32011402011833)

GMT+8, 2024-12-15 22:20

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

返回顶部