Author Topic: Updating a line  (Read 2119 times)

0 Members and 1 Guest are viewing this topic.

ibv-survey

  • Guest
Updating a line
« 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?

Arizona

  • Guest
Re: Updating a line
« Reply #1 on: September 11, 2007, 07:53:06 AM »
Can you post some of your code? :-)

ibv-survey

  • Guest
Re: Updating a line
« Reply #2 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.
« Last Edit: September 11, 2007, 11:10:47 AM by Maverick® »

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: Updating a line
« Reply #3 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
« Last Edit: September 11, 2007, 10:03:50 AM by Keith™ »
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

ibv-survey

  • Guest
Re: Updating a line
« Reply #4 on: September 11, 2007, 10:41:55 AM »
Hi Keith,

That was it.  Thanks.

I'll now have a go at the polyline.

Bob Wahr

  • Guest
Re: Updating a line
« Reply #5 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.

Bryco

  • Water Moccasin
  • Posts: 1883
Re: Updating a line
« Reply #6 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