乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 82|回复: 4

一点字典帮助 - 请

[复制链接]

55

主题

197

帖子

8

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
416
发表于 2006-7-12 17:45:28 | 显示全部楼层 |阅读模式
在VBA,我真的很努力地去理解这本字典,但是我仍然有困难。我用下面的LISP在namedobjdict中创建了一个xrecord:

  1. (defun jb:SaveKeynoteFilename  (file / datalist xname newdict)
  2.   (setq        dataList (append (list '(0 . "XRECORD") '(100 . "AcDbXrecord") (cons 300 file)))
  3.         xname         (entmakex dataList))
  4.   (dictremove (namedobjdict) "JB_KEYNOTE_FILE")
  5.   (setq        newdict
  6.          (dictadd (namedobjdict) "JB_KEYNOTE_FILE" xname)
  7.         xname nil)
  8.   newdict)

有人能告诉我如何通过VBA检索这些数据吗?非常感谢!
jb

本帖以下内容被隐藏保护;需要你回复后,才能看到!

游客,如果您要查看本帖隐藏内容请回复
回复

使用道具 举报

170

主题

1424

帖子

8

银币

顶梁支柱

Rank: 50Rank: 50

铜币
2119
发表于 2006-7-12 18:03:39 | 显示全部楼层
今天真的很忙,所以我需要停止在这里查看,但是哦,好吧。我没有时间给你一个好答案,所以我给你两个坏答案
从帮助
  1. Sub Example_GetXData()
  2.     ' This example creates a line and attaches extended data to that line.
  3.    
  4.     ' Create the line
  5.     Dim lineObj As AcadLine
  6.     Dim startPt(0 To 2) As Double, endPt(0 To 2) As Double
  7.     startPt(0) = 1#: startPt(1) = 1#: startPt(2) = 0#
  8.     endPt(0) = 5#: endPt(1) = 5#: endPt(2) = 0#
  9.     Set lineObj = ThisDrawing.ModelSpace.AddLine(startPt, endPt)
  10.     ZoomAll
  11.     ' Initialize all the xdata values. Note that first data in the list should be
  12.     ' application name and first datatype code should be 1001
  13.     Dim DataType(0 To 9) As Integer
  14.     Dim Data(0 To 9) As Variant
  15.     Dim reals3(0 To 2) As Double
  16.     Dim worldPos(0 To 2) As Double
  17.    
  18.     DataType(0) = 1001: Data(0) = "Test_Application"
  19.     DataType(1) = 1000: Data(1) = "This is a test for xdata"
  20.     DataType(2) = 1003: Data(2) = "0"                   ' layer
  21.     DataType(3) = 1040: Data(3) = 1.23479137438413E+40  ' real
  22.     DataType(4) = 1041: Data(4) = 1237324938            ' distance
  23.     DataType(5) = 1070: Data(5) = 32767                 ' 16 bit Integer
  24.     DataType(6) = 1071: Data(6) = 32767                 ' 32 bit Integer
  25.     DataType(7) = 1042: Data(7) = 10                    ' scaleFactor
  26.     reals3(0) = -2.95: reals3(1) = 100: reals3(2) = -20
  27.     DataType(8) = 1010: Data(8) = reals3                ' real
  28.    
  29.     worldPos(0) = 4: worldPos(1) = 400.99999999: worldPos(2) = 2.798989
  30.     DataType(9) = 1011: Data(9) = worldPos              ' world space position
  31.    
  32.     ' Attach the xdata to the line
  33.     lineObj.SetXData DataType, Data
  34.    
  35.     ' Return the xdata for the line
  36.     Dim xdataOut As Variant
  37.     Dim xtypeOut As Variant
  38.     lineObj.GetXData "", xtypeOut, xdataOut
  39.    
  40. End Sub

您也可以这样做。以下内容几乎没有经过深思熟虑,完全没有经过测试,几乎可以保证不起作用,但应该会让您走上正确的道路。
  1. Sub test()
  2. Dim objDic As AcadDictionary
  3. Dim objDix As AcadDictionaries
  4. Dim varXDO As Variant
  5. Dim varXTO As Variant
  6. Set objDix = ThisDrawing.Dictionaries
  7. For Each objDic In objDix
  8.   If objDic.Name = "JB_KEYNOTE_FILE" Then
  9.     objDic.GetXData "", varXDO, varXTO
  10.     Exit For
  11.   End If
  12. Next objDic
  13. End Sub

回复

使用道具 举报

55

主题

197

帖子

8

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
416
发表于 2006-7-13 01:01:33 | 显示全部楼层
jb:我发布这个,因为它似乎有点像你需要的
我发现的一个想法是,如果将xrecord视为字典,则它将出错,因此注意vardic是一个对象
我想我是在搞乱这个子,想弄清楚如何从vba中获得一些lisp。分担痛苦。
  1. Sub Dimstuff()
  2.     '(dictremove (namedobjdict) "AcadDim")
  3.       '(setq cur (append '((0 . "XRECORD") (100 . "AcDbXrecord") (90 . 990106)) cur))
  4.       '(dictadd (namedobjdict) "AcadDim" (entmakex cur))
  5.       '(acet-ql-get)
  6.     Dim varDic As AcadObject
  7.     Dim oDic As AcadDictionary
  8.     Dim oDics As AcadDictionaries
  9.     Dim x As AcadXRecord
  10.     Dim i As Integer
  11.     Dim XRecordDataType As Variant, XRecordData As Variant
  12.     Dim ArraySize As Long, iCount As Long
  13.     Dim DataType As Integer, Data As String, msg As String
  14.     Dim isThere As Boolean
  15.     Set oDics = ThisDrawing.Dictionaries
  16.     For Each varDic In oDics
  17.         If TypeOf varDic Is AcadXRecord Then
  18.         Debug.Print "XRecord=" & varDic.Name
  19.             If varDic.Name = "AcadDim" Then
  20.                 Set x = varDic
  21.                 isThere = True
  22.                 Exit For
  23.             End If
  24.         End If
  25.         If TypeOf varDic Is AcadDictionary Then
  26.         Debug.Print "Dictionary=" & varDic.Name
  27.             If varDic.Name = "AcadDim" Then
  28.                 Set oDic = varDic
  29.                 For Each x In oDic
  30.                 Debug.Print x.Name
  31.                 Next
  32.                 'Set X = oDic.GetObject("AcadDim")
  33.                 'IsThere = True
  34.                 Exit For
  35.             End If
  36.         End If
  37.     Next
  38.    
  39.     If Not isThere Then
  40.     Debug.Print isThere
  41.         Dim xType(16) As Integer, XData(16)
  42.         xType(0) = 90: XData(0) = 990106
  43.         xType(1) = 3: XData(1) = ""
  44.         xType(2) = 40: XData(2) = 0
  45.         xType(3) = 60: XData(3) = 0
  46.         xType(4) = 61: XData(4) = 0
  47.         xType(5) = 62: XData(5) = 2
  48.         xType(6) = 63: XData(6) = 2
  49.         xType(7) = 64: XData(7) = 0
  50.         xType(8) = 65: XData(8) = 0
  51.         xType(9) = 66: XData(9) = 0
  52.         xType(10) = 67: XData(10) = 3
  53.         xType(11) = 68: XData(11) = 0
  54.         xType(12) = 69: XData(12) = 0
  55.         xType(13) = 70: XData(13) = 0
  56.         xType(14) = 71: XData(14) = 1
  57.         xType(15) = 72: XData(15) = 0
  58.         xType(16) = 170: XData(16) = 0
  59.    
  60.    
  61.         Set oDic = oDics.Add("AcadDim")
  62.         Set x = oDic.AddXRecord("AcadDim")
  63.         x.SetXRecordData xType, XData
  64.     End If
  65.    
  66.     For Each varDic In oDics
  67.         'Debug.Print varDic.ObjectName
  68.         If TypeOf varDic Is AcadDictionary Then
  69.             Debug.Print varDic.Name
  70.         End If
  71.         If TypeOf varDic Is AcadXRecord Then
  72.             Debug.Print "XRecord=" & varDic.Name
  73.         End If
  74.     Next
  75.    
  76.     On Error Resume Next
  77.     x.GetXRecordData XRecordDataType, XRecordData
  78.    
  79.     For i = 0 To UBound(XRecordDataType)
  80.         ' Get information for this element
  81.         
  82.         DataType = XRecordDataType(i)
  83.         Data = XRecordData(i)
  84.         Debug.Print i, DataType, Data
  85.     Next
  86. End Sub

回复

使用道具 举报

55

主题

197

帖子

8

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
416
发表于 2006-7-13 16:08:59 | 显示全部楼层
谢谢你们的帮助
以下是我的结论:
  1. Public Sub jbKeyNotesFormRefresh()
  2. Dim KeynoteDict As AcadDictionary, KeynoteXRecord As AcadXRecord
  3.     Dim XRecordDataType As Variant, XRecordData As Variant
  4.     Dim ArraySize As Long, iCount As Long
  5.     Dim DataType As Integer, Data As String, msg As String
  6.     Dim file As String, str As String
  7.     ' Unique identifiers to distinguish this XRecordData from other XRecordData
  8.     Const TYPE_STRING = 300
  9.     Const TAG_DICTIONARY_NAME = "JB_KEYNOTE"
  10.     Const TAG_XRECORD_NAME = "JB_KEYNOTE_FILE"
  11.    
  12.     ' Connect to the dictionary in which to store the XRecord
  13.     On Error GoTo ERR
  14.     Set KeynoteDict = ThisDrawing.Dictionaries(TAG_DICTIONARY_NAME)
  15.     Set KeynoteXRecord = KeynoteDict.GetObject(TAG_XRECORD_NAME)
  16.     On Error GoTo 0
  17.    
  18.     ' Get current XRecordData
  19.     KeynoteXRecord.GetXRecordData XRecordDataType, XRecordData
  20.    
  21.     ' If there is no array yet then create one
  22.     If VarType(XRecordDataType) And vbArray = vbArray Then
  23.         ArraySize = UBound(XRecordDataType) + 1       ' Get the size of the data elements returned
  24.         ArraySize = ArraySize + 1                        ' Increase to hold new data
  25.    
  26.         ReDim Preserve XRecordDataType(0 To ArraySize)
  27.         ReDim Preserve XRecordData(0 To ArraySize)
  28.     Else
  29.         ArraySize = 0
  30.         ReDim XRecordDataType(0 To ArraySize) As Integer
  31.         ReDim XRecordData(0 To ArraySize) As Variant
  32.     End If
  33.    
  34.     ' Read back all XRecordData entries
  35.     KeynoteXRecord.GetXRecordData XRecordDataType, XRecordData
  36.     ArraySize = UBound(XRecordDataType)
  37.    
  38.     ' Retrieve and display stored XRecordData
  39.     For iCount = 0 To ArraySize
  40.         ' Get information for this element
  41.         DataType = XRecordDataType(iCount)
  42.         Data = XRecordData(iCount)
  43.         
  44.         If DataType = TYPE_STRING Then
  45.             file = Data
  46.         End If
  47.     Next
  48.    
  49.    
  50.     KeyNotes.ListBox2.Clear
  51. On Error GoTo ErrMessage
  52. If Not file = "" Then
  53. Open file For Input As #1
  54. Do While Not EOF(1)
  55.     Input #1, str
  56.     KeyNotes.ListBox2.AddItem (str)
  57. Loop
  58. Close #1
  59.     End If
  60. ErrMessage:
  61.     Close #1
  62.     Exit Sub
  63.    
  64.     Exit Sub
  65. ERR:
  66.     KeyNotes.ListBox2.Clear
  67. End Sub

我在表单刷新代码中包含了字典内容,因为我不知道如何在函数之间传递变量
jb
回复

使用道具 举报

55

主题

197

帖子

8

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
416
发表于 2006-7-13 16:25:26 | 显示全部楼层
这里有一件非常简单的事情,希望能把它弄清楚
  1. public sub test()
  2. Dim strOne as String
  3. dim StrTwo as string
  4. dim intOne as integer
  5. dim intTwo as integer
  6. strone = "This"
  7. strtwo = "a (hopefully simple to"
  8. intone = 3
  9. inttwo = 1
  10. msgbox stringmaker(strone,strtwo,intone,inttwo)
  11. end sub
  12. Public Function StringMaker(strA as string, strB as string, intA as integer, intB as integer) as string
  13. stringmaker = strA & " is " & strB & " understand) demonstration on passing data to and from a function as easy as " & intb & ", 2, " & inta
  14. end function
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-7-5 23:09 , Processed in 0.962770 second(s), 62 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表