Obtaining Element ID from Active Element

Dear all,

I am trying to write a short BASIC macro that will extract element IDs from the active (i.e. selected) element.

It will only pertain to a singular element, i.e. one element will be selected and its ID will be stored in a variable.

However, I do not know what Microstation use as a placeholder for any selected elements, if it does that at all. To use an equivalent scenario in Excel, one can manipulate worksheets and cells by using their respective placeholders, "ActiveSheet" and "ActiveCell".

I worked out that said element (say, a rectangle) will be created on its own layer, which can be isolated and selected via key-ins. However, I would like to do something as in the following mock-code:

-----------------------------------------------------

Dim oEL as Element

Dim oID as DLong

oEL = ActiveElement

oID = oEL.id

-----------------------------------------------------

Please advice, thank you.

Parents
  • To be most productive in MicroStation VBA consider learning a couple keystrokes to help make your learning MicroStation VBA easier.

    1. Open the Microsoft VBA Editor (Alt + F11)
    2. Open the Microsoft VBA Object Browser (F2)
    3. Search in the Object Browser for keywords of interest
    4. Open help for a specific item (Select an item, then press F1)
    5. Search the open help file (Click the Search Tab, then use wildcard and boolean search operators.  e.g. *linear* AND *element* AND *properties*
    6. TIP: Always look to the top of each VBA help page for an "Example" link providing code snips to quickly test functionality.

    VBA programs process selected elements using a Model Reference (like separate sheets in a book), so code to process selected elements in the ActiveModelReference would look somewhat like this:

    Option Explicit
    
    Sub ProcessSelectedElements()
    
        Dim oModel As ModelReference: Set oModel = ActiveModelReference
        Dim oEE As ElementEnumerator: Set oEE = oModel.GetSelectedElements()
        Dim oEl As Element
        Dim sMessage As String
        Do While oEE.MoveNext
            If sMessage <> "" Then
                sMessage = sMessage & ", " & DLongToString(oEE.Current.ID)
            Else
                sMessage = DLongToString(oEE.Current.ID)
            End If
        Loop
        MsgBox sMessage, vbOKOnly, "Selected Element IDs"
    
    End Sub

    HTH,
    Bob



    Answer Verified By: Christopher Cheong 

Reply
  • To be most productive in MicroStation VBA consider learning a couple keystrokes to help make your learning MicroStation VBA easier.

    1. Open the Microsoft VBA Editor (Alt + F11)
    2. Open the Microsoft VBA Object Browser (F2)
    3. Search in the Object Browser for keywords of interest
    4. Open help for a specific item (Select an item, then press F1)
    5. Search the open help file (Click the Search Tab, then use wildcard and boolean search operators.  e.g. *linear* AND *element* AND *properties*
    6. TIP: Always look to the top of each VBA help page for an "Example" link providing code snips to quickly test functionality.

    VBA programs process selected elements using a Model Reference (like separate sheets in a book), so code to process selected elements in the ActiveModelReference would look somewhat like this:

    Option Explicit
    
    Sub ProcessSelectedElements()
    
        Dim oModel As ModelReference: Set oModel = ActiveModelReference
        Dim oEE As ElementEnumerator: Set oEE = oModel.GetSelectedElements()
        Dim oEl As Element
        Dim sMessage As String
        Do While oEE.MoveNext
            If sMessage <> "" Then
                sMessage = sMessage & ", " & DLongToString(oEE.Current.ID)
            Else
                sMessage = DLongToString(oEE.Current.ID)
            End If
        Loop
        MsgBox sMessage, vbOKOnly, "Selected Element IDs"
    
    End Sub

    HTH,
    Bob



    Answer Verified By: Christopher Cheong 

Children