可以先找到交点,把交点坐标形成数组。然后在每个交点处选择周围的对象,将每个对象打断于交点。 找交点我用的是两两相交的办法,如果一个交点有两个以上对象,会有重复。希望有人能给出更好的方法。 对填充和块参照无法打断。 Sub 交点处相互打断() On Error Resume Next Dim ssetObj As AcadSelectionSet '创建选择集 Set ssetObj = ThisDrawing.SelectionSets("test") If Err Then Err.Clear Set ssetObj = ThisDrawing.SelectionSets.Add("test") End If ssetObj.Clear '首先清空选择集 ssetObj.Select acSelectionSetAll ' 取得交点 Dim i As Long Dim j As Long Dim k As Long Dim pt As Variant Dim points() As Double Dim N As Long N = 0 For i = 0 To ssetObj.Count - 1 For j = i + 1 To ssetObj.Count - 1 pt = ssetObj(i).IntersectWith(ssetObj(j), acExtendNone) If UBound(pt) >= 2 Then ReDim Preserve points(N + UBound(pt)) '逐步定义数组,需要关键字 For k = 0 To UBound(pt) points(N + k) = pt(k) Next N = N + UBound(pt) + 1 End If Next Next '交点处打断 Dim bpt(0 To 2) As Double Dim ss As AcadSelectionSet Set ss = ThisDrawing.SelectionSets("dog") If Err Then Err.Clear Set ss = ThisDrawing.SelectionSets.Add("dog") End If For i = 0 To UBound(points) Step 3 bpt(0) = points(i) bpt(1) = points(i + 1) bpt(2) = points(i + 2) ss.Clear SelectAtPoint ss, bpt For k = 0 To ss.Count - 1 ThisDrawing.SendCommand "_break" & vbCr & "(handent """ & ss(k).Handle & """)" & vbCr & bpt(0) & "," & bpt(1) & vbCr & "@" & vbCr Next Next End Sub
' 选择通过某点的实体 Public Sub SelectAtPoint(ByRef SSet As AcadSelectionSet, ByVal pt As Variant) ' 构造一个以pt为中心的小矩形作为选择范围 Dim pt1 As Variant, pt2 As Variant Dim objUtility As Object Set objUtility = ThisDrawing.Utility ' 必须使用后期绑定 objUtility.CreateTypedArray pt1, vbDouble, pt(0) - 0.0001, pt(1) - 0.0001, pt(2) objUtility.CreateTypedArray pt2, vbDouble, pt(0) + 0.0001, pt(1) + 0.0001, pt(2) SSet.Select acSelectionSetCrossing, pt1, pt2 End Sub
|