Indiacad Admin
Joined: 26 Jul 2006 Posts: 19
|
Posted: Wed Feb 11, 2009 10:08 am Post subject: Reversing a Polyline |
|
|
I was browsing through my old collections and found this. A very useful routine, for those who deals with Pipe lines, where flow direction is utmost important. This routine reverses the direction of a selected 2dpolyline.
| Code: | Option Explicit
'Option Compare Binary
Public Sub RevPoly()
Dim PlSet As AcadSelectionSet, i As Integer, Pl As AcadPolyline, Cord As Variant
Dim PlCode(0) As Integer, PlVal(0) As Variant
Dim GpCode As Variant, GpVal As Variant
Dim NewCord As Variant
PlCode(0) = 0: PlVal(0) = "*Polyline"
GpCode = PlCode: GpVal = PlVal
Set PlSet = CreateSel()
PlSet.SelectOnScreen GpCode, GpVal
For i = 0 To PlSet.Count - 1
Cord = PlSet(i).Coordinates
Rev PlSet(i)
Next i
End Sub
Public Function Rev(Pline As AcadEntity) ' As AcadPolyline
Dim CrDs As Variant, Ncord() As Double, i As Integer, j As Integer, Stp As Integer
j = 0
If Pline.ObjectName Like "*3dPolyline" Then
Stp = 3
ElseIf Pline.ObjectName Like "*DbPolyline" Then
Stp = 2
Else
Stp = 0
End If
If Stp <> 0 Then
CrDs = Pline.Coordinates
ReDim Ncord(UBound(CrDs)) As Double
For i = UBound(CrDs) - (Stp - 1) To 0 Step -Stp
Ncord(j) = CrDs(i)
Ncord(j + 1) = CrDs(i + 1)
If Stp = 3 Then
Ncord(j + 2) = CrDs(i + 2)
End If
j = j + Stp
Next i
Pline.Coordinates = Ncord
End If
'Set Rev = Pline
End Function
Public Function CreateSel(Optional Sname As String = "SS") As AcadSelectionSet
On Error Resume Next
Dim Acsel As AcadSelectionSet
Set Acsel = ThisDrawing.SelectionSets(Sname)
Acsel.Clear
If Err Then
Set Acsel = ThisDrawing.SelectionSets.Add(Sname)
End If
Acsel.Clear
Set CreateSel = Acsel
End Function |
REviews and comments are welcome |
|