CAD开发者社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

AutoCAD 2024 开发者帮助

GetXData 方法 (ActiveX)

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

GetXData 方法 (ActiveX)

获取与对象关联的扩展数据 (XData)。

支持的平台:仅限 Windows

签名

VBA:

object.GetXData AppName, XDataType, XDataValue
对象

类型:所有图形对象AttributeReferenceBlockDictionaryDimensionDimStyleGroupLayerLayoutLinetypeMaterialMLeaderStylePlotConfigurationRegisteredApplicationTableStyleTextStyleUCSViewViewportXRecord

此方法应用到的对象。

应用程序名称

访问:仅输入

类型:字符串

字符串将返回附加到对象的所有数据,而不考虑创建它的应用程序。提供应用程序名称将仅返回由指定应用程序创建的数据。NULL

XData类型

访问:仅输出

类型:变体(短裤阵列)

短整数值的数组,表示扩展数据 (XData) 中每个值的 DXF 组代码值。

XDataValue

访问:仅输出

类型:变体(变体数组)

构成扩展数据 (XData) 的值数组。

返回值 (RetVal)

无返回值。

言论

扩展数据是由使用 ObjectARX 或 AutoLISP 编写的应用程序创建的特定于实例的数据的一个示例。此数据可以添加到任何对象中。此数据遵循对象的定义数据,并按照保存到文档中的顺序进行维护。(AutoCAD 会保留此信息,但不会使用它。

例子

VBA:

Sub Example_GetXData()
    ' This example creates a line and attaches extended data to that line.
    
    ' Create the line
    Dim lineObj As AcadLine
    Dim startPt(0 To 2) As Double, endPt(0 To 2) As Double
    startPt(0) = 1#: startPt(1) = 1#: startPt(2) = 0#
    endPt(0) = 5#: endPt(1) = 5#: endPt(2) = 0#
    Set lineObj = ThisDrawing.ModelSpace.AddLine(startPt, endPt)
    ZoomAll

    ' Initialize all the xdata values. Note that first data in the list should be
    ' application name and first datatype code should be 1001
    Dim DataType(0 To 9) As Integer
    Dim Data(0 To 9) As Variant
    Dim reals3(0 To 2) As Double
    Dim worldPos(0 To 2) As Double
    
    DataType(0) = 1001: Data(0) = "Test_Application"
    DataType(1) = 1000: Data(1) = "This is a test for xdata"

    DataType(2) = 1003: Data(2) = "0"                   ' layer
    DataType(3) = 1040: Data(3) = 1.23479137438413E+40  ' real
    DataType(4) = 1041: Data(4) = 1237324938            ' distance
    DataType(5) = 1070: Data(5) = 32767                 ' 16 bit Integer
    DataType(6) = 1071: Data(6) = 32767                 ' 32 bit Integer
    DataType(7) = 1042: Data(7) = 10                    ' scaleFactor

    reals3(0) = -2.95: reals3(1) = 100: reals3(2) = -20
    DataType(8) = 1010: Data(8) = reals3                ' real
    
    worldPos(0) = 4: worldPos(1) = 400.99999999: worldPos(2) = 2.798989
    DataType(9) = 1011: Data(9) = worldPos              ' world space position
    
    ' Attach the xdata to the line
    lineObj.SetXData DataType, Data
    
    ' Return the xdata for the line
    Dim xdataOut As Variant
    Dim xtypeOut As Variant
    lineObj.GetXData "", xtypeOut, xdataOut
    
End Sub

可视化 LISP:

(vl-load-com)
(defun c:Example_GetXData()
    ;; This example creates a line and attaches extended data to that line.
    (setq acadObj (vlax-get-acad-object))
    (setq doc (vla-get-ActiveDocument acadObj))
    
    ;; Create the line
    (setq startPt (vlax-3d-point 1 1 0)
          endPt (vlax-3d-point 5 5 0))
    (setq modelSpace (vla-get-ModelSpace doc))
    (setq lineObj (vla-AddLine modelSpace startPt endPt))
    (vla-ZoomAll acadObj)

    ;; Initialize all the xdata values. Note that first data in the list should be
    ;; application name and first datatype code should be 1001
    (setq DataType (vlax-make-safearray vlax-vbInteger '(0 . 9)))
    (setq Data (vlax-make-safearray vlax-vbVariant '(0 . 9)))

    (vlax-safearray-put-element DataType 0 1001)
    (vlax-safearray-put-element Data 0 "Test_Application")

    (vlax-safearray-put-element DataType 1 1000)
    (vlax-safearray-put-element Data 1 "This is a test for xdata")

    ;; layer
    (vlax-safearray-put-element DataType 2 1003)
    (vlax-safearray-put-element Data 2 "0")

    ;; real
    (vlax-safearray-put-element DataType 3 1040)
    (vlax-safearray-put-element Data 3 1.23479137438413E+40)

    ;; distance
    (vlax-safearray-put-element DataType 4 1041)
    (vlax-safearray-put-element Data 4 1237324938)
  
    ;; 16 bit Integer
    (vlax-safearray-put-element DataType 5 1070)
    (vlax-safearray-put-element Data 5 32767)

    ;; 32 bit Integer
    (vlax-safearray-put-element DataType 6 1071)
    (vlax-safearray-put-element Data 6 32767)

    ;; scaleFactor
    (vlax-safearray-put-element DataType 7 1042)
    (vlax-safearray-put-element Data 7 10)

    ;; 3D point
    (setq reals3 (vlax-3d-point -2.95 100 -20))
    (vlax-safearray-put-element DataType 8 1010)
    (vlax-safearray-put-element Data 8 reals3)
    
    ;; world space position
    (setq worldPos (vlax-3d-point 4 400.99999999 2.798989))
    (vlax-safearray-put-element DataType 9 1011)
    (vlax-safearray-put-element Data 9 worldPos)
    
    ;; Attach the xdata to the line
    (vla-SetXData lineObj DataType Data)
    
    ;; Return the xdata for the line
    (vla-GetXData lineObj "" 'xtypeOut 'xdataOut)
)

路过

雷人

握手

鲜花

鸡蛋

最新评论

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

GMT+8, 2025-3-5 15:38

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

返回顶部