TheSwamp

Code Red => VB(A) => Topic started by: ibv-survey on September 11, 2007, 07:03:32 AM

Title: Updating a line
Post by: ibv-survey on September 11, 2007, 07:03:32 AM
I have a vba module that allows the user to pick a line. It then swaps the endpoints to reverse the line's direction. But when I update the line the direction in the graphic window is not reversed although in VBA Manager it is.  I put an extra line in to change the colour and that works when the line is updated.  The same problem occurs with a polyline module that I'm working on too.
Any ideas?
Title: Re: Updating a line
Post by: Arizona on September 11, 2007, 07:53:06 AM
Can you post some of your code? :-)
Title: Re: Updating a line
Post by: ibv-survey on September 11, 2007, 09:49:05 AM
It looks like this:

Code: [Select]
Attribute VB_Name = "RichtungAendern"
Option Explicit

'Attribute VB_Name = "Richtung Ändern"
'Reverse line direction - German Version

Sub RichtungAendern()

    Dim objLineEnt As AcadEntity
    Dim txtEnt As AcadText
    Dim linEnt As AcadLine
    Dim orgLineAngle As Double
    Dim varSelPoint As Variant
    Dim linAngle As Double
    Dim PI As Double
    Dim varLineStart As Variant
    Dim varLineEnd As Variant
    Dim varTemp As Variant

    'initialise variables
    varSelPoint = 0#


    'get a line
    Do
        On Error Resume Next
START:
        ThisDrawing.Utility.GetEntity objLineEnt, varSelPoint, "eine Linie wählen"

            Dim entName As String
            entName = objLineEnt.ObjectName
       

        'only process if a line was selected
        If objLineEnt.ObjectName = "AcDbLine" Then

            varLineStart = objLineEnt.StartPoint
            varLineEnd = objLineEnt.EndPoint
            varTemp = varLineStart
            varLineStart = varLineEnd
            varLineEnd = varTemp
            objLineEnt.color = acRed
            objLineEnt.Update

        Else    'inform user that no line was selected
            MsgBox ("das war keine Linie!" & vbCr & "Bitte eine Linie wählen")
            GoTo START
        End If

    Loop    'go back and get another line

End Sub

_________________________________________________

It updates the line colour to red but does not swap the end points.
Title: Re: Updating a line
Post by: Keith™ on September 11, 2007, 10:02:16 AM
Code: [Select]
            varLineStart = objLineEnt.StartPoint
            varLineEnd = objLineEnt.EndPoint
            objLineEnt.StartPoint = varLineEnd
            objLineEnt.EndPoint = varLineStart
            objLineEnt.color = acRed
            objLineEnt.Update
Title: Re: Updating a line
Post by: ibv-survey on September 11, 2007, 10:41:55 AM
Hi Keith,

That was it.  Thanks.

I'll now have a go at the polyline.
Title: Re: Updating a line
Post by: Bob Wahr on October 15, 2007, 01:45:07 PM
PLINE is not going to be even close to the same function.  For plines, you will have to get the list of coordinates, reverse the list, draw in a new pline and delete the old pline.  It will also have to be different for ACADLWPolylines and ACADPolylines.  And that's assuming that every polyline ever selected will be made of straight segments.  If it has any curves, the fun will REALLY start.
Title: Re: Updating a line
Post by: Bryco on October 15, 2007, 07:54:46 PM
Bob, great to hear from you again.
Now I know your statement is true for acad 2000
but on 2008 try this
Code: [Select]
Sub SwapEnds(P As AcadLWPolyline)

    Dim P As AcadLWPolyline
    Dim C1, C2
    C1 = P.Coordinate(1)
    C2 = P.Coordinate(0)
    P.Coordinate(0) = C1
    P.Coordinate(1) = C2

End Sub
it swaps the ends on a line LWpline