GetConstantAttributes Example

Using Programming Languages other than 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

 

   Comments?