maobamboo 发表于 2009-10-17 09:34:00

[求助]集合类是否可以设置扩展数据

<p>对象都都可以设置扩展数据和获取其扩展数据</p><p>看见ACAD的帮助文档 集合类也可以设置扩展数据和获取扩展数据</p><p>代码如下:</p><p>Sub Example_GetXData()<br/>&nbsp;&nbsp;&nbsp; ' This example creates a line and attaches extended data to that line.<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; ' Create the line<br/>&nbsp;&nbsp;&nbsp; Dim lineObj As AcadLine<br/>&nbsp;&nbsp;&nbsp; Dim layersobject As AcadLayers<br/>&nbsp;&nbsp;&nbsp; Dim startPt(0 To 2) As Double, endPt(0 To 2) As Double<br/>&nbsp;&nbsp;&nbsp; startPt(0) = 1#: startPt(1) = 1#: startPt(2) = 0#<br/>&nbsp;&nbsp;&nbsp; endPt(0) = 5#: endPt(1) = 5#: endPt(2) = 0#<br/>&nbsp;&nbsp;&nbsp; Set lineObj = ThisDrawing.ModelSpace.AddLine(startPt, endPt)<br/>&nbsp;&nbsp;&nbsp; ZoomAll</p><p>&nbsp;&nbsp;&nbsp; ' Initialize all the xdata values. Note that first data in the list should be<br/>&nbsp;&nbsp;&nbsp; ' application name and first datatype code should be 1001<br/>&nbsp;&nbsp;&nbsp; Dim DataType(0 To 9) As Integer<br/>&nbsp;&nbsp;&nbsp; Dim Data(0 To 9) As Variant<br/>&nbsp;&nbsp;&nbsp; Dim reals3(0 To 2) As Double<br/>&nbsp;&nbsp;&nbsp; Dim worldPos(0 To 2) As Double<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; DataType(0) = 1001: Data(0) = "Test_Application"<br/>&nbsp;&nbsp;&nbsp; DataType(1) = 1000: Data(1) = "This is a test for xdata"</p><p>&nbsp;&nbsp;&nbsp; DataType(2) = 1003: Data(2) = "0"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ' layer<br/>&nbsp;&nbsp;&nbsp; DataType(3) = 1040: Data(3) = 1.23479137438413E+40&nbsp; ' real<br/>&nbsp;&nbsp;&nbsp; DataType(4) = 1041: Data(4) = 1237324938&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ' distance<br/>&nbsp;&nbsp;&nbsp; DataType(5) = 1070: Data(5) = 32767&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ' 16 bit Integer<br/>&nbsp;&nbsp;&nbsp; DataType(6) = 1071: Data(6) = 32767&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ' 32 bit Integer<br/>&nbsp;&nbsp;&nbsp; DataType(7) = 1042: Data(7) = 10&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ' scaleFactor</p><p>&nbsp;&nbsp;&nbsp; reals3(0) = -2.95: reals3(1) = 100: reals3(2) = -20<br/>&nbsp;&nbsp;&nbsp; DataType(8) = 1010: Data(8) = reals3&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ' real</p><p>&nbsp;&nbsp;&nbsp; worldPos(0) = 4: worldPos(1) = 400.99999999: worldPos(2) = 2.798989<br/>&nbsp;&nbsp;&nbsp; DataType(9) = 1011: Data(9) = worldPos&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ' world space position</p><p>&nbsp;&nbsp;&nbsp; ' Attach the xdata to the line<br/>&nbsp; Set layersobject = ThisDrawing.Layers<br/>&nbsp;&nbsp; layersobject.SetXData DataType, Data</p><p>&nbsp;&nbsp;&nbsp; ' Return the xdata for the line<br/>&nbsp;&nbsp;&nbsp; Dim xdataOut As Variant<br/>&nbsp;&nbsp;&nbsp; Dim xtypeOut As Variant<br/>&nbsp; layersobject.GetXData "", xtypeOut, xdataOut<br/>&nbsp;<br/>End Sub<br/>运行程序报错,想问下SetXData GetXData 不支持集合类?</p>

雪山飞狐_lzh 发表于 2009-10-18 19:36:00

<p>这种情况用字典更好</p>

lihengmin 发表于 2010-10-6 16:18:00

<p>&nbsp; Set layersobject = ThisDrawing.Layers<br/>&nbsp;&nbsp; layersobject.SetXData DataType, Data</p>扩展数据只能赋给实体,不能赋给层吧!
页: [1]
查看完整版本: [求助]集合类是否可以设置扩展数据