CAD开发者社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

ActiveX 开发指南

相关分类

GetConstantAttributes Method (ActiveX)

2023-1-4 08:58| 发布者: admin| 查看: 651| 评论: 0|来自: AutoCAD

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

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

支持的平台:仅窗口

签名

工 务 局:

RetVal = object.GetConstantAttributes
对象

类型:块引用,比较引用,外部引用最小块

此方法适用的对象。

返回值(RetVal)

类型:变量(属性对象数组)

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

言论

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

例子

工 务 局:

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

Visual 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 )

GMT+8, 2024-5-12 05:54

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

返回顶部