Gets the constant attributes in the block or external reference.
Supported platforms: Windows only
VBA:
RetVal = object.GetConstantAttributes
Type: BlockReference, ComparedReference, ExternalReference, MInsertBlock
The objects this method applies to.
Type: Variant (array of Attribute objects)
The array of Attribute objects that are constant for the block reference.
This method returns an array of constant attributes attached to the block or external reference. The attributes returned are the constant attribute definitions, not attribute references.
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
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."))
)