Extracting a line's coordinates with VBA error

Hello,


I am trying to extract the coordinates of a line's start and end points which I have selected with my VBA macro. I tried using for example with just the x-coordinate:

this.GetElement().Segments[0].Start.X

or

this.GetElement().StartPoint.X

but none of those work. I get the error "Object required". I am using Microstation V8 2010 version. 

The purpose of the code is to find a line with select by attributes, get the coordinates of the line's start and end point to be able to place a line somewhere along the line. Can anyone help me with this? 

Here is the code so far:

Sub Macro1()
Dim startPoint As Point3d
Dim point As Point3d, point2 As Point3d
Dim lngTemp As Long
Dim StartX

' Start a command
CadInputQueue.SendCommand "MDL SILENTLOAD SELECTBY dialog"

CadInputQueue.SendCommand "SELECTBY EXECUTE"

Dim modalHandler As New Macro1ModalHandler
AddModalDialogEventsHandler modalHandler

' The following statement opens modal dialog "Alert"

CadInputQueue.SendCommand "SELECTBY EXECUTE"

RemoveModalDialogEventsHandler modalHandler
CommandState.StartDefaultCommand

this.GetElement().startPoint.X

' Select place point
CadInputQueue.SendCommand "PLACE POINT"

End Sub

Thanks in advance

  • There is a MicroStation Programming forum that is more appropriate for this type of question, but I'll respond here...

    First - Once you have the line elements selected you will need this kind of structure to extract the end points.

    Sub GetSelectedLineElements()
        Dim ee As ElementEnumerator
        Dim elLine As LineElement
        Dim ptStart As Point3d
        Dim ptEnd As Point3d
        
        If ActiveModelReference.AnyElementsSelected Then
            Set ee = ActiveModelReference.GetSelectedElements
            Do While ee.MoveNext
                If ee.Current.IsLineElement Then
                    Set elLine = ee.Current.AsLineElement
                    ptStart = elLine.StartPoint
                    ptEnd = elLine.EndPoint
                End If
            Loop
        End If
    End Sub

    Second - Get rid of the call to the modal Select By Attributes dialog. Working with modal MicroStation dialogs in VBA should be avoided. You can use the ElementScanCriteria object to replace it like so...

    Sub UseScanCriteria()
        Dim es As New ElementScanCriteria
        Dim ee As ElementEnumerator
        Dim elLine As LineElement
        Dim ptStart As Point3d
        Dim ptEnd As Point3d
        
        With es
            .ExcludeAllTypes
            .IncludeType msdElementTypeLine
        End If
        
        Set ee = ActiveModelReference.Scan(es)
        Do While ee.MoveNext
            If ee.Current.IsLineElement Then
                Set elLine = ee.Current.AsLineElement
                ptStart = elLine.StartPoint
                ptEnd = elLine.EndPoint
            End If
        Loop
    End Sub
    

    You can further filter what attributes you want to scan for, look for examples in the MicroStation VBA help.

    Rod Wing
    Senior Systems Analyst

    Answer Verified By: Acke Man 

  • Post questions about VBA to the Programming Forum.  You can move your post using the More=>Move button.

     
    Regards, Jon Summers
    LA Solutions