我想遍历图层"ab1"中的图块及图层"abcd"的闭合多段线,如果图块的坐标在闭合多段线的区域外,则把区域外的图块删除,如在闭合的区域内,则保留。 我想把图块的坐标点画圆,面域,把闭合多段线也进行面域,并求交,如有相交,则保留,没相交则删除, 可是我这个程序有问题,下面也不知道怎么编了,请高手帮帮忙,帮我修改一下。 Sub Example_Select() '选择某图层的图块与多段线区域比较 Dim ssetObj As AcadSelectionSet On Error Resume Next Set ssetObj = ThisDrawing.SelectionSets.Add("SSET") If Err <> 0 Then Set ssetObj = ThisDrawing.SelectionSets.Item("SSET") ssetObj.Clear End If Dim mode As Integer Dim object As AcadEntity mode = acSelectionSetAll Dim gpCode(1) As Integer Dim dataValue(1) As Variant gpCode(0) = 0 dataValue(0) = "insert" gpCode(1) = 8 dataValue(1) = "ab1" Dim groupCode As Variant, dataCode As Variant groupCode = gpCode dataCode = dataValue ssetObj.Select mode, , , groupCode, dataCode '提示有几个对象加入选择集 MsgBox "图中有" & ssetObj.Count & "个图元已加入到选择集SSET中。" '遍历程序 For i = 0 To ssetObj.Count - 1 Set object = ssetObj.Item(i) Next i '定义变量为变体型 Dim xy As Variant '遍历选择集的对象 For Each ent In ssetObj '求出块对象的坐标 xy = ent.InsertionPoint '以下为绘制圆程序 Dim cobj(0 To 0) As AcadCircle Set cobj(0) = ThisDrawing.ModelSpace.AddCircle(xy, 50) cobj(0).Layer = "ab1" '对圆进行面域 Dim regionobj As Variant regionobj = ThisDrawing.ModelSpace.AddRegion(cobj) cobj(0).Erase Next 'MsgBox "坐标是:" & xy(0) ''''''''''''' '以上部分为图块坐标提取程序 ''''''''''''''''''''''' '以下部分为多段线提取并面域 Dim ssetObj1 As AcadSelectionSet Set ssetObj1 = ThisDrawing.SelectionSets.Add("SSET1") If Err <> 0 Then Set ssetObj1 = ThisDrawing.SelectionSets.Item("SSET1") ssetObj1.Clear End If Dim mode1 As Integer Dim object1(0 To 0) As AcadEntity mode1 = acSelectionSetAll Dim gpCode1(1) As Integer Dim dataValue1(1) As Variant gpCode1(0) = 0 dataValue1(0) = "LWPOLYLINE" gpCode1(1) = 8 dataValue1(1) = "abcd" Dim groupCode1 As Variant, dataCode1 As Variant groupCode1 = gpCode1 dataCode1 = dataValue1 ssetObj1.Select mode1, , , groupCode1, dataCode1 '显示有几个图元加入选择集内 MsgBox "图中有" & ssetObj1.Count & "个图元已加入到选择集SSET中。" For i1 = 0 To ssetObj1.Count - 1 Set object1(0) = ssetObj1.Item(i1) If Not Err Then Dim regionobj1 As Variant regionobj1 = ThisDrawing.ModelSpace.AddRegion(object1) End If Next i1 Dim roundroomobj As AcadRegion Dim pillarobj As AcadRegion 'If regionobj(0).Area > regionobj1(0).Area Then
Set roundroomobj = regionobj1(0) Set pillarobj = regionobj(0) 'Else 'Set pillarobj = regionobj1(0) 'Set roundroomobj = regionobj(0) 'End If roundroomobj.Color = acRed pillarobj.Color = acCyan roundroomobj.Boolean acIntersection, pillarobj End Sub
|