明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1432|回复: 2

如何將一個變量放入autocad中,關閉autocad後,下次打開時這個變量還存在

[复制链接]
发表于 2006-8-19 13:34:00 | 显示全部楼层 |阅读模式

如何将一个变量放入AutoCAD中,关闭autocad后,下次打开时这个变量还存在cad中,这好象要用在词典,请问一下是不是先增加一个词典,然后再用setxdata,再用getxdata,有没有哪位在师可以贴个类子上来

发表于 2006-8-19 13:43:00 | 显示全部楼层
字典和Xdata是两回事,下面的函数是向字典读写的
  1. Public Function SetXRecord(ByVal DictName As String, ByVal Keyword As String, ByVal XRecordData)
  2.     Dim pDict As AcadDictionary
  3.     Dim pXRecord As AcadXRecord
  4.     Dim XRecordType() As Integer
  5.     Dim pLen As Integer
  6.    
  7.     Set pDict = ThisDrawing.Dictionaries.Add(DictName)
  8.     Set pXRecord = pDict.AddXRecord(Keyword)
  9.    
  10.     pLen = UBound(XRecordData)
  11.     ReDim XRecordType(pLen) As Integer
  12.     For i = 0 To pLen
  13.         Select Case VarType(XRecordData(i))
  14.             Case vbInteger, vbLong
  15.                 XRecordType(i) = 70
  16.             Case vbSingle, vbDouble
  17.                 XRecordType(i) = 40
  18.             Case vbString
  19.                 XRecordType(i) = 1
  20.         End Select
  21.     Next i
  22.    
  23.     pXRecord.SetXRecordData XRecordType, XRecordData
  24. End Function
  25. Public Function GetXRecord(ByVal DictName As String, ByVal Keyword As String)
  26. On Error GoTo ErrHandle
  27.     Dim pDict As AcadDictionary
  28.     Dim pXRecord As AcadXRecord
  29.     Dim xt
  30.     Set pDict = ThisDrawing.Dictionaries(DictName)
  31.     Set pXRecord = pDict.GetObject(Keyword)
  32.     pXRecord.GetXRecordData xt, GetXRecord
  33.     Exit Function
  34. ErrHandle:
  35.     GetXRecord = Null
  36. End Function
  37. Public Function CreateArray(ByVal TypeName As VbVarType, ParamArray ValArray())
  38.     Dim nCount As Integer
  39.     Dim i
  40.     Dim mArray
  41.    
  42.     nCount = UBound(ValArray)
  43.    
  44.     Select Case TypeName
  45.     Case vbDouble
  46.         Dim dArray() As Double
  47.         ReDim dArray(nCount)
  48.         For i = 0 To nCount
  49.             dArray(i) = ValArray(i)
  50.         Next i
  51.         CreateArray = dArray
  52.     Case vbInteger
  53.         Dim nArray() As Integer
  54.         ReDim nArray(nCount)
  55.         For i = 0 To nCount
  56.             nArray(i) = ValArray(i)
  57.         Next i
  58.         CreateArray = nArray
  59.     Case vbString
  60.         Dim sArray() As String
  61.         ReDim sArray(nCount)
  62.         For i = 0 To nCount
  63.             sArray(i) = ValArray(i)
  64.         Next i
  65.         CreateArray = sArray
  66.     Case vbVariant
  67.         Dim vArray()
  68.         ReDim vArray(nCount)
  69.         For i = 0 To nCount
  70.             vArray(i) = ValArray(i)
  71.         Next i
  72.         CreateArray = vArray
  73.     Case vbObject
  74.         Dim oArray() As Object
  75.         ReDim oArray(nCount)
  76.         For i = 0 To nCount
  77.             Set oArray(i) = ValArray(i)
  78.         Next i
  79.         CreateArray = oArray
  80.     End Select
  81. End Function
例子
  1. Sub tt()
  2. Dim arr1(2) As Variant
  3. SetXRecord "tlscad", "A", Array(1, 2, "A")
  4. SetXRecord "tlscad", "B", Array(3, 4, "B")
  5. a = GetXRecord("tlscad", "A")
  6. If Not IsNull(a) Then MsgBox a(2)
  7. End Sub
 楼主| 发表于 2006-8-21 12:07:00 | 显示全部楼层
先謝版主了
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-11-27 00:35 , Processed in 0.156285 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表