CAD开发者社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

AutoCAD 2024 开发者帮助

Mode 属性 (ActiveX)

2024-5-18 19:08| 发布者: admin| 查看: 117| 评论: 0|原作者: admin|来自: AutoCAD

Mode 属性 (ActiveX)

指定属性定义的模式。

支持的平台:仅限 Windows

签名

VBA:

object.Mode 
对象

类型:属性

此属性应用于的对象。

属性值

只读:

类型:枚举acAttributeMode

  • acAttributeModeNormal:指定保留每个属性的当前可见性。
  • acAttributeModeInvisible:指定插入块时不显示属性值。ATTDISP 命令覆盖不可见模式。
  • acAttributeModeConstant:为块插入提供属性的固定值。
  • acAttributeModeVerify:提示您在插入块时验证属性值是否正确。
  • acAttributeModeLockPosition:锁定属性的位置。
  • acAttributeModeMultipleLine:允许属性转移到多行。
  • acAttributeModePreset:在插入包含预设属性的块时,将属性设置为默认值。

言论

注意:此属性的值存储在 AFLAGS 系统变量中。

例子

VBA:

Sub Example_Mode()
    ' This example creates an attribute definition in model space.
    ' It then queries the initial value of the Mode property,
    ' changes that value, and finally resets the value.
    
    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
    
    ' Return the current field length of the attribute
    Dim currMode As Integer
    Dim constant As String
    currMode = attributeObj.mode
    GoSub GETCONSTANT
    MsgBox "The Mode of the attribute is " & constant, vbInformation, "Mode Example"
    
    ' Change the field length
    attributeObj.mode = acAttributeModeInvisible
    GoSub GETCONSTANT
    attributeObj.Update
    MsgBox "The new Mode of the attribute is " & constant, vbInformation, "Mode Example"
    
    ' Reset the field length to the original value
    attributeObj.mode = currMode
    GoSub GETCONSTANT
    attributeObj.Update
    MsgBox "The Mode of the attribute is reset to " & constant, vbInformation, "Mode Example"
    Exit Sub
    
GETCONSTANT:
    ' Get the constant that corresponds to the current mode
    constant = Choose(attributeObj.mode, "acAttributeModeInvisible", "acAttributeModeConstant", "", "acAttributeModeVerify", "", "", "", "acAttributeModePreset")
    Return
End Sub

可视化 LISP:

(vl-load-com)
(defun c:Example_Mode()
    ;; This example creates an attribute definition in model space.
    ;; It then queries the initial value of the Mode property,
    ;; changes that value, and finally resets the value.
    (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)
    
    ;; Return the current field length of the attribute
    (setq currMode (vla-get-Mode attributeObj))

    ;; Get the constant that corresponds to the current mode
    (setq constant (cond
                       ((= (vla-get-Mode attributeObj) 0) "acAttributeModeNormal")
                       ((= (vla-get-Mode attributeObj) 1) "acAttributeModeInvisible")
                       ((= (vla-get-Mode attributeObj) 2) "acAttributeModeConstant")
                       ((= (vla-get-Mode attributeObj) 4) "acAttributeModeVerify")
                       ((= (vla-get-Mode attributeObj) 8) "acAttributeModePreset")
                   ))

    (alert (strcat "The Mode of the attribute is " constant))
    
    ;; Change the field length
    (vla-put-Mode attributeObj acAttributeModeInvisible)
  
    (setq constant (cond
                       ((= (vla-get-Mode attributeObj) 0) "acAttributeModeNormal")
                       ((= (vla-get-Mode attributeObj) 1) "acAttributeModeInvisible")
                       ((= (vla-get-Mode attributeObj) 2) "acAttributeModeConstant")
                       ((= (vla-get-Mode attributeObj) 4) "acAttributeModeVerify")
                       ((= (vla-get-Mode attributeObj) 8) "acAttributeModePreset")
                   ))
  
    (vla-Update attributeObj)
    (alert (strcat "The new Mode of the attribute is " constant))
    
    ;; Reset the field length to the original value
    (vla-put-Mode attributeObj currMode)
    (setq constant (cond
                       ((= (vla-get-Mode attributeObj) 0) "acAttributeModeNormal")
                       ((= (vla-get-Mode attributeObj) 1) "acAttributeModeInvisible")
                       ((= (vla-get-Mode attributeObj) 2) "acAttributeModeConstant")
                       ((= (vla-get-Mode attributeObj) 4) "acAttributeModeVerify")
                       ((= (vla-get-Mode attributeObj) 8) "acAttributeModePreset")
                   ))

    (vla-Update attributeObj)
    (alert (strcat "The Mode of the attribute is reset to " constant))
)

路过

雷人

握手

鲜花

鸡蛋

最新评论

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

GMT+8, 2025-3-14 07:45

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

返回顶部