明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 3061|回复: 4

[VBA]请教遍历图像对象

[复制链接]
发表于 2005-11-14 11:06:00 | 显示全部楼层 |阅读模式
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
    Dim I As Integer
    objCount = ThisDrawing.ModelSpace.count
    
    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
请问当modelspace中对象数目超过Integer上限时该如何处理。
发表于 2005-11-14 17:01:00 | 显示全部楼层

  dim i as double

For I = 0 To ThisDrawing.ModelSpace.count  - 1 step 1
     Set mspaceObj = ThisDrawing.ModelSpace.Item(fix(I)) '取整
    MsgBox "The objects in ModelSpace include: " & mspaceObj.ObjectName, vbInformation, "Count 示例"
    Next

1,你用什么版本的AutoCAD 和VB?

2,你可以使用长整数

3,For each Obj in ModelSpace 这样不用到整数,ModelSpace 是一个集合

 楼主| 发表于 2005-11-14 22:48:00 | 显示全部楼层

以前论坛里的一个例子:

Private Sub AcadDocument_BeginCommand(ByVal CommandName As String)
'Dim entcount As Double
entcount = ThisDrawing.ModelSpace.Count
End Sub
Private Sub AcadDocument_EndCommand(ByVal CommandName As String)
    If Left(UCase(CommandName), 3) = "DIM" Then
       'Count = ThisDrawing.ModelSpace.Count
        Dim NewEnt As AcadEntity
        Dim i As Long
        Dim NewLayerName As String
        '以下定义了要将标注对象移动到的图层名称
        NewLayerName = "标注"
        Dim newlayer As AcadLayer
        Set newlayer = ThisDrawing.Layers.Add(NewLayerName)
        newlayer.color = acGreen
        For i = entcount To ThisDrawing.ModelSpace.Count - 1
        Set NewEnt = ThisDrawing.ModelSpace.Item(i)
        'If TypeOf NewEnt Is AcadDimension Then
        NewEnt.Layer = "标注"
        'End If
        Next

end sub

当对象超过integer上限时就会出错,如果用For each Obj in ModelSpace 方法,每次遍历选择集就会很慢。

发表于 2006-9-8 15:45:00 | 显示全部楼层

用For each Obj in ModelSpace 方法遍历选择集,与用dim as Inter 有何区别?

一张图纸的实体数是一定的,分实体遍历也是一样的.只不过是过滤了line,circle等实体.

 

发表于 2006-12-25 14:29:00 | 显示全部楼层

稍微练习了一下,有点收获

不过还不知道怎么筛选

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2025-2-23 03:00 , Processed in 0.185601 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表