CAD开发者社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

ActiveX 开发指南

相关分类

预设属性 (ActiveX)

2023-1-3 08:15| 发布者: admin| 查看: 349| 评论: 0|来自: AutoCAD

摘要: 指定属性是否为预设。

指定属性是否为预设。

支持的平台:仅窗口

签名

工 务 局:

object.Preset
对象

类型:属性

此属性适用的对象。

属性值

只读:

类型:布尔

  • True:该属性是预设属性。
  • False:该属性不是预设属性。

言论

当用户插入块时,预设属性将属性设置为其默认值或预设值。

属性只能作为四种可选模式之一存在:常量、预设、不可见或验证。AFLAGS 系统变量存储当前模式设置。可以使用属性查询当前模式。Mode

例子

工 务 局:

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))
)

路过

雷人

握手

鲜花

鸡蛋

最新评论

QQ|Archiver|CAD开发者社区 ( 苏ICP备2022047690号-1 )

GMT+8, 2024-5-19 15:57

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

返回顶部