- Sub test()
- Dim objselectionset As AcadSelectionSet
- Set objselectionset = ThisDrawing.SelectionSets.Add("objselectionset")
- Dim entobj(0) As AcadEntity
- Set entobj(0) = ThisDrawing.ModelSpace(0)
- objselectionset.AddItems entobj
- Set entobj(0) = ThisDrawing.ModelSpace(1)
- objselectionset.AddItems entobj
- Dim objselectionset1 As AcadSelectionSet
- Set objselectionset1 = ThisDrawing.SelectionSets.Add("objselectionset1")
- Set entobj(0) = ThisDrawing.ModelSpace(2)
- objselectionset1.AddItems entobj
- Set entobj(0) = ThisDrawing.ModelSpace(3)
- objselectionset1.AddItems entobj
-
- Dim entobj1 As AcadEntity
- Dim entobj2 As AcadEntity
- Dim pt As Variant
- Dim lineobj As AcadLine
- ' 处理水平的直线
- For Each entobj1 In objselectionset
- For Each entobj2 In objselectionset1
- Set lineobj = entobj1
- pt = entobj1.IntersectWith(entobj2, acExtendNone)
- If Sqr((pt(0) - lineobj.StartPoint(0)) ^ 2 + (pt(1) - lineobj.StartPoint(1)) ^ 2) _
- < Sqr((pt(0) - lineobj.EndPoint(0)) ^ 2 + (pt(1) - lineobj.EndPoint(1)) ^ 2) Then
- ThisDrawing.ModelSpace.AddLine lineobj.StartPoint, pt
- Else
- ThisDrawing.ModelSpace.AddLine pt, lineobj.EndPoint
- End If
- Next
- Next
- ' 处理垂直的直线
- For Each entobj1 In objselectionset1
- For Each entobj2 In objselectionset
- Set lineobj = entobj1
- pt = entobj1.IntersectWith(entobj2, acExtendNone)
- If Sqr((pt(0) - lineobj.StartPoint(0)) ^ 2 + (pt(1) - lineobj.StartPoint(1)) ^ 2) _
- < Sqr((pt(0) - lineobj.EndPoint(0)) ^ 2 + (pt(1) - lineobj.EndPoint(1)) ^ 2) Then
- ThisDrawing.ModelSpace.AddLine lineobj.StartPoint, pt
- Else
- ThisDrawing.ModelSpace.AddLine pt, lineobj.EndPoint
- End If
- Next
- Next
- ' 删除直线
- For Each entobj1 In objselectionset
- entobj1.Delete
- Next
- For Each entobj1 In objselectionset1
- entobj1.Delete
- Next
- End Sub
|