适用于交点处仅有两条相关线条,按附件要求编程如下,请检验: Sub 交点处等间距打断2() On Error Resume Next Dim Ent1 As AcadEntity, Pnt1 As Variant Dim Ent2 As AcadEntity, Pnt2 As Variant ThisDrawing.Utility.GetEntity Ent1, Pnt1, "选择一个对象用于打断:" If Err Then Exit Sub ThisDrawing.Utility.GetEntity Ent2, Pnt2, "选择一个被打断的对象:" If Err Then Exit Sub Dim Layer1 As String Dim Layer2 As String Layer1 = Ent1.Layer Layer2 = Ent2.Layer Dim fType(0) As Integer ' 过滤器规则 Dim fData(0) As Variant ' 过滤器参数 fType(0) = 8 fData(0) = Layer1 & "," & Layer2 Dim SSfish As AcadSelectionSet '创建选择集 Set SSfish = ThisDrawing.SelectionSets("fish") If Err Then Err.Clear Set SSfish = ThisDrawing.SelectionSets.Add("fish") End If SSfish.Clear '首先清空选择集 SSfish.SelectOnScreen fType, fData Dim jianju As Double jianju = ThisDrawing.Utility.GetReal("指定打断间距:") If Err Then Exit Sub ' 取得交点 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 SSfish.Count - 2 For j = i + 1 To SSfish.Count - 1 pt = SSfish(i).IntersectWith(SSfish(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 circleObj As AcadCircle Dim cpt As Variant Dim cpt1(2) As Double Dim cpt2(2) As Double Dim SSdog As AcadSelectionSet Set SSdog = ThisDrawing.SelectionSets("dog") If Err Then Err.Clear Set SSdog = ThisDrawing.SelectionSets.Add("dog") End If Dim SSpig As AcadSelectionSet Set SSpig = ThisDrawing.SelectionSets("pig") If Err Then Err.Clear Set SSpig = ThisDrawing.SelectionSets.Add("pig") End If Dim BreakObj As AcadEntity For i = 0 To UBound(points) Step 3 bpt(0) = points(i) bpt(1) = points(i + 1) bpt(2) = points(i + 2) SSdog.Clear SelectAtPoint SSdog, bpt SSpig.Clear SSpig.Select acSelectionSetPrevious, , , fType, fData If SSpig.Count <> 2 Then Exit Sub Set circleObj = ThisDrawing.ModelSpace.AddCircle(bpt, jianju / 2) If SSpig(0).Layer = Layer1 And SSpig(1).Layer = Layer2 Then Set BreakObj = SSpig(1) ElseIf SSpig(0).Layer = Layer2 And SSpig(1).Layer = Layer1 Then Set BreakObj = SSpig(0) ElseIf SSpig(0).Layer = Layer2 And SSpig(1).Layer = Layer2 Then Set BreakObj = SSpig(1) '自行设定 Else GoTo 10 End If cpt = BreakObj.IntersectWith(circleObj, acExtendNone) If UBound(cpt) = 5 Then cpt1(0) = cpt(0) cpt1(1) = cpt(1) cpt1(2) = cpt(2) cpt2(0) = cpt(3) cpt2(1) = cpt(4) cpt2(2) = cpt(5) ThisDrawing.SendCommand "_break" & vbCr & axEnt2lspEnt(BreakObj) & vbCr & axPoint2lspPoint(cpt1) & vbCr & axPoint2lspPoint(cpt2) & vbCr End If 10: circleObj.Delete 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 ' 转换点的函数 Public Function axPoint2lspPoint(ByVal pnt As Variant) As String axPoint2lspPoint = pnt(0) & "," & pnt(1) & "," & pnt(2) End Function ' 转换图元函数 Public Function axEnt2lspEnt(ByVal entObj As AcadEntity) As String Dim entHandle As String entHandle = entObj.Handle axEnt2lspEnt = "(handent " & Chr(34) & entHandle & Chr(34) & ")" End Function |