Get Coordinate Values

Anonymous
Anonymous

I have written a macro using Visual Basic that draws consecutive lines and arcs based upon entries from the user (boundary description). Immediately after a line has been drawn, how do I retrieve the end point coordinates of that line (xyz) and save it as a variable to be used later in the macro?

 The user enters a bearing and distance for each segment and the macro is set up to keyin the bearing and distance (i.e. "di=1000,N 45^12"10' E") using the "Place Line Constrained" command.  Is there a quick way to retrieve the end coordinates of each line as they are drafted in Microstation?

Parents
  • Hello jdawg9996,
    You can use the following to get a handle to the last valid element added
    to the file

    dim oElement as Element
    Set oElement = ActiveModelReference.GraphicalElementCache.GetLastValidElement

    Then you can check if the element is a line, arc, etc and get the last point
    properties
    Cast the oElement to the correct element type line, arc etc
    Then use the LineElement.EndPoint property to get the last point.




    > I have written a macro using Visual Basic that draws consecutive lines
    > and arcs based upon entries from the user (boundary description).
    > Immediately after a line has been drawn, how do I retrieve the end
    > point coordinates of that line (xyz) and save it as a variable to be
    > used later in the macro?
    >
    > The user enters a bearing and distance for each segment and the
    > macro is set up to keyin the bearing and distance (i.e. "di=1000,N
    > 45^12"10' E") using the "Place Line Constrained" command. Is there a
    > quick way to retrieve the end coordinates of each line as they are
    > drafted in Microstation?
    >
  • Thank you mwrbentley!

    I was able to extract all of the information from the previous element using your recommendation. However, I'm struggling to extract the endpoint from this information.  Two questions for you:

    1) How do I cast the oElement as a line?

    2) To get the last point do I just do the following:  Lastpoint = LineElement.EndPoint

    Here is a sample of what I have:

    Dim startPoint As Point3d
    Dim point As Point3d, point2 As Point3d

    Dim LastElement as Element

    Dim BD_Entry As Variant

    Dim LastPoint as Variant

    CadInputQueue.SendKeyin "place line constrained"

    point.X = startPoint.X
    point.Y = startPoint.Y
    point.Z = startPoint.Z
    CadInputQueue.SendDataPoint point, 1

    BD_Entry = "DI=3000,n 45^12'12" & Chr$(34) & "W"
    CadInputQueue.SendKeyin BD_Entry

    Set LastElement = ActiveModelReference.GraphicalElementCache.GetLastValidElement
    Lastpoint = LineElement.EndPoint

    KeyInEntry = "Choose last"
    CadInputQueue.SendKeyin KeyInEntry
    Lastpoint = Object.AsLineElement.EndPoint

    Thanks again!

  • jdawg:
    1. How do I cast the oElement as a line?
    2. To get the last point do I just do the following: Lastpoint = LineElement.EndPoint
    1. How do I cast the oElement as a line: use the As keyword
      • Dim oLine As LineElement
        Set oLine = oElement As LineElement
      • or use something like With oElement As LineElement ... End With
    2. Lastpoint = LineElement.EndPoint: or use the AsVertexList property to get all vertices

    Regards, Jon Summers
    LA Solutions

     
    Regards, Jon Summers
    LA Solutions

  • Thank you Jon!

    When I type "Set oLine = oElement As LineElement" I get an error reading, "Compile Error: Expected end of statement" and it highlights "As".  Am I missing something obvious?


    I haven't been able to check part 2 because I'm still struggling with Part 1.

     This is what I have thus far:

    Dim oElement As Element
    Dim oLine As LineElement

    CadInputQueue.SendKeyin "place line constrained"

    point.X = startPoint.X
    point.Y = startPoint.Y
    point.Z = startPoint.Z
    CadInputQueue.SendDataPoint point, 1

    BD_Entry = "DI=3000,n 45^12'12" & Chr$(34) & "W"
    CadInputQueue.SendKeyin BD_Entry

    Set oElement = ActiveModelReference.GraphicalElementCache.GetLastValidElement
    Set oLine = oElement As LineElement

    Lastpoint = LineElement.EndPoint

    End Sub


    Any thoughts?

  • jdawg:

    When I type Set oLine = oElement As LineElement I get an error reading, "Compile Error: Expected end of statement" and it highlights "As".  Am I missing something obvious?

    My typo: there is no space after As: use oElement.AsLineElement

    Element is an abstract concept — all elements are instances of class Element. You can cast an Element to any concrete class, such as a LineElement, by using the AsXxxElement property.

    Regards, Jon Summers
    LA Solutions

     
    Regards, Jon Summers
    LA Solutions

  • Works like a charm!!!


    Thanks again for your help!

Reply Children
No Data