neophyte 发表于 2022-7-6 14:14:06

删除图形的一部分-VBA-

你好
 
我想知道如何擦除图形的一部分(通过VBA)。
 
要删除的区域在每个图形上始终相同
我想通过windows选择(点1:0,0,0点2:10,15,0)
 
我尝试使用AcSelectionSetWindow,但这不起作用
 
谢谢
 
ps:这是我测试的。我知道垃圾箱里有几行代码,但我保留了所有经过测试的代码行
 
Private Sub test()

   Dim ObjSelection As AcadSelectionSet
   Dim ObjetOut As AcadEntity

   Dim Point1(0 To 2) As Double
   Dim Point2(0 To 2) As Double
   Dim Point3(0 To 5) As Double
   'Data
   Point1(0) = 0#
   Point1(1) = 0#
   Point1(2) = 0#
   Point2(0) = 10#
   Point2(1) = 15#
   Point2(2) = 0#

   Point3(0) = 0#
   Point3(1) = 0#
   Point3(2) = 0#
   Point3(3) = 10#
   Point3(4) = 15#
   Point3(5) = 0#

    On Error Resume Next
    'set ObjSelection = ThisDrawing.PaperSpace.Item
   '. SelectionSets.Item.SelectByPolygon(acSelectionSetWindowPolygon, Point3)

   ObjSelection.Clear
   Set ObjetOut = ObjSelection.Select acSelectionSetWindow, Point1, Point2

   'ByPolygon acSelectionSetWindow, Point3

   'ObjSelection.Select acSelectionSetWindow, Point1, Point2
    'Set ObjSelection = SelectionSets.Item

'objSelection.Clear
'   Set objObjet = objSelection
'   objSelection.AddItems objObjets
'objSelection.Erase

   'objSelection.SelectByPolygon(acSelectionSetWindowPolygon, 0,0,0 10,15,0)
   'Set objselectionset = selectionsetscollection.Add(strCartouche)

End Sub

SEANT 发表于 2022-7-6 14:23:51

试试这个。
 
Private Sub test()

   Dim ObjSelection As AcadSelectionSet
   Dim ObjetOut As AcadEntity

   Dim Point1(0 To 2) As Double
   Dim Point2(0 To 2) As Double
   Dim Point3(0 To 5) As Double
   'Data
   Point1(0) = 0#
   Point1(1) = 0#
   Point1(2) = 0#
   Point2(0) = 10#
   Point2(1) = 15#
   Point2(2) = 0#

   On Error Resume Next
   ThisDrawing.SelectionSets.Item("TempSSet").Delete
   On Error GoTo 0
   
   Set ObjSelection = ThisDrawing.SelectionSets.Add("TempSSet")
   ObjSelection.Select acSelectionSetWindow, Point1, Point2
   
   For Each ObjetOut In ObjSelection
   ObjetOut.Delete
   Next

ThisDrawing.Regen acAllViewports
End Sub

neophyte 发表于 2022-7-6 14:36:57

谢谢
这非常有效。
 
我还有一个问题,什么是“TempSSet”?

SEANT 发表于 2022-7-6 14:40:18

从VBA实现时,选择集需要有名称。如果VBA例程尝试创建已存在的命名选择集和/或尝试删除不存在的命名选择集,该例程将崩溃。有几种方法可以解决这些问题;我使用的方法(两个“On Error”之间的语句)是最基本的。

neophyte 发表于 2022-7-6 14:48:38

谢谢你的提示。此外,感谢您抽出时间回答我们的问题

neophyte 发表于 2022-7-6 14:59:14

你好,又是我!
 
我忘了,我必须保留一些信息。此信息不在每个图形的同一层上。
所以可以擦除图形的一部分,但只能在一层上,在擦除实体之前进行“过滤”?
 
谢谢

SEANT 发表于 2022-7-6 15:10:36

是的,所有的选择方法(虽然不是Thisdrawing.Utility.GetEntity)都支持过滤。
 
此线程具有和使用按层过滤的选择的示例。该示例采用acSelectionSetAll模式,但与acSelectionSetWindow同样适用。
 
http://www.cadtutor.net/forum/showthread.php?t=38124

neophyte 发表于 2022-7-6 15:17:18

你的快!
谢谢你的链接,我没有看到这个脚印
页: [1]
查看完整版本: 删除图形的一部分-VBA-