Sub dxlj()‘-------------------------------多线连接 Dim zuobiao As Variant Dim zuobiao1 As Variant Dim xuln As AcadLWPolyline On Error GoTo we Dim mysel As AcadSelectionSet If ThisDrawing.SelectionSets.count = 0 Then Set mysel = ThisDrawing.SelectionSets.Add("mysel") AppActivate ThisDrawing.Application.Caption mysel.SelectOnScreen Else ThisDrawing.SelectionSets.Item(0).Delete Set mysel = ThisDrawing.SelectionSets.Add("mysel") AppActivate ThisDrawing.Application.Caption mysel.SelectOnScreen End If If mysel.count = 2 Then Dim minn As Integer Dim minn1 As Integer If mysel(0).EntityType = 24 And mysel(1).EntityType = 24 Then zuobiao = mysel(0).Coordinates zuobiao1 = mysel(1).Coordinates minn = UBound(zuobiao) minn1 = UBound(zuobiao1) ReDim zuobb(0 To minn + minn1 + 1) As Double If Sqr((zuobiao(UBound(zuobiao) - 1) - zuobiao1(0)) ^ 2 + (zuobiao(UBound(zuobiao)) - zuobiao1(1)) ^ 2) _ < Sqr((zuobiao(UBound(zuobiao) - 1) - zuobiao1(UBound(zuobiao1) - 1)) ^ 2 + (zuobiao(UBound(zuobiao)) - zuobiao1(UBound(zuobiao1))) ^ 2) And Sqr((zuobiao(UBound(zuobiao) - 1) - zuobiao1(0)) ^ 2 + (zuobiao(UBound(zuobiao)) - zuobiao1(1)) ^ 2) _ < Sqr((zuobiao(0) - zuobiao1(0)) ^ 2 + (zuobiao(1) - zuobiao1(1)) ^ 2) Then For i = 0 To minn zuobb(i) = zuobiao(i) Next For i = 0 To minn1 zuobb(i + minn + 1) = zuobiao1(i) Next ElseIf Sqr((zuobiao(UBound(zuobiao) - 1) - zuobiao1(UBound(zuobiao1) - 1)) ^ 2 + (zuobiao(UBound(zuobiao)) - zuobiao1(UBound(zuobiao1))) ^ 2) _ < Sqr((zuobiao(UBound(zuobiao) - 1) - zuobiao1(0)) ^ 2 + (zuobiao(UBound(zuobiao)) - zuobiao1(1)) ^ 2) And Sqr((zuobiao(UBound(zuobiao) - 1) - zuobiao1(UBound(zuobiao1) - 1)) ^ 2 + (zuobiao(UBound(zuobiao)) - zuobiao1(UBound(zuobiao1))) ^ 2) _ < Sqr((zuobiao(0) - zuobiao1(UBound(zuobiao1) - 1)) ^ 2 + (zuobiao(1) - zuobiao1(UBound(zuobiao1))) ^ 2) Then For i = 0 To minn zuobb(i) = zuobiao(i) Next For i = 0 To minn1 Step 2 zuobb(i + minn + 1) = zuobiao1(minn1 - i - 1) zuobb(i + minn + 2) = zuobiao1(minn1 - i) Next ElseIf Sqr((zuobiao(0) - zuobiao1(0)) ^ 2 + (zuobiao(1) - zuobiao1(1)) ^ 2) _ < Sqr((zuobiao(0) - zuobiao1(UBound(zuobiao1) - 1)) ^ 2 + (zuobiao(1) - zuobiao1(UBound(zuobiao1))) ^ 2) And Sqr((zuobiao(0) - zuobiao1(0)) ^ 2 + (zuobiao(1) - zuobiao1(1)) ^ 2) _ < Sqr((zuobiao(UBound(zuobiao) - 1) - zuobiao1(0)) ^ 2 + (zuobiao(UBound(zuobiao)) - zuobiao1(1)) ^ 2) Then For i = 0 To minn Step 2 zuobb(i) = zuobiao(minn - i - 1) zuobb(i + 1) = zuobiao(minn - i) Next For i = 0 To minn1 zuobb(i + minn + 1) = zuobiao1(i) Next ElseIf Sqr((zuobiao(0) - zuobiao1(UBound(zuobiao1) - 1)) ^ 2 + (zuobiao(1) - zuobiao1(UBound(zuobiao1))) ^ 2) _ < Sqr((zuobiao(0) - zuobiao1(0)) ^ 2 + (zuobiao(1) - zuobiao1(1)) ^ 2) And Sqr((zuobiao(0) - zuobiao1(UBound(zuobiao1) - 1)) ^ 2 + (zuobiao(1) - zuobiao1(UBound(zuobiao1))) ^ 2) _ < Sqr((zuobiao(UBound(zuobiao) - 1) - zuobiao1(UBound(zuobiao1) - 1)) ^ 2 + (zuobiao(UBound(zuobiao)) - zuobiao1(UBound(zuobiao1))) ^ 2) Then For i = 0 To minn Step 2 zuobb(i) = zuobiao(minn - i - 1) zuobb(i + 1) = zuobiao(minn - i) Next For i = 0 To minn1 Step 2 zuobb(i + minn + 1) = zuobiao1(minn1 - i - 1) zuobb(i + minn + 2) = zuobiao1(minn1 - i) Next End If ThisDrawing.ActiveLayer = ThisDrawing.Layers(mysel(0).Layer) Set xuln = ThisDrawing.ModelSpace.AddLightWeightPolyline(zuobb) xuln.Elevation = mysel(0).Elevation xuln.Thickness = mysel(0).Thickness xuln.ConstantWidth = mysel(0).ConstantWidth xuln.Linetype = mysel(0).Linetype xuln.color = mysel(0).color xuln.Lineweight = mysel(0).Lineweight mysel(0).Delete mysel(1).Delete ElseIf mysel(0).EntityType = 2 And mysel(1).EntityType = 2 Then zuobiao = mysel(0).Coordinates zuobiao1 = mysel(1).Coordinates minn = UBound(zuobiao) minn1 = UBound(zuobiao1) ReDim zuobb(0 To minn + minn1 + 1) As Double If Sqr((zuobiao(UBound(zuobiao) - 2) - zuobiao1(0)) ^ 2 + (zuobiao(UBound(zuobiao) - 1) - zuobiao1(1)) ^ 2) _ < Sqr((zuobiao(UBound(zuobiao) - 2) - zuobiao1(UBound(zuobiao1) - 2)) ^ 2 + (zuobiao(UBound(zuobiao) - 1) - zuobiao1(UBound(zuobiao1) - 1)) ^ 2) And Sqr((zuobiao(UBound(zuobiao) - 2) - zuobiao1(0)) ^ 2 + (zuobiao(UBound(zuobiao) - 1) - zuobiao1(1)) ^ 2) _ < Sqr((zuobiao(0) - zuobiao1(0)) ^ 2 + (zuobiao(1) - zuobiao1(1)) ^ 2) Then For i = 0 To minn zuobb(i) = zuobiao(i) Next For i = 0 To minn1 zuobb(i + minn + 1) = zuobiao1(i) Next ElseIf Sqr((zuobiao(UBound(zuobiao) - 2) - zuobiao1(UBound(zuobiao1) - 2)) ^ 2 + (zuobiao(UBound(zuobiao) - 1) - zuobiao1(UBound(zuobiao1) - 1)) ^ 2) _ < Sqr((zuobiao(UBound(zuobiao) - 2) - zuobiao1(0)) ^ 2 + (zuobiao(UBound(zuobiao) - 1) - zuobiao1(1)) ^ 2) And Sqr((zuobiao(UBound(zuobiao) - 2) - zuobiao1(UBound(zuobiao1) - 2)) ^ 2 + (zuobiao(UBound(zuobiao) - 1) - zuobiao1(UBound(zuobiao1) - 1)) ^ 2) _ < Sqr((zuobiao(0) - zuobiao1(UBound(zuobiao1) - 2)) ^ 2 + (zuobiao(1) - zuobiao1(UBound(zuobiao1) - 1)) ^ 2) Then For i = 0 To minn zuobb(i) = zuobiao(i) Next For i = 0 To minn1 Step 3 zuobb(i + minn + 1) = zuobiao1(minn1 - i - 2) zuobb(i + minn + 2) = zuobiao1(minn1 - i - 1) zuobb(i + minn + 3) = zuobiao1(minn1 - i) Next ElseIf Sqr((zuobiao(0) - zuobiao1(0)) ^ 2 + (zuobiao(1) - zuobiao1(1)) ^ 2) _ < Sqr((zuobiao(0) - zuobiao1(UBound(zuobiao1) - 2)) ^ 2 + (zuobiao(1) - zuobiao1(UBound(zuobiao1) - 1)) ^ 2) And Sqr((zuobiao(0) - zuobiao1(0)) ^ 2 + (zuobiao(1) - zuobiao1(1)) ^ 2) _ < Sqr((zuobiao(UBound(zuobiao) - 2) - zuobiao1(0)) ^ 2 + (zuobiao(UBound(zuobiao) - 1) - zuobiao1(1)) ^ 2) Then For i = 0 To minn Step 3 zuobb(i) = zuobiao(minn - i - 2) zuobb(i + 1) = zuobiao(minn - i - 1) zuobb(i + 2) = zuobiao(minn - i) Next For i = 0 To minn1 zuobb(i + minn + 1) = zuobiao1(i) Next ElseIf Sqr((zuobiao(0) - zuobiao1(UBound(zuobiao1) - 2)) ^ 2 + (zuobiao(1) - zuobiao1(UBound(zuobiao1) - 1)) ^ 2) _ < Sqr((zuobiao(0) - zuobiao1(0)) ^ 2 + (zuobiao(1) - zuobiao1(1)) ^ 2) And Sqr((zuobiao(0) - zuobiao1(UBound(zuobiao1) - 2)) ^ 2 + (zuobiao(1) - zuobiao1(UBound(zuobiao1) - 1)) ^ 2) _ < Sqr((zuobiao(UBound(zuobiao) - 2) - zuobiao1(UBound(zuobiao1) - 2)) ^ 2 + (zuobiao(UBound(zuobiao) - 1) - zuobiao1(UBound(zuobiao1) - 1)) ^ 2) Then For i = 0 To minn Step 3 zuobb(i) = zuobiao(minn - i - 2) zuobb(i + 1) = zuobiao(minn - i - 1) zuobb(i + 2) = zuobiao(minn - i) Next For i = 0 To minn1 Step 3 zuobb(i + minn + 1) = zuobiao1(minn1 - i - 2) zuobb(i + minn + 2) = zuobiao1(minn1 - i - 1) zuobb(i + minn + 3) = zuobiao1(minn1 - i) Next End If ThisDrawing.ActiveLayer = ThisDrawing.Layers(mysel(0).Layer) mysel(0).Delete mysel(1).Delete ThisDrawing.ModelSpace.Add3DPoly zuobb ElseIf mysel(0).EntityType = 23 And mysel(1).EntityType = 23 Then zuobiao = mysel(0).Coordinates zuobiao1 = mysel(1).Coordinates minn = UBound(zuobiao) minn1 = UBound(zuobiao1) ReDim zuobb(0 To minn + minn1 + 1) As Double If Sqr((zuobiao(UBound(zuobiao) - 2) - zuobiao1(0)) ^ 2 + (zuobiao(UBound(zuobiao) - 1) - zuobiao1(1)) ^ 2) _ < Sqr((zuobiao(UBound(zuobiao) - 2) - zuobiao1(UBound(zuobiao1) - 2)) ^ 2 + (zuobiao(UBound(zuobiao) - 1) - zuobiao1(UBound(zuobiao1) - 1)) ^ 2) And Sqr((zuobiao(UBound(zuobiao) - 2) - zuobiao1(0)) ^ 2 + (zuobiao(UBound(zuobiao) - 1) - zuobiao1(1)) ^ 2) _ < Sqr((zuobiao(0) - zuobiao1(0)) ^ 2 + (zuobiao(1) - zuobiao1(1)) ^ 2) Then For i = 0 To minn zuobb(i) = zuobiao(i) Next For i = 0 To minn1 zuobb(i + minn + 1) = zuobiao1(i) Next ElseIf Sqr((zuobiao(UBound(zuobiao) - 2) - zuobiao1(UBound(zuobiao1) - 2)) ^ 2 + (zuobiao(UBound(zuobiao) - 1) - zuobiao1(UBound(zuobiao1) - 1)) ^ 2) _ < Sqr((zuobiao(UBound(zuobiao) - 2) - zuobiao1(0)) ^ 2 + (zuobiao(UBound(zuobiao) - 1) - zuobiao1(1)) ^ 2) And Sqr((zuobiao(UBound(zuobiao) - 2) - zuobiao1(UBound(zuobiao1) - 2)) ^ 2 + (zuobiao(UBound(zuobiao) - 1) - zuobiao1(UBound(zuobiao1) - 1)) ^ 2) _ < Sqr((zuobiao(0) - zuobiao1(UBound(zuobiao1) - 2)) ^ 2 + (zuobiao(1) - zuobiao1(UBound(zuobiao1) - 1)) ^ 2) Then For i = 0 To minn zuobb(i) = zuobiao(i) Next For i = 0 To minn1 Step 3 zuobb(i + minn + 1) = zuobiao1(minn1 - i - 2) zuobb(i + minn + 2) = zuobiao1(minn1 - i - 1) zuobb(i + minn + 3) = zuobiao1(minn1 - i) Next ElseIf Sqr((zuobiao(0) - zuobiao1(0)) ^ 2 + (zuobiao(1) - zuobiao1(1)) ^ 2) _ < Sqr((zuobiao(0) - zuobiao1(UBound(zuobiao1) - 2)) ^ 2 + (zuobiao(1) - zuobiao1(UBound(zuobiao1) - 1)) ^ 2) And Sqr((zuobiao(0) - zuobiao1(0)) ^ 2 + (zuobiao(1) - zuobiao1(1)) ^ 2) _ < Sqr((zuobiao(UBound(zuobiao) - 2) - zuobiao1(0)) ^ 2 + (zuobiao(UBound(zuobiao) - 1) - zuobiao1(1)) ^ 2) Then For i = 0 To minn Step 3 zuobb(i) = zuobiao(minn - i - 2) zuobb(i + 1) = zuobiao(minn - i - 1) zuobb(i + 2) = zuobiao(minn - i) Next For i = 0 To minn1 zuobb(i + minn + 1) = zuobiao1(i) Next ElseIf Sqr((zuobiao(0) - zuobiao1(UBound(zuobiao1) - 2)) ^ 2 + (zuobiao(1) - zuobiao1(UBound(zuobiao1) - 1)) ^ 2) _ < Sqr((zuobiao(0) - zuobiao1(0)) ^ 2 + (zuobiao(1) - zuobiao1(1)) ^ 2) And Sqr((zuobiao(0) - zuobiao1(UBound(zuobiao1) - 2)) ^ 2 + (zuobiao(1) - zuobiao1(UBound(zuobiao1) - 1)) ^ 2) _ < Sqr((zuobiao(UBound(zuobiao) - 2) - zuobiao1(UBound(zuobiao1) - 2)) ^ 2 + (zuobiao(UBound(zuobiao) - 1) - zuobiao1(UBound(zuobiao1) - 1)) ^ 2) Then For i = 0 To minn Step 3 zuobb(i) = zuobiao(minn - i - 2) zuobb(i + 1) = zuobiao(minn - i - 1) zuobb(i + 2) = zuobiao(minn - i) Next For i = 0 To minn1 Step 3 zuobb(i + minn + 1) = zuobiao1(minn1 - i - 2) zuobb(i + minn + 2) = zuobiao1(minn1 - i - 1) zuobb(i + minn + 3) = zuobiao1(minn1 - i) Next End If ThisDrawing.ActiveLayer = ThisDrawing.Layers(mysel(0).Layer) Set xuln = ThisDrawing.ModelSpace.AddPolyline(zuobb) xuln.Thickness = mysel(0).Thickness xuln.ConstantWidth = mysel(0).ConstantWidth xuln.Linetype = mysel(0).Linetype xuln.color = mysel(0).color xuln.Lineweight = mysel(0).Lineweight mysel(0).Delete mysel(1).Delete End If Else MsgBox "此方法限于两根线" End If If mysel.count <> 0 Then mysel.Delete End If we: End Sub |