Create Attribute Definitions and Attribute References

To create an attribute reference, first you must create an attribute definition on a block by using the AddAttribute method. This method requires six values as input: the height of the attribute text, the Attribute mode, a prompt string, the insertion point, the tag string, and the default attribute value.

The mode value is optional. There are five constants you can enter to specify the Attribute mode:


Specifies that the current mode of each attribute is maintained.


Specifies that attribute values won't appear when you insert the block. The ATTDISP command overrides the Invisible mode.


Gives attributes a fixed value for block insertions.


Prompts you to verify that the attribute value is correct when you insert the block.


Sets the attribute to its default value when you insert a block containing a present attribute. The value cannot be edited in this mode.

You can enter none, any combination, or all of the options. To specify a combination of options, add the constants together. For example, you can enter acAttributeModeInvisible + acAttributeModeConstant.

The prompt string appears when a block containing the attribute is inserted. The default for this string is the Tag string. Input acAttributeModeConstant for the mode to disable the prompt.

The tag string identifies each occurrence of the attribute. You can use any characters except spaces or exclamation points. AutoCAD changes lowercase letters to uppercase.

Once the attribute definition is defined in a block, whenever you insert the block using the InsertBlock method you can specify a different value for the attribute reference.

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

Define an attribute definition

This example creates a block and then adds an attribute to the block. The block is then inserted into the drawing.

Sub Ch10_CreatingAnAttribute()
	' Define 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, "BlockWithAttribute")

	' Add an attribute to the block
	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 = "New Prompt"
	insertionPoint(0) = 5
	insertionPoint(1) = 5
	insertionPoint(2) = 0
	tag = "New Tag"
	value = "New Value"
	Set attributeObj = blockObj.AddAttribute(height, mode, _
						prompt, insertionPoint, tag, value)
	' Insert the block, creating a block reference
	' and an attribute reference
	Dim blockRefObj As AcadBlockReference
	insertionPnt(0) = 2
	insertionPnt(1) = 2
	insertionPnt(2) = 0
	Set blockRefObj = ThisDrawing.ModelSpace.InsertBlock _
			 (insertionPnt, "BlockWithAttribute", 1#, 1#, 1#, 0)
End Sub