India CAD - Indian AutoCAD Community Forum Index
  Register FAQ Search Memberlist Usergroups Profile Log in to check your private messages Log in 
Log in to check your private messages  ·  fChat
Reversing a Polyline

 
Post new topic   Reply to topic    India CAD - Indian AutoCAD Community Forum Index -> VBA
View previous topic :: View next topic  
Author Message
Indiacad
Admin


Joined: 26 Jul 2006
Posts: 19

PostPosted: Wed Feb 11, 2009 10:08 am    Post subject: Reversing a Polyline Reply with quote

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
Back to top
View user's profile Send private message Send e-mail Yahoo Messenger
Display posts from previous:   
Post new topic   Reply to topic    India CAD - Indian AutoCAD Community Forum Index -> VBA All times are GMT + 5.5 Hours


Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum