TheSwamp

Code Red => VB(A) => Topic started by: DaveW on June 21, 2006, 10:19:51 PM

Title: Reverse Plines
Post by: DaveW on June 21, 2006, 10:19:51 PM
I got these from Malcom Fernandez. He was a great help and loves to share.

One for open and one is for closed.


Code: [Select]

Private Sub reverse_pline(polyEnt As AcadLWPolyline)
'this does a closed polyline


        Dim idx As Integer
        Dim numPts As Integer
        Dim numBulge As Integer
        Dim bulge As Double
'set an array to store the coordinates of the pline
        Dim newcoord() As Double
        numPts = UBound(polyEnt.Coordinates) - 1 'was -1
        ReDim newcoord(numPts + 1) 'was 1
'set an array to store the bludge factor for each segment
        Dim newbulge() As Double
        numBulge = (((numPts)) / 2)  'was -3)/2
        ReDim newbulge(numBulge)
'loop through the vertices of the pline and save x,y in reverse order
        For idx = 0 To numPts Step 2
            newcoord(numPts - idx) = polyEnt.Coordinates(idx)
            newcoord(numPts - idx + 1) = polyEnt.Coordinates(idx + 1) 'was +1 in 2 places
        Next idx
'loop through the bulge factors and save in reverse order
        For idx = 0 To numBulge
          If idx <> numBulge Then
            newbulge(numBulge - idx) = polyEnt.GetBulge(idx) * -1
           
            Else
           
            newbulge(0) = polyEnt.GetBulge(idx) * -1
           
          End If
        Next idx
       
'reverse the original pline
        polyEnt.Coordinates = newcoord

       
        For idx = 0 To numBulge
       
          If idx = 0 Then
            polyEnt.SetBulge (numBulge), newbulge(idx)
          Else
            polyEnt.SetBulge (idx - 1), newbulge(idx)
          End If
           
        Next idx
       
        polyEnt.Update

End Sub


Code: [Select]
Private Sub revPline(polyEnt As AcadLWPolyline)
'this does an open polyline
        Dim idx As Integer
        Dim numPts As Integer
        Dim numBulge As Integer
        Dim bulge As Double
'set an array to store the coordinates of the pline
        Dim newcoord() As Double
        numPts = UBound(polyEnt.Coordinates) - 1
        ReDim newcoord(numPts + 1)
'set an array to store the bludge factor for each segment
        Dim newbulge() As Double

        numBulge = ((numPts - 3) / 2)
       
        If ((UBound(polyEnt.Coordinates) + 1) / 2) Mod 2 = 0 Then
           GoTo myout
        Else
           numBulge = numBulge + 1
        End If
myout:
        ReDim newbulge(numBulge)
'loop through the vertices of the pline and save x,y in reverse order
        For idx = 0 To numPts Step 2
            newcoord(numPts - idx) = polyEnt.Coordinates(idx)
            newcoord(numPts - idx + 1) = polyEnt.Coordinates(idx + 1)
        Next idx
'loop through the bulge factors and save in reverse order
        For idx = 0 To numBulge
            newbulge(numBulge - idx) = polyEnt.GetBulge(idx) * -1
        Next idx
       
'reverse the original pline
        polyEnt.Coordinates = newcoord

       
        For idx = 0 To numBulge
            polyEnt.SetBulge idx, newbulge(idx)
        Next idx
       
        polyEnt.Update
End Sub
Title: Re: Reverse Plines
Post by: ElpanovEvgeniy on June 22, 2006, 12:28:43 AM
Your program does not keep variable width of a segment...
Look my program on LISP.

http://www.theswamp.org/index.php?topic=8878.msg114590#msg114590
Title: Re: Reverse Plines
Post by: DaveW on June 23, 2006, 09:42:48 AM
Thanks anyway, but I do not read lisp. I would not have any idea what you are doing there.

It would not be that much work to add that here, using the budge arrays as a starting point.