CAD开发者社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

ActiveX 开发指南

相关分类

GetEntity Method (ActiveX)

2023-1-4 08:28| 发布者: admin| 查看: 605| 评论: 0|来自: AutoCAD

摘要: 以交互方式获取对象。

以交互方式获取对象。

支持的平台:仅窗口

签名

工 务 局:

object.GetEntity Object, PickedPoint [, Prompt]
对象

类型:实用工具

此方法适用的对象。

对象

访问:仅输出

类型:对象

拾取的对象。可以是任何图形对象之一。

拾取点

访问:仅输出

类型:变体(双精度的三元素数组)

指定所选点的三维 WCS 坐标。

提示

访问:仅输入;自选

类型:变体(字符串)

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

返回值(RetVal)

无返回值。

言论

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

返回的拾取点不一定位于所选对象上。返回的点表示选择时十字准线的位置。此点与对象之间的关系因选择框的大小和当前缩放比例而异。GetEntity

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

例子

工 务 局:

Sub Example_GetEntity()
    ' This example creates several objects in model space. It then
    ' prompts the user to select an object. The example continues to
    ' have the user select objects until the user selects in empty space.
    
    AppActivate ThisDrawing.Application.Caption

    ' Create a Ray object in model space
    Dim rayObj As AcadRay
    Dim basePoint(0 To 2) As Double
    Dim SecondPoint(0 To 2) As Double
    basePoint(0) = 3#: basePoint(1) = 3#: basePoint(2) = 0#
    SecondPoint(0) = 1#: SecondPoint(1) = 3#: SecondPoint(2) = 0#
    Set rayObj = ThisDrawing.ModelSpace.AddRay(basePoint, SecondPoint)
    
    ' Create a polyline object in model space
    Dim plineObj As AcadLWPolyline
    Dim points(0 To 5) As Double
    points(0) = 3: points(1) = 7
    points(2) = 9: points(3) = 2
    points(4) = 3: points(5) = 5
    Set plineObj = ThisDrawing.ModelSpace.AddLightWeightPolyline(points)
    plineObj.Closed = True

    ' Create a line object in model space
    Dim lineObj As AcadLine
    Dim startPoint(0 To 2) As Double
    Dim endPoint(0 To 2) As Double
    startPoint(0) = 0: startPoint(1) = 0: startPoint(2) = 0
    endPoint(0) = 2: endPoint(1) = 2: endPoint(2) = 0
    Set lineObj = ThisDrawing.ModelSpace.AddLine(startPoint, endPoint)
    
    ' Create a circle object in model space
    Dim circObj As AcadCircle
    Dim centerPt(0 To 2) As Double
    Dim radius As Double
    centerPt(0) = 20: centerPt(1) = 30: centerPt(2) = 0
    radius = 3
    Set circObj = ThisDrawing.ModelSpace.AddCircle(centerPt, radius)

    ' Create an ellipse object in model space
    Dim ellObj As AcadEllipse
    Dim majAxis(0 To 2) As Double
    Dim center(0 To 2) As Double
    Dim radRatio As Double
    center(0) = 5#: center(1) = 5#: center(2) = 0#
    majAxis(0) = 10: majAxis(1) = 20#: majAxis(2) = 0#
    radRatio = 0.3
    Set ellObj = ThisDrawing.ModelSpace.AddEllipse(center, majAxis, radRatio)

    ZoomAll
    
    ' Begin the selection
    Dim returnObj As AcadObject
    Dim basePnt As Variant
    
    On Error Resume Next
    
    ' The following example waits for a selection from the user
RETRY:
    ThisDrawing.Utility.GetEntity returnObj, basePnt, "Select an object"
    
    If Err <> 0 Then
        Err.Clear
        MsgBox "Program ended.", , "GetEntity Example"
        Exit Sub
    Else
        returnObj.Update
        MsgBox "The object type is: " & returnObj.EntityName, , "GetEntity Example"
        returnObj.Update
    End If
    
    GoTo RETRY
End Sub

Visual LISP:

(vl-load-com)
(defun c:Example_GetEntity()
    ;; This example creates several objects in model space. It then
    ;; prompts the user to select an object. The example continues to
    ;; have the user select objects until the user selects in empty space.
    (setq acadObj (vlax-get-acad-object))
    (setq doc (vla-get-ActiveDocument acadObj))
    (setq modelSpace (vla-get-ModelSpace doc))

    ;; Create a Ray object in model space
    (setq basePoint (vlax-3d-point 3 3 0)
          secondPoint (vlax-3d-point 1 3 0))
    (setq rayObj (vla-AddRay modelSpace basePoint SecondPoint))
    
    ;; Create a polyline object in model space
    (setq points (vlax-make-safearray vlax-vbDouble '(0 . 5)))
    (vlax-safearray-fill points '(3 7
                                  9 2
                                  3 5
                                 )
    )
    (setq plineObj (vla-AddLightWeightPolyline modelSpace points))
    (vla-put-Closed plineObj :vlax-true)

    ;; Create a line object in model space
    (setq startPoint (vlax-3d-point 0 0 0)
          endPoint (vlax-3d-point 2 2 0))
    (setq lineObj (vla-AddLine modelSpace startPoint endPoint))
    
    ;; Create a circle object in model space
    (setq centerPt (vlax-3d-point 20 30 0)
          radius 3)
    (setq circObj (vla-AddCircle modelSpace centerPt radius))

    ;; Create an ellipse object in model space
    (setq center (vlax-3d-point 5 5 0)
          majAxis (vlax-3d-point 10 20 0)
          radRatio 0.3)
    (setq ellObj (vla-AddEllipse modelSpace center majAxis radRatio))

    (vla-ZoomAll acadObj)
    
    ;; Begin the selection
    ;; The following example waits for a selection from the user
    (while (= (setq err (vl-catch-all-apply 'vla-GetEntity (list (vla-get-Utility doc) 'returnObj 'basePnt "Select an object"))) nil)
        (vla-Update returnObj)
	       (alert (strcat "The object type is: " (vla-get-ObjectName returnObj)))
        (vla-Update returnObj)
    )

    (alert "Program ended.")
)

路过

雷人

握手

鲜花

鸡蛋

最新评论

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

GMT+8, 2024-5-12 04:42

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

返回顶部