Preset Property (ActiveX)

Specifies if the attribute is preset.

Supported platforms: Windows only

Signature

VBA:

object.Preset
object

Type: Attribute

The object this property applies to.

Property Value

Read-only: No

Type: Boolean

Remarks

A preset attribute sets the attribute to its default, or preset, value when the user inserts the block.

An attribute may exist as only one of four optional modes: constant, preset, invisible, or verify. The AFLAGS system variable stores the current mode settings. You can query the current mode using the Mode property.

Examples

VBA:

Sub Example_Preset()
    ' This example creates a block containing an attribute definition.
    ' Initially, the attribute has the preset flag turned on and will display a preset
    ' value for the attribute when the parent block is inserted as a reference.
    '
    ' Every time the example is run, attempt to find the attribute and
    ' toggle the Preset value.
    '
    ' * Note: After running this example for the first time, select the menu "Insert/Block..."
    ' and create a block reference from "Block-PRESET".  You will see
    ' the preset value display for the attribute when the blockref is displayed.
    '
    ' Then run the example again and repeat the block insert.  Notice this time that the
    ' preset has been turned off, and you are now prompted for the attribute value.
    
    Dim attributeObj As AcadAttribute
    Dim height As Double, mode As Long, prompt As String, tag As String, value As String
    Dim AttrInsertionPoint(0 To 2) As Double
    Dim BlockInsertionPoint(0 To 2) As Double
    Dim newBlock As AcadBlock
    Dim IsPreset As String
    
    ' Determine if this block has already been created.  If so, get the block and
    ' the attribute inside; otherwise, create a new block containing an
    ' attribute.
    On Error Resume Next
    
    Set newBlock = ThisDrawing.Blocks("Block-PRESET")
    
    
    If Err = 0 Then         ' The example block has been created
        Set attributeObj = newBlock.Item(0)                 ' Get only object in example block
    
        attributeObj.Preset = Not attributeObj.Preset     ' Toggle the attribute preset value
    
    ElseIf Err <> 0 Then    ' The example block has not been created
    
        ' Create a new block to hold the Attribute object
        BlockInsertionPoint(0) = 0: BlockInsertionPoint(1) = 0: BlockInsertionPoint(2) = 0
        Set newBlock = ThisDrawing.Blocks.Add(BlockInsertionPoint, "Block-PRESET")
    
        ' Define the attribute definition
        AttrInsertionPoint(0) = 0: AttrInsertionPoint(1) = 0: AttrInsertionPoint(2) = 0
        height = 1#
        mode = acAttributeModePreset
        prompt = "New Prompt"
        tag = "New_Tag"
        value = "Preset"
        
        ' Add attribute definition object to new block
        Set attributeObj = newBlock.AddAttribute(height, mode, prompt, AttrInsertionPoint, tag, value)
    
    End If
    
    On Error GoTo 0

    ' Read the attribute back and display information
    IsPreset = IIf(attributeObj.Preset, "has a preset value of: " & attributeObj.textString, _
                   "does not have a preset value")
                   
    MsgBox "The block attribute " & IsPreset, vbInformation
End Sub

Visual LISP:

(vl-load-com)
(defun c:Example_Preset()
    ;; This example creates a block containing an attribute definition.
    ;; Initially, the attribute has the preset flag turned on and will display a preset
    ;; value for the attribute when the parent block is inserted as a reference.
    ;;
    ;; Every time the example is run, attempt to find the attribute and
    ;; toggle the Preset value.
    ;;
    ;; * Note: After running this example for the first time, select the menu "Insert/Block..."
    ;; and create a block reference from "Block-PRESET".  You will see
    ;; the preset value display for the attribute when the blockref is displayed.
    ;;
    ;; Then run the example again and repeat the block insert.  Notice this time that the
    ;; preset has been turned off, and you are now prompted for the attribute value.
    (setq acadObj (vlax-get-acad-object))
    (setq doc (vla-get-ActiveDocument acadObj))

    ;; Determine if this block has already been created.  If so, get the block and
    ;; the attribute inside; otherwise, create a new block containing an
    ;; attribute.
    
    (setq err (vl-catch-all-apply 'vla-Item (list (vla-get-Blocks doc) "Block-PRESET")))
  
    (if (/= (type err) 'VL-CATCH-ALL-APPLY-ERROR)             ;; The example block has been created
        (progn
            (setq newBlock err)
            (setq attributeObj (vla-Item newBlock 0))         ;; Get only object in example block
    
            (vla-put-Preset attributeObj (if (= (vla-get-Preset attributeObj) :vlax-true) :vlax-false :vlax-true))     ;; Toggle the attribute preset value
        )
        (progn
	           ;; Create a new block to hold the Attribute object
            (setq BlockInsertionPoint (vlax-3d-point 0 0 0))

            (setq newBlock (vla-Add (vla-get-Blocks doc) BlockInsertionPoint "Block-PRESET"))

	           ;; Define the attribute definition
            (setq attrInsertionPoint (vlax-3d-point 0 0 0)
	                 attHeight 1
	                 attMode acAttributeModePreset
	                 attPrompt "New Prompt"
	                 attTag "New_Tag"
                  attValue "Preset")
	        
	           ;; Add attribute definition object to new block
	           (setq attributeObj (vla-AddAttribute newBlock attHeight attMode attPrompt attrInsertionPoint attTag attValue))
        )
    )
    
    ;; Read the attribute back and display information
    (setq IsPreset (if (= (vla-get-Preset attributeObj) :vlax-true)
                             (strcat "has a preset value of: " (vla-get-TextString attributeObj))
                                     "does not have a preset value"))
                   
    (alert (strcat "The block attribute " IsPreset))
)