不能用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 > 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> Set selobj = ssetobj.Item(i1)<BR> selobj.SetXData datatype, data<BR> getobj = selobj.GetXData("", dattype, dat)<BR>Next<BR> MsgBox getobj<BR>End Sub</P> <P>setXData中datatype, data的元素个数都要大于1,否则将把符合1001码的XData删除</P>
<P>1001码是程序名,不要带参数</P>
<P>后面可以跟一个1000码附上文本信息</P>
<P> </P>
<P> </P> <P>斑竹,去改了一下,好象还是不行,斑竹能不能帮我修一下,只在执行时msgbox可以显示"螺丝"这两个字就行,在此先谢谢斑竹!!</P> <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> Set selobj = ssetobj.Item(i)<BR> selobj.SetXData datatype, data<BR> selobj.GetXData "myapp", xt, xd<BR> MsgBox xd(1)<BR> <BR>Next<BR>End Sub<BR></P> <P>顶顶!</P> <P>多谢版主这样好心的人</P>
页:
[1]