扩展字典问题
<p>Sub mysel()<br/>Dim sset As AcadSelectionSet '定义选择集对象<br/>Dim element As AcadEntity '定义选择集中的元素对象<br/>Dim objdic As AcadDictionary<br/>Dim objrec As AcadXRecord<br/>Dim jim As String<br/>Dim xdtype(10) As Variant<br/>Dim xdt(10) As Variant<br/>Set sset = ThisDrawing.SelectionSets.Add("ca0s") '新建一个选择集<br/>sset.SelectOnScreen '提示用户选择<br/>Set element = sset.Item(0) <br/>UserForm1.Show<br/>Dim i As Integer<br/>For i = 0 To 5<br/>xdtype(i) = i + 10<br/>xdt(i) = UserForm1.Controls("TextBox" & (i + 1)).Value<br/>Next<br/>Set objdic = element.GetExtensionDictionary()<br/>Set objrec = objdic.AddXRecord(jim)<br/><font color="#ee1111">objrec.SetXRecordData xdtype, xdt</font><br/>End Sub<br/></p><p>运行到<font color="#ee1111">objrec.SetXRecordData xdtype, xdt</font><font color="#000000">这句时就出错, [调用方法setobjectid(接口iacadbaseobject)失败],我想是不是xdatatype有类型的要求,但是我看网上别的例子都可以用的啊,书上也说只要1000以下都可以的.哪位大侠帮忙看一下,谢谢</font></p> <p>参考如下代码:</p><p>'——————————————————————————————————————————————————<br/>'名称:XRecord_ForJIM<br/>'作者:罗简单<br/>'日期:2008-11-5<br/>'功能:为选择的实体添加扩展字典,并且添加完成后,读出<br/>'扩展字典内的值(为明经通道中jimzhoujim书写的代码)<br/>'——————————————————————————————————————————————————<br/>Sub XRecord_ForJIM()<br/> Dim pEnt As AcadEntity '定义实体<br/> Dim pBasePt As Variant '定义获取实体的点<br/> <br/> ThisDrawing.Utility.GetEntity pEnt, pBasePt, vbNewLine & "请需要添加扩展字典的选择实体:"<br/> <br/> Dim pDictionary As AcadDictionary<br/> Dim pXRecord As AcadXRecord<br/> <br/> Dim pType(2) As Integer<br/> Dim pData(2) As Variant<br/> <br/> '设置自定义值<br/> pType(0) = 1: pData(0) = "jimzhoujim" '作者<br/> pType(1) = 2: pData(1) = Now '日期<br/> pType(2) = 2: pData(2) = "XRecord_Test" '名称<br/> <br/> Dim pKeyWord As String<br/> pKeyWord = "jim"<br/> <br/> '******************************************************<br/> '获取刚才选择的实体pEnt的扩展字典(Extension Dictionary)<br/> <br/> 'If an object does not have an extension dictionary,<br/> 'this method will create a new extension dictionary<br/> 'for that object and return it in the return value.</p><p> 'You can query an object to see if it has an extension<br/> 'dictionary by using the HasExtensionDictionary property.<br/> Set pDictionary = pEnt.GetExtensionDictionary<br/> Set pXRecord = pDictionary.AddXRecord(pKeyWord)<br/> '******************************************************</p><p> '添加扩展字典<br/> pXRecord.SetXRecordData pType, pData<br/> <br/> <br/> '获取刚才添加的扩展字典<br/> pXRecord.GetXRecordData pType, pData<br/> <br/> Dim i As Integer '循环参数<br/> Dim strMessage As String<br/> For i = 0 To UBound(pType)<br/> strMessage = strMessage & vbCrLf & pType(i) & ":" & pData(i)<br/> Next i<br/> <br/> '以消息框的形式呈现给JIM<br/> MsgBox strMessage</p><p>End Sub<br/></p> 本帖最后由 作者 于 2008-11-6 16:36:05 编辑 <br /><br /> <p>你的代码经过如下修改可用</p><p>Sub mysel()<br/>Dim sset As AcadSelectionSet '定义选择集对象<br/>Dim element As AcadEntity '定义选择集中的元素对象<br/>Dim objdic As AcadDictionary<br/>Dim objrec As AcadXRecord<br/>Dim jim As String</p><p>Dim xdtype(10) As Integer <font color="#ff0000"> '这里修改为Integer<br/></font>Dim xdt(10) As Variant<br/>Set sset = ThisDrawing.SelectionSets.Add("ca1110s") '新建一个选择集<br/>sset.SelectOnScreen '提示用户选择<br/>Set element = sset.Item(0)<br/>Dim i As Integer<br/>For i = 0 To 5 <font color="#ff0000">'好像这里不能大于10,这个得再研究研究,如果你研究出来了请与我分享一下(QQ:45096732)<br/></font>xdtype(i) = i<br/>xdt(i) = Str(i)<br/>Next<br/>Set objdic = element.GetExtensionDictionary()<br/>jim = "jim" <font color="#ff0000"> '这里需要先初始化</font><br/>Set objrec = objdic.AddXRecord(jim)<br/>objrec.SetXRecordData xdtype, xdt</p><p>objrec.GetXRecordData xdtype, xdt<br/><font color="#f73809">'因为在上面数组的上限设的是10,所以<br/>'后面的4个值是NULL</font><br/>For i = 0 To UBound(xdtype)<br/> MsgBox xdt(i)<br/>Next i<br/>End Sub</p><p></p><p class="body"><font color="#ff0000">XRecord 对象用来存储和管理任意数据。该对象概念上与 XData 相似但不限制长度和顺序。 </font></p><p class="body"><font color="#ff0000">与 XData 不同的是,XRecords 的值使用所有低于 1000 的标准 AutoCAD 组码。它支持所有标准的 AutoCAD 组码。也就是说,除了所有正常使用的数据类型,XRecord 还能够存储对象 ID,这使 XRecords 可以拥有其它对象包括其它的 XRecords。 </font></p><p class="body"><font color="#ff0000">以下组码对所有 XRecord 对象通用: </font><table cellspacing="1" cellpadding="4" border="0"><tbody><tr valign="top"><th align="left"><p class="-emphasis"><font color="#ff0000">组码</font></p></th><th align="left"><p class="-emphasis"><font color="#ff0000">描述</font></p></th></tr><tr valign="top"><td class="body"><font color="#ff0000">100 </font></td><td class="body"><font color="#ff0000"> 子类标记 (AcDbXrecord) </font></td></tr><tr valign="top"><td class="body"><font color="#ff0000">1-369 (除了 5 和 105) </font></td><td class="body"><p><font color="#ff0000">这些值可以由程序以任何方式使用。</font></p></td></tr></tbody></table></p>
页:
[1]