yuangw1234 发表于 2006-6-4 21:23:00

不能用getxdata

<P>本人选择一个物体,并对其set xdata,其中data为“螺丝”,现在想用get xdata方法得到</P>
<P>“螺丝”,但msgbox 后是空的 ,请问为什么,程序如下,多谢各位<BR>Public Sub xd()<BR>Dim i As Integer, ssetobj As AcadSelectionSet, selobj As AcadEntity<BR>Dim i1 As Integer, datatype(0) As Integer, data(0) As Variant, getobj As Variant, dattype As Variant, dat As Variant<BR>i = ThisDrawing.SelectionSets.Count<BR>While (i &gt; 0)<BR>If ThisDrawing.SelectionSets.Item(i - 1).Name = "xd" Then<BR>ThisDrawing.SelectionSets.Item(i - 1).Delete<BR>End If<BR>i = i - 1<BR>Wend<BR>Set ssetobj = ThisDrawing.SelectionSets.Add("xd")<BR>datatype(0) = 1001: data(0) = "螺丝"<BR>For i1 = 0 To ssetobj.Count - 1<BR>&nbsp;&nbsp;&nbsp; Set selobj = ssetobj.Item(i1)<BR>&nbsp;&nbsp;&nbsp; selobj.SetXData datatype, data<BR>&nbsp;&nbsp;&nbsp; getobj = selobj.GetXData("", dattype, dat)<BR>Next<BR>&nbsp;&nbsp;&nbsp; MsgBox getobj<BR>End Sub</P>

雪山飞狐_lzh 发表于 2006-6-5 13:21:00

<P>setXData中datatype, data的元素个数都要大于1,否则将把符合1001码的XData删除</P>
<P>1001码是程序名,不要带参数</P>
<P>后面可以跟一个1000码附上文本信息</P>
<P>&nbsp;</P>
<P>&nbsp;</P>

yuangw1234 发表于 2006-6-5 13:31:00

<P>斑竹,去改了一下,好象还是不行,斑竹能不能帮我修一下,只在执行时msgbox可以显示"螺丝"这两个字就行,在此先谢谢斑竹!!</P>

雪山飞狐_lzh 发表于 2006-6-5 13:41:00

<P>Public Sub xd()<BR>On Error Resume Next<BR>Dim ssetobj As AcadSelectionSet<BR>Dim selobj As AcadEntity<BR>Dim xt, xd<BR>Dim datatype(1) As Integer, data(1)<BR>ThisDrawing.SelectionSets("xd").Delete<BR>Set ssetobj = ThisDrawing.SelectionSets.Add("xd")<BR>ssetobj.SelectOnScreen<BR>datatype(0) = 1001: data(0) = "myapp"<BR>datatype(1) = 1000: data(1) = "螺丝"</P>
<P>For i = 0 To ssetobj.Count - 1<BR>&nbsp;&nbsp;&nbsp; Set selobj = ssetobj.Item(i)<BR>&nbsp;&nbsp;&nbsp; selobj.SetXData datatype, data<BR>&nbsp;&nbsp;&nbsp; selobj.GetXData "myapp", xt, xd<BR>&nbsp;&nbsp;&nbsp;&nbsp; MsgBox xd(1)<BR>&nbsp;&nbsp; <BR>Next<BR>End Sub<BR></P>

xinghesnak 发表于 2006-6-5 14:00:00

<P>顶顶!</P>

yuangw1234 发表于 2006-6-5 16:55:00

<P>多谢版主这样好心的人</P>
页: [1]
查看完整版本: 不能用getxdata