AddAttribute Method (ActiveX)

Creates an attribute definition at the given location with the specified properties.

Supported platforms: Windows only

Signature

VBA:

RetVal = object.AddAttribute(Height, Mode, Prompt, InsertionPoint, Tag, Value)
object

Type: Block, ModelSpace, PaperSpace

The objects this method applies to.

Height

Access: Input-only

Type: Double

The text height in the current drawing unit.

Mode

Access: Input-only

Type: AcAttributeMode enum

Any combination of constants can be used by adding them together:

  • acAttributeModeInvisible: Specifies that attribute values will not appear when you insert the block. The AutoCAD ATTDISP command overrides the Invisible mode.
  • acAttributeModeConstant: Gives attributes a fixed value for block insertions.
  • acAttributeModeVerify: Prompts to verify the attribute value is correct when the block is inserted.
  • acAttributeModeLockPosition: Locks the position of the attributes.
  • acAttributeModeMultipleLine: Allows the attributes to carry-over onto multiple lines. Prompts you to verify that the attribute value is correct when you insert the block.
  • acAttributeModePreset: Sets the attribute to its default value when you insert a block containing a current attribute. The value cannot be edited in this mode.
Prompt

Access: Input-only

Type: String

This string appears when a block containing this attribute is inserted. The default for this string is the Tag string. Inputting acAttributeModeConstant for the Mode parameter disables the prompt.

InsertionPoint

Access: Input-only

Type: Variant (three-element array of doubles)

The 3D WCS coordinates specifying the location for the attribute.

Tag

Access: Input-only

Type: String

This non-null string identifies each occurrence of the attribute. Enter any characters except spaces or exclamation points. AutoCAD changes lowercase letters to uppercase.

Value

Access: Input-only

Type: String

This non-null string is the default attribute value.

Return Value (RetVal)

Type: Attribute

The newly created Attribute object.

Remarks

An attribute definition is associated to the block for which it is created. Attribute definitions created in model space or paper space are not considered to be attached to any given block.

The AutoCAD AFLAGS system variable stores the mode setting. You can query this value using the GetVariable method, or set it using the SetVariable method.

Examples

VBA:

Sub Example_AddAttribute()
    ' This example creates an attribute definition in model space.
    
    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
    
    ' Define the attribute definition
    height = 1#
    mode = acAttributeModeVerify
    prompt = "New Prompt"
    insertionPoint(0) = 5#: insertionPoint(1) = 5#: insertionPoint(2) = 0
    tag = "NEW_TAG"
    value = "New Value"
    
    ' Create the attribute definition object in model space
    Set attributeObj = ThisDrawing.ModelSpace.AddAttribute(height, mode, prompt, insertionPoint, tag, value)
    ZoomAll
    
End Sub

Visual LISP:

(vl-load-com)
(defun c:Example_AddAttribute()
    ;; This example creates an attribute definition in model space.
    (setq acadObj (vlax-get-acad-object))
    (setq doc (vla-get-ActiveDocument acadObj))
   
    ;; Define the attribute definition
    (setq insertionPoint (vlax-3d-point 5 5 0) 
          attHeight 1
          attMode acAttributeModeVerify
          attPrompt "New Prompt"
          attTag "NEW_TAG"
          attValue "New Value")
    
    ;; Create the attribute definition object in model space
    (setq modelSpace (vla-get-ModelSpace doc))  
    (setq attributeObj (vla-AddAttribute modelSpace attHeight attMode attPrompt insertionPoint attTag attValue))
    (vla-ZoomAll acadObj)
)