HasAttributes Property (ActiveX)

Specifies whether the block has any attributes in it.

Supported platforms: Windows only

Signature

VBA:

object.HasAttributes
object

Type: BlockReferences, ComparedReference, ExternalReference, MInsertBlock

The object this property applies to.

Property Value

Read-only: Yes

Type: Boolean

Remarks

This property is True if the block reference contains any editable or constant (non-editable) attributes. It is False if there are no attributes.

To return an array of Attribute objects associated to a block, use the GetAttributes method.

Examples

VBA:

Sub Example_HasAttributes()
    ' This example first creates a block without attributes.
    ' It then inserts the block and checks whether it has attributes.
    ' It then adds attributes to the block and inserts it again.
    ' Then it checks the new block reference for attributes.
    
    ' 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, "CircleBlock")
    
    ' Add a circle to the block
    Dim circleObj As AcadCircle
    Dim center(0 To 2) As Double
    Dim radius As Double
    center(0) = 0: center(1) = 0: center(2) = 0
    radius = 1
    Set circleObj = blockObj.AddCircle(center, radius)
   
    ' Insert the block
    Dim blockRefObj As AcadBlockReference
    insertionPnt(0) = 2#: insertionPnt(1) = 2#: insertionPnt(2) = 0
    Set blockRefObj = ThisDrawing.ModelSpace.InsertBlock(insertionPnt, "CircleBlock", 1#, 1#, 1#, 0)
    ThisDrawing.Application.ZoomAll
    MsgBox "This block reference " & IIf(blockRefObj.HasAttributes, "has attributes.", "does not have attributes."), , "Has Attributes Example"
    
    ' Add attributes to the block definition.
    ' 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) = 1#: insertionPoint(1) = 1#: insertionPoint(2) = 0
    tag = "Attribute_Tag"
    value = "Attribute Value"
    
    ' Create the attribute definition
    Set attributeObj = blockObj.AddAttribute(height, mode, prompt, insertionPoint, tag, value)
       
    ' Insert the block again
    Dim blockRefObj2 As AcadBlockReference
    insertionPnt(0) = 3#: insertionPnt(1) = 3#: insertionPnt(2) = 0
    Set blockRefObj2 = ThisDrawing.ModelSpace.InsertBlock(insertionPnt, "CircleBlock", 1#, 1#, 1#, 0)
    ZoomAll
    MsgBox "The first block reference " & IIf(blockRefObj.HasAttributes, "has attributes.", "does not have attributes.") & vbCrLf & _
            "The second block reference " & IIf(blockRefObj2.HasAttributes, "has attributes.", "does not have attributes."), , "Has Attributes Example"

End Sub

Visual LISP:

(vl-load-com)
(defun c:Example_HasAttributes()
    ;; This example first creates a block without attributes.
    ;; It then inserts the block and checks whether it has attributes.
    ;; It then adds attributes to the block and inserts it again.
    ;; Then it checks the new block reference for attributes.
    (setq acadObj (vlax-get-acad-object))
    (setq doc (vla-get-ActiveDocument acadObj))

    ;; Create the block
    (setq insertionPnt (vlax-3d-point 0 0 0))  
    (setq blockObj (vla-Add (vla-get-Blocks doc) insertionPnt "CircleBlock"))
    
    ;; Add a circle to the block
    (setq center (vlax-3d-point 0 0 0))  
    (setq radius 1)
    (setq circleObj (vla-AddCircle blockObj center radius))
   
    ;; Insert the block
    (setq insertionPnt (vlax-3d-point 2 2 0))  
    (setq modelSpace (vla-get-ModelSpace doc))
    (setq blockRefObj (vla-InsertBlock modelSpace insertionPnt "CircleBlock" 1 1 1 0))
    (vla-ZoomAll acadObj)
    (alert (strcat "This block reference " (if (= (vla-get-HasAttributes blockRefObj) :vlax-true) "has attributes." "does not have attributes.")))
    
    ;; Add attributes to the block definition.
    ;; Define the attribute definition.
    (setq insertionPoint (vlax-3d-point 1 1 0)
          attHeight 1
          attMode acAttributeModeVerify
          attPrompt "Attribute Prompt"
          attTag "Attribute_Tag"
          attValue "Attribute Value")
    
    ;; Create the attribute definition
    (setq attributeObj (vla-AddAttribute blockObj attHeight attMode attPrompt insertionPoint attTag attValue))
       
    ;; Insert the block again
    (setq insertionPnt (vlax-3d-point 3 3 0))  
    (setq blockRefObj2 (vla-InsertBlock modelSpace insertionPnt "CircleBlock" 1 1 1 0))
    (vla-ZoomAll acadObj)
    (alert (strcat "The first block reference " (if (= (vla-get-HasAttributes blockRefObj) :vlax-true) "has attributes." "does not have attributes.")
                   "\nThe second block reference " (if (= (vla-get-HasAttributes blockRefObj2) :vlax-true) "has attributes." "does not have attributes.")))
)