CAD开发者社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

AutoCAD 2024 开发者帮助

GetXRecordData 方法 (ActiveX)

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

GetXRecordData 方法 (ActiveX)

获取与字典关联的扩展记录数据 (XRecordData)。

支持的平台:仅限 Windows

签名

VBA:

object.GetXRecordData XRecordDataType, XRecordDataValue
对象

类型: XRecord

此方法应用到的对象。

XRecordDataType

访问:仅输出

类型:变体(短裤阵列)

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

XRecordDataValue

访问:仅输出

类型:变体(变体数组)

构成扩展记录 (XRecord) 数据的值数组。

返回值 (RetVal)

无返回值。

言论

XRecord对象用于存储和管理任意数据。此对象在概念上类似于 XData,但不受大小或顺序的限制。

与XData不同,使用值均低于1000的标准AutoCAD组代码。支持所有标准 AutoCAD 组代码。这意味着,除了所有常用的数据类型之外,an 还能够存储对象 ID,从而允许拥有其他对象,包括其他 .XRecordsXRecordXRecordsXRecords

以下组代码是所有对象通用的:XRecord

组代码 描述
100 子类标记 (AcDbXrecord)
1-369(5 和 105 除外) 应用程序可以以任何方式使用这些值。

例子

VBA:

Sub Example_SetXRecordData()
    ' This example creates a new XRecord if one doesn't exist,
    ' appends data to the XRecord, and reads it back.  To see data being added,
    ' run the example more than once.
    
    Dim TrackingDictionary As AcadDictionary, TrackingXRecord As AcadXRecord
    Dim XRecordDataType As Variant, XRecordData As Variant
    Dim ArraySize As Long, iCount As Long
    Dim DataType As Integer, Data As String, msg As String
    
    ' Unique identifiers to distinguish our XRecordData from other XRecordData
    Const TYPE_STRING = 1
    Const TAG_DICTIONARY_NAME = "ObjectTrackerDictionary"
    Const TAG_XRECORD_NAME = "ObjectTrackerXRecord"

    ' Connect to the dictionary in which the XRecord is stored
    On Error GoTo CREATE
    Set TrackingDictionary = ThisDrawing.Dictionaries(TAG_DICTIONARY_NAME)
    Set TrackingXRecord = TrackingDictionary.GetObject(TAG_XRECORD_NAME)
    On Error GoTo 0
    
    ' Get current XRecordData
    TrackingXRecord.GetXRecordData XRecordDataType, XRecordData
    
    ' If there is no array already, create one
    If VarType(XRecordDataType) And vbArray = vbArray Then
        ArraySize = UBound(XRecordDataType) + 1       ' Get the size of the data elements returned
        ArraySize = ArraySize + 1                        ' Increase to hold new data
    
        ReDim Preserve XRecordDataType(0 To ArraySize)
        ReDim Preserve XRecordData(0 To ArraySize)
    Else
        ArraySize = 0
        ReDim XRecordDataType(0 To ArraySize) As Integer
        ReDim XRecordData(0 To ArraySize) As Variant
    End If
    
    ' Append new XRecord Data
    '
    ' For this sample, we only append the current time to the XRecord
    XRecordDataType(ArraySize) = TYPE_STRING: XRecordData(ArraySize) = CStr(Now)
    TrackingXRecord.SetXRecordData XRecordDataType, XRecordData
    
    ' Read back all XRecordData entries
    TrackingXRecord.GetXRecordData XRecordDataType, XRecordData
    ArraySize = UBound(XRecordDataType)
    
    ' Retrieve and display stored XRecordData
    For iCount = 0 To ArraySize
        ' Get information for this element
        DataType = XRecordDataType(iCount)
        Data = XRecordData(iCount)
        
        If DataType = TYPE_STRING Then
            msg = msg & Data & vbCrLf
        End If
    Next
    
    MsgBox "The data in the XRecord is: " & vbCrLf & vbCrLf & msg, vbInformation
    
    Exit Sub

CREATE:
    ' Create the objects that hold the XRecordData
    If TrackingDictionary Is Nothing Then  ' Make sure the tracking object is there
        Set TrackingDictionary = ThisDrawing.Dictionaries.Add(TAG_DICTIONARY_NAME)
        Set TrackingXRecord = TrackingDictionary.AddXRecord(TAG_XRECORD_NAME)
    End If
    
    Resume
End Sub

可视化 LISP:

(vl-load-com)
(defun c:Example_SetXRecordData()
    ;; This example creates a new XRecord if one doesn't exist,
    ;; appends data to the XRecord, and then reads it back.  To see data being added,
    ;; run the example more than once.
    (setq acadObj (vlax-get-acad-object))
    (setq doc (vla-get-ActiveDocument acadObj))
    
    ;; Unique identifiers to distinguish this XRecordData from other XRecordData
    (setq TYPE_STRING 1
          TAG_DICTIONARY_NAME "ObjectTrackerDictionary"
          TAG_XRECORD_NAME "ObjectTrackerXRecord")

    ;; Connect to the dictionary in which to store the XRecord
    (setq dictionaries (vla-get-Dictionaries doc))
    (setq TrackingDictionary (vl-catch-all-apply 'vla-Item (list dictionaries TAG_DICTIONARY_NAME)))

    (if (= (type TrackingDictionary) 'VLA-OBJECT)
        (setq TrackingXRecord (vl-catch-all-apply 'vla-GetObject (list TrackingDictionary TAG_XRECORD_NAME)))
        (progn
            ;; Create the objects that hold this XRecordData
            (setq TrackingDictionary (vla-Add dictionaries TAG_DICTIONARY_NAME))

            ;; Add a new XRecord, but only if using AutoCAD
            (if (/= (strcase (getvar "PROGRAM") T) "acadlt")
                (setq TrackingXRecord (vla-AddXRecord TrackingDictionary TAG_XRECORD_NAME))
            )
        )
    )

    ;; Get current XRecordData
    (if (= (type TrackingXRecord) 'VLA-OBJECT)
        (progn
            (vla-GetXRecordData TrackingXRecord 'temp-XRecordDataType 'temp-XRecordData)
    
            ;; If there is no array yet then create one
            (setq ArraySize 0)
            (if (/= temp-XRecordDataType nil)
                (progn
                    (setq ArraySize (vlax-safearray-get-u-bound temp-XRecordDataType 1))
                    (setq XRecordDataType (vlax-make-safearray vlax-vbInteger (cons 0 (1+ ArraySize))))
                    (setq XRecordData (vlax-make-safearray vlax-vbVariant (cons 0 (1+ ArraySize))))

                    (setq iCount 0)
                    (while (>= ArraySize iCount)
                        ;; Get information for this element
                        (setq DataType (vlax-safearray-get-element temp-XRecordDataType iCount))
                        (setq Data (vlax-variant-value (vlax-safearray-get-element temp-XRecordData iCount)))

                        (vlax-safearray-put-element XRecordDataType iCount DataType)
                        (vlax-safearray-put-element XRecordData iCount Data)
	      
                        (setq iCount (1+ iCount))
                    )
                )
                (progn
                    (setq XRecordDataType (vlax-make-safearray vlax-vbInteger '(0 . 0)))
                    (setq XRecordData (vlax-make-safearray vlax-vbVariant '(0 . 0)))
                )
            )

            ;; Append new XRecord Data, but only if using AutoCAD
            (if (/= (strcase (getvar "PROGRAM") T) "acadlt")
                (progn
                    ;; For this sample we only append the current time to the XRecord
                    (vlax-safearray-put-element XRecordDataType ArraySize TYPE_STRING)
                    (setq cdate (rtos (vlax-variant-value (vla-GetVariable doc "CDATE")) 2 6))
                    (vlax-safearray-put-element XRecordData ArraySize (strcat (substr cdate 5 2) "/"
                                                                              (substr cdate 7 2) "/"
                                                                              (substr cdate 1 4) "-"
                                                                              (substr cdate 10 2) ":"
                                                                              (substr cdate 12 2) ":"
                                                                              (substr cdate 14)))
                    (vla-SetXRecordData TrackingXRecord XRecordDataType XRecordData)
    
                    ;; Read back all XRecordData entries
                    (vla-GetXRecordData TrackingXRecord 'XRecordDataType 'XRecordData)
                    (setq ArraySize (vlax-safearray-get-u-bound XRecordDataType 1))
                )
            )

            ;; Display the stored XRecord Data
            (setq iCount 0
                  msg "")
            (while (>= ArraySize iCount)
                ;; Get information for this element
                (setq DataType (vlax-safearray-get-element XRecordDataType iCount))
                (setq Data (vlax-variant-value (vlax-safearray-get-element XRecordData iCount)))

                (if (= DataType TYPE_STRING)
                    (setq msg (strcat msg Data "\n"))
                )
      
                (setq iCount (1+ iCount))
            )
    
            (alert (strcat "The data in the XRecord is: \n\n" msg))
        )
        (alert "XRecord was not added or found.\nXRecords can only be added using the API with AutoCAD.")
    )
)

路过

雷人

握手

鲜花

鸡蛋

最新评论

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

GMT+8, 2024-6-27 15:57

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

返回顶部