CAD开发者社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

AutoCAD 2023 开发者帮助

GetSubEntity 方法 (ActiveX)

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

GetSubEntity 方法 (ActiveX)

以交互方式获取对象或子实体。

支持的平台:仅限 Windows

签名

VBA:

object.GetSubEntity Object, PickedPoint, TransMatrix, ContextData [, Prompt]
对象

类型: 实用程序

此方法应用到的对象。

对象

访问:仅输出

类型:对象

选取的对象或子实体。可以是任何绘图对象之一。

PickedPoint

访问:仅输出

类型:变体(双打的三元素阵列)

指定所选点的 3D WCS 坐标。

TransMatrix的

访问:仅输出

类型:变体(4x4 双打阵列)

应用于此图元的转换矩阵。

上下文数据

访问:仅输出

类型:变体(多头数组)

选定对象中任何嵌套对象的对象 ID 数组。

提示

访问:仅输入;自选

类型:变体(字符串)

要显示的文本,用于提示用户输入。

返回值 (RetVal)

无返回值。

言论

此方法要求 AutoCAD 用户通过在图形屏幕上选取一个点来选择对象。如果选取了对象或子实体,则在第一个参数中返回该对象或子实体,第二个参数将包含 WCS 坐标中选取的点。如果拾取点不在对象上,则该方法将失败。

此方法可以检索对象,即使该对象在屏幕上不可见或位于冻结图层上。

例子

VBA:

Sub Example_GetSubEntity()
    ' This example prompts the user to select on object on the screen with a mouse click,
    ' and returns some information about the selected object.
    
    AppActivate ThisDrawing.Application.Caption
    
    Dim Object As Object
    Dim PickedPoint As Variant, TransMatrix As Variant, ContextData As Variant
    Dim HasContextData As String
    
    On Error GoTo NOT_ENTITY
        
TRYAGAIN:
        
    MsgBox "Use the mouse to click on an object in the current drawing after dismissing this dialog box."
        
    ' Get information about selected object
    ThisDrawing.Utility.GetSubEntity Object, PickedPoint, TransMatrix, ContextData
    
    ' Process and display selected object properties
    HasContextData = IIf(VarType(ContextData) = vbEmpty, " does not ", " does ")
    
    MsgBox "The object you chose was an: " & TypeName(Object) & vbCrLf & _
            "Your point of selection was: " & PickedPoint(0) & ", " & _
                                              PickedPoint(1) & ", " & _
                                              PickedPoint(2) & vbCrLf & _
            "This object" & HasContextData & "have nested objects."
    
    Exit Sub
    
NOT_ENTITY:
    ' If you click on empty space or do not select an entity,
    ' this error will be generated
    If MsgBox("You have not selected an object.  Click OK to try again.", _
               vbOKCancel & vbInformation) = vbOK Then
        Resume TRYAGAIN
    End If
End Sub

可视化 LISP:

(vl-load-com)
(defun c:Example_GetSubEntity()
    ;; This example prompts the user to select on object on the screen with a mouse click,
    ;; and returns some information about the selected object.
    (setq acadObj (vlax-get-acad-object))
    (setq doc (vla-get-ActiveDocument acadObj))
    
    ;; Get information about selected object
    (vla-GetSubEntity (vla-get-Utility doc) 'Object 'PickedPoint 'TransMatrix 'ContextData "Select a subentity: ")
    
    ;; Process and display selected object properties
    (if (/= ContextData nil)
        (setq HasContextData " does ")
        (setq HasContextData " does not ")
    )
    
    (alert (strcat "The object you chose was an: " (vla-get-ObjectName Object)
                   "\nYour point of selection was: " (rtos (vlax-safearray-get-element PickedPoint 0) 2) ", "
		                                                   (rtos (vlax-safearray-get-element PickedPoint 1) 2) ", "
		                                                   (rtos (vlax-safearray-get-element PickedPoint 2) 2)
                   "\nThis object" HasContextData "have nested objects."))
)

路过

雷人

握手

鲜花

鸡蛋

最新评论

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

GMT+8, 2024-12-15 22:25

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

返回顶部