topirol 发表于 2003-7-3 20:10:00

删除一个图层上的所有实体,用什么办法比较好呢?

我目前用的方法是
for i=0 to mospace.count-1 step 1

if mospace.item(i).layer="kk" then
set entry=mospace.item(i)
entry.delete
end if
next

但如果mospace中实体数量很大的时候就很慢了,请问有没有更好的办法呢?

mccad 发表于 2003-7-3 22:51:00

用选择集的方法比较好

dongcijie 发表于 2003-7-7 11:47:00

如何使用选择集?

mccad 发表于 2003-7-7 12:24:00

Sub DelLayEnt()
    Dim LayerName As String
    LayerName = "0"'这里保存着要删除的图层名称
    Dim ss As AcadSelectionSet
    Set ss = CreateSelectionSet()
    Dim fType As Variant
    Dim fDate As Variant
    BuildFilter fType, fData, 8, LayerName
    ss.Select acSelectionSetAll, , , fType, fData
    Dim Ent As AcadEntity
    For Each Ent In ss
      Ent.Delete
    Next
    Update
    Debug.Print "所有在图层" & LayerName & "上的对象都已经被删除了。"
End Sub

Public Sub BuildFilter(typeArray, dataArray, ParamArray gCodes())
    Dim fType() As Integer, fData()
    Dim index As Long, i As Long
   
    index = LBound(gCodes) - 1
      
    For i = LBound(gCodes) To UBound(gCodes) Step 2
      index = index + 1
      ReDim Preserve fType(0 To index)
      ReDim Preserve fData(0 To index)
      fType(index) = CInt(gCodes(i))
      fData(index) = gCodes(i + 1)
    Next
    typeArray = fType: dataArray = fData
End Sub

Public Function CreateSelectionSet(Optional ssName As String = "ss") As AcadSelectionSet

    Dim ss As AcadSelectionSet
   
    On Error Resume Next
    Set ss = ThisDrawing.SelectionSets(ssName)
    If Err Then Set ss = ThisDrawing.SelectionSets.Add(ssName)
    ss.Clear
    Set CreateSelectionSet = ss
End Function

清风明月名字 发表于 2012-4-1 09:05:21

谢谢mccad,代码非常好用

千度Show颖 发表于 2012-9-7 10:13:15

这个是什么语言的代码
页: [1]
查看完整版本: 删除一个图层上的所有实体,用什么办法比较好呢?