我已经为此工作了2年,它的99.5%,其中一些3D有点棘手。我为cnc画了很多,所以我不想要额外的顶点或线。这应该删除坏蛋。至于应该加入什么,你必须做出决定。我不知道我是否应该先把所有的线都做成多边形。我很确定我可以在这里消除一些步骤,但是越来越难看到树木的觅食。
- Option Explicit
- Declare Function GetCursor Lib "user32" () As Long
- Public Declare Function GetAsyncKeyState Lib "user32" _
- (ByVal vKey As Long) As Integer
- Public Declare Sub CopyMemory Lib "kernel32" _
- Alias "RtlMoveMemory" _
- (dest As Any, source As Any, ByVal Length As Long) 'AlmostEqual
- Private DeleteCol As Collection
- Private StartEndCol As Collection
- Private SlopeCol As Collection
- Private CoordList As Collection
- Private Const PolyClosedFudge As Double = 0.005
- 'If the first coordinate and last coordinate are within this distance
- 'The poly will be closed.
- Const Pi As Double = 3.14159265358979
- Public Property Get CurrentSpace() As AcadBlock
- If ThisDrawing.GetVariable("CVPORT") = 1 Then
- Set CurrentSpace = ThisDrawing.PaperSpace
- Else
- Set CurrentSpace = ThisDrawing.ModelSpace
- End If
- End Property
- 'Aims
- '1) To select a group of lines,arcs and polys
- 'and create clean polys w/ no double ups
- 'or double points.
- '2) Delete unnecessary geometry
- 'Some will want to add a layer control here.
- '3) Note 2d and 3dpolys are not included
- '4) I have used line formulas rather than polar angles
- 'hoping that it will be faster.
- Sub VBAPLJoin()
- 'On Error GoTo Err_Control
- Dim oLine As AcadLine
- Dim LineCol As New Collection
- Dim oPline As AcadLWPolyline
- Dim CoordsCt As Integer
- Dim oArc As AcadArc
- Dim oSSets As AcadSelectionSets
- Dim ss As AcadSelectionSet
- Dim FilterType(6) As Integer
- Dim FilterData(6) As Variant
- Dim i As Integer, j As Integer, k As Integer
- Dim intNotParallel As Integer
- Dim PtsCount As Integer, Count As Integer
- Dim StartPt As Variant, EndPt As Variant
- Dim StartP(2) As Double, EndP(2) As Double
- Dim Pt As Variant
- Dim pts() As Double
- Dim SE(4) As Variant
- Dim obj(0) As AcadEntity
- Dim M As Double, OrigY As Double
- Dim UcsNormal As Variant, N As Variant
- Dim blnRemove As Boolean
- Dim dblElev As Double
- Dim strlayer As String
- Dim util As AcadUtility
- PtsCount = 1
- Set util = ThisDrawing.Utility
- Set StartEndCol = New Collection
-
- 'Stage 1 Create the selectionset
- Set oSSets = ThisDrawing.SelectionSets
- For Each ss In oSSets
- If ss.Name = "SS" Then
- ss.Delete
- Exit For
- End If
- Next
- Set ss = oSSets.Add("SS")
-
-
- FilterType(0) = 0: FilterData(0) = "Line,Arc,LWPolyline"
- FilterType(1) = -4: FilterData(1) = ""
- FilterType(6) = -4: FilterData(6) = "NOT>"
-
- Do ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
- ss.SelectOnScreen FilterType:=FilterType, FilterData:=FilterData
- Loop Until GetCursor = 0
-
- If ss.Count > 500 Then
- MsgBox "You have selected " & ss.Count & " objects. Please select less :"
- Exit Sub
- End If
- If ss.Count = 0 Then
- Set ss = Nothing
- ''''''''''''MsgBox "Nothing selected."
- Exit Sub
- End If
- If ss.Count = 1 Then
- If TypeOf ss(0) Is AcadLWPolyline Then
- Set oPline = ss(0)
- If UBound(oPline.Coordinates) = 3 Then
- Exit Sub
- End If
- End If
- End If
- UcsNormal = CurrentUcsNormal
- 'We're using the SS set index to keep track of the objects
- 'So first pass is just to clean up the set
- 'From then on the order wont change
-
- 'Stage 2- delete zero length ents, remove non applicable ents
- For i = ss.Count - 1 To 0 Step -1
- If TypeOf ss(i) Is AcadLine Then
- Set oLine = ss(i)
- If oLine.Length 0 Then
- CheckLines LineCol 'Sub checks for equal, overlapping lines
- End If
- If ss.Count = 0 Then 'items may have been removed
- Exit Sub
- End If
- If intNotParallel = 1 Then
- MsgBox intNotParallel & " object was not parallel to the current UCS."
- ElseIf intNotParallel > 1 Then
- MsgBox intNotParallel & " objects were not parallel to the current UCS."
- End If
|