- 积分
- 2943
- 明经币
- 个
- 注册时间
- 2003-11-3
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
- uniteSS为框选。uniteline为一根一根选择(只能选择两根)。对多段线和直线都有效。
复制代码- Sub uniteSS()
- 'On Error Resume Next
- Dim ssetObj As AcadSelectionSet
- Set ssetObj = CreateSelectionSet("uniteSS")
- Dim fType, fData
- BuildFilter fType, fData, -4, "<or", 0, "line", 0, "LWPolyline", -4, "or>"
- '屏选直线或多段线
- ssetObj.SelectOnScreen fType, fData
- Dim i As Integer
- If ssetObj.Count <= 1 Then
- ThisDrawing.Utility.Prompt "选择的线少于两个,退出命令。"
- Exit Sub
- End If
-
- Dim line1 As Object
- Dim line2 As Object
-
- Set line1 = ssetObj(0)
- Dim pd As Boolean
- For i = 1 To ssetObj.Count
- Set line2 = ssetObj(i)
- '连接线
- pd = unite2Line(line1, line2)
- '如果连接不成功,则退出命令。
- If Not pd Then ssetObj.Delete: Exit Sub
- Next
- ssetObj.Delete
- End Sub
- Sub uniteline()
- On Error Resume Next
- '取得线
- Dim line1 As Object
- Dim line2 As Object
- Dim pt1, pt2, pt3, pt4, basePnt As AcadEntity
- Dim lpt1, lpt2 As Variant
-
- gwGetEntity line1, basePnt, "请选择第一根直线或多段线:", "AcDbLine", "AcDbPolyline"
- If line1 Is Nothing Then
- ThisDrawing.Utility.Prompt "用户取消,退出命令。"
- Exit Sub
- End If
-
- gwGetEntity line2, basePnt, "请选择第二根直线或多段线:", "AcDbLine", "AcDbPolyline"
- If line2 Is Nothing Then
- ThisDrawing.Utility.Prompt "用户取消,退出命令。"
- Exit Sub
- End If
- '连接线
- unite2Line line1, line2
- End Sub
- Function unite2Line(ByRef line1 As Object, ByVal line2 As Object) As Boolean
- '连接线函数,连接后的线返回到变量line1中,如果连接成功,unite2Line返回true,否则为false
- On Error Resume Next
- unite2Line = False
-
- If line1.Handle = line2.Handle Then
- ThisDrawing.Utility.Prompt "选择的是同一直线或多段线,退出命令。"
- Exit Function
- End If
-
- getLinePoint line1, pt1, pt2
- getLinePoint line2, pt3, pt4
-
- Dim A1, A2, A3 As Double
- Dim maxdi As Double
- A1 = ThisDrawing.Utility.AngleFromXAxis(pt1, pt2)
- A2 = ThisDrawing.Utility.AngleFromXAxis(pt3, pt4)
- A3 = ThisDrawing.Utility.AngleFromXAxis(pt1, pt3)
- '判断四点是否共线
- If Abs(A1 - A2) < 0.0000001 And (Abs(A1 - A3) < 0.0000001 Or Abs(Abs(A1 - A3) - PI) < 0.0000001) Then
- '取得距离最远的两个点。
- maxdi = MaxDouble(GetDistance(pt1, pt2), GetDistance(pt1, pt3), GetDistance(pt1, pt4), _
- GetDistance(pt2, pt3), GetDistance(pt2, pt4), GetDistance(pt3, pt4))
- If GetDistance(pt1, pt2) = maxdi Then lpt1 = pt1: lpt2 = pt2
- If GetDistance(pt1, pt3) = maxdi Then lpt1 = pt1: lpt2 = pt3
- If GetDistance(pt1, pt4) = maxdi Then lpt1 = pt1: lpt2 = pt4
- If GetDistance(pt2, pt3) = maxdi Then lpt1 = pt2: lpt2 = pt3
- If GetDistance(pt2, pt4) = maxdi Then lpt1 = pt2: lpt2 = pt4
- If GetDistance(pt3, pt4) = maxdi Then lpt1 = pt3: lpt2 = pt4
- '画直线
- Select Case line1.ObjectName
- Case "AcDbLine"
- line1.StartPoint = lpt1
- line1.EndPoint = lpt2
- line2.Delete
- ThisDrawing.Utility.Prompt "线段已连接为直线."
- unite2Line = True
- Case "AcDbPolyline"
- Dim newPline As AcadLWPolyline
- Set newPline = AddLWPlineSeg(lpt1, lpt2, line1.ConstantWidth)
- newPline.Layer = line1.Layer
- newPline.color = line1.color
- newPline.Linetype = line1.Linetype
- line1.Delete
- line2.Delete
- Set line1 = newPline
- ThisDrawing.Utility.Prompt "线段已连接为多段线."
- unite2Line = True
- End Select
- Else: ThisDrawing.Utility.Prompt "两线不在同一直线上,退出命令."
- End If
- End Function
|
|