[VBA]请教遍历图像对象
<PRE class=Code>Sub Example_Count()' Use count to retrieve the number of objects in a collection
' You might use this value in a loop structure to iterate through the collection
MsgBox "There are " & ThisDrawing.Layers.count & " layer(s) in the drawing."
MsgBox "There are " & ThisDrawing.ModelSpace.count & " object(s) in ModelSpace."
Dim objCount As Integer
<FONT color=#de1062> Dim I As Integer
objCount = ThisDrawing.ModelSpace.count</FONT>
Dim mspaceObj As AcadObject
For I = 0 To objCount - 1
Set mspaceObj = ThisDrawing.ModelSpace.Item(I)
MsgBox "The objects in ModelSpace include: " & mspaceObj.ObjectName, vbInformation, "Count 示例"
Next
End Sub</PRE><PRE class=Code>请问当modelspace中对象数目超过<FONT color=#de1062>Integer上限时该如何处理。</FONT></PRE> <P> dim i as double</P>
<P>For I = 0 To <FONT color=#de1062>ThisDrawing.ModelSpace.count </FONT> - 1 step 1<BR> Set mspaceObj = ThisDrawing.ModelSpace.Item(fix(I)) '取整<BR> MsgBox "The objects in ModelSpace include: " & mspaceObj.ObjectName, vbInformation, "Count 示例"<BR> Next</P>
<P>1,你用什么版本的AutoCAD 和VB?</P>
<P>2,你可以使用长整数</P>
<P>3,For each Obj in ModelSpace 这样不用到整数,ModelSpace 是一个集合<BR></P> <P>以前论坛里的一个例子:</P>
<P>Private Sub AcadDocument_BeginCommand(ByVal CommandName As String)<BR>'Dim entcount As Double<BR>entcount = ThisDrawing.ModelSpace.Count<BR>End Sub<BR>Private Sub AcadDocument_EndCommand(ByVal CommandName As String)<BR> If Left(UCase(CommandName), 3) = "DIM" Then<BR> 'Count = ThisDrawing.ModelSpace.Count<BR> Dim NewEnt As AcadEntity<BR> Dim i As Long<BR> Dim NewLayerName As String<BR> '以下定义了要将标注对象移动到的图层名称<BR> NewLayerName = "标注"<BR> Dim newlayer As AcadLayer<BR> Set newlayer = ThisDrawing.Layers.Add(NewLayerName)<BR> newlayer.color = acGreen<BR> For i = entcount To ThisDrawing.ModelSpace.Count - 1<BR> Set NewEnt = ThisDrawing.ModelSpace.Item(i)<BR> 'If TypeOf NewEnt Is AcadDimension Then<BR> NewEnt.Layer = "标注"<BR> 'End If<BR> Next</P>
<P>end sub</P>
<P>当对象超过integer上限时就会出错,如果用For each Obj in ModelSpace 方法,每次遍历选择集就会很慢。</P> <P>用For each Obj in ModelSpace 方法遍历选择集,与用dim as Inter 有何区别?</P>
<P>一张图纸的实体数是一定的,分实体遍历也是一样的.只不过是过滤了line,circle等实体.</P>
<P> </P> <p>稍微练习了一下,有点收获</p><p>不过还不知道怎么筛选</p>
页:
[1]