- 积分
- 5155
- 明经币
- 个
- 注册时间
- 2003-1-15
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
发表于 2004-6-4 22:12:00
|
显示全部楼层
cxf11991发表于2004-6-4 17:11:00我做的是关于剪切线段的代码 比如说有4条直线成井字放置,长短都不一样,我想把交点之间的线段都剪掉, 这样:- Option ExplicitPublic Sub CrossWall()
- Dim hline1 As AcadLine, hline2 As AcadLine, vline1 As AcadLine, vline2 As AcadLine
- Dim hline11 As AcadLine, hline12 As AcadLine
- Dim hline21 As AcadLine, hline22 As AcadLine
- Dim vline11 As AcadLine, vline12 As AcadLine
- Dim vline21 As AcadLine, vline22 As AcadLine
- Dim p1, p2, p3, p4 As Variant
- Dim sset As AcadSelectionSet
- Dim scount As Integer, i As Integer i = ThisDrawing.SelectionSets.Count
-
- While (i > 0)
- Set sset = ThisDrawing.SelectionSets.Item(i - 1)
- If sset.Name = "EXTSET" Then
- sset.Delete
- End If
- i = i - 1
- Wend
-
- Set sset = ThisDrawing.SelectionSets.Add("EXTSET") ThisDrawing.Utility.Prompt "请「框选」欲修十字交角的墙线....."
- Dim cwp1, cwp2, interpt
-
- cwp1 = ThisDrawing.Utility.GetPoint(, "框选的第一点:")
- cwp2 = ThisDrawing.Utility.GetCorner(cwp1, "框选的对角点:")
-
- Dim gpCode(0) As Integer
- Dim dataValue(0) As Variant
- gpCode(0) = 0
- dataValue(0) = "Line"
-
- Dim groupCode As Variant, dataCode As Variant
- groupCode = gpCode
- dataCode = dataValue
-
- sset.Select acSelectionSetCrossing, cwp1, cwp2, groupCode, dataCode scount = sset.Count
-
- If scount > 4 Then
- MsgBox "您框选了超过四条以上的墙线. 请再执行程序一次....", vbOKOnly, "trim error"
- Exit Sub
- ElseIf scount < 4 Then
- MsgBox "您框选了的墙线少于四条. 请再执行程序一次....", vbOKOnly, "trim error"
- Exit Sub
- End If
-
-
- Set hline1 = sset.Item(0)
-
- Dim si As Integer
-
- For si = 1 To 3
- interpt = hline1.IntersectWith(sset.Item(si), acExtendNone)
- If UBound(interpt) = -1 Then
- Set hline2 = sset.Item(si)
- End If
- Next
-
- For si = 1 To 3
- If sset.Item(si).ObjectID <> hline1.ObjectID And sset.Item(si).ObjectID <> hline2.ObjectID Then
- Set vline1 = sset.Item(si)
- End If
- Next
- For si = 1 To 3
- If sset.Item(si).ObjectID <> hline1.ObjectID And _
- sset.Item(si).ObjectID <> hline2.ObjectID And sset.Item(si).ObjectID <> vline1.ObjectID Then
- Set vline2 = sset.Item(si)
- End If
- Next
-
- p1 = hline1.IntersectWith(vline1, acExtendNone)
- p2 = hline1.IntersectWith(vline2, acExtendNone)
- p3 = hline2.IntersectWith(vline1, acExtendNone)
- p4 = hline2.IntersectWith(vline2, acExtendNone)
- If UBound(p1) = -1 Or UBound(p2) = -1 Or UBound(p3) = -1 Or UBound(p4) = -1 Then
- MsgBox "您所选取的墙线无法在 X 方向做截取动作,请于修正错误后,再试一次!", vbOKOnly
- Exit Sub
- End If
-
- If distance(hline1.StartPoint, p1) > distance(hline1.StartPoint, p2) Then
- Set hline11 = ThisDrawing.ModelSpace.AddLine(hline1.StartPoint, p2)
- Set hline12 = ThisDrawing.ModelSpace.AddLine(hline1.EndPoint, p1)
- Else
- Set hline11 = ThisDrawing.ModelSpace.AddLine(hline1.StartPoint, p1)
- Set hline12 = ThisDrawing.ModelSpace.AddLine(hline1.EndPoint, p2)
- End If
-
- If distance(hline2.StartPoint, p3) > distance(hline1.StartPoint, p4) Then
- Set hline21 = ThisDrawing.ModelSpace.AddLine(hline2.StartPoint, p4)
- Set hline22 = ThisDrawing.ModelSpace.AddLine(hline2.EndPoint, p3)
- Else
- Set hline21 = ThisDrawing.ModelSpace.AddLine(hline2.StartPoint, p3)
- Set hline22 = ThisDrawing.ModelSpace.AddLine(hline2.EndPoint, p4)
- End If
-
- If distance(vline1.StartPoint, p1) > distance(vline1.StartPoint, p3) Then
- Set vline11 = ThisDrawing.ModelSpace.AddLine(vline1.StartPoint, p3)
- Set vline12 = ThisDrawing.ModelSpace.AddLine(vline1.EndPoint, p1)
- Else
- Set vline11 = ThisDrawing.ModelSpace.AddLine(vline1.StartPoint, p1)
- Set vline12 = ThisDrawing.ModelSpace.AddLine(vline1.EndPoint, p3)
- End If
-
- If distance(vline2.StartPoint, p2) > distance(vline2.StartPoint, p4) Then
- Set vline21 = ThisDrawing.ModelSpace.AddLine(vline2.StartPoint, p4)
- Set vline22 = ThisDrawing.ModelSpace.AddLine(vline2.EndPoint, p2)
- Else
- Set vline21 = ThisDrawing.ModelSpace.AddLine(vline2.StartPoint, p2)
- Set vline22 = ThisDrawing.ModelSpace.AddLine(vline2.EndPoint, p4)
- End If
-
- hline11.Layer = hline1.Layer
- hline12.Layer = hline1.Layer
- hline21.Layer = hline1.Layer
- hline22.Layer = hline1.Layer
- vline11.Layer = hline1.Layer
- vline12.Layer = hline1.Layer
- vline21.Layer = hline1.Layer
- vline22.Layer = hline1.Layer
-
- hline1.Delete
- hline2.Delete
- vline1.Delete
- vline2.Delete
- End Sub
- Function distance(pt1, pt2 As Variant) As Double
- distance = ((pt1(0) - pt2(0)) ^ 2 + (pt1(1) - pt2(1)) ^ 2) ^ 0.5
- End Function
|
|