Eplan Platform API
EPLAN API / User Guide / API Higher Electrotechnical services / Accessing selected objects
In This Topic
    Accessing selected objects
    In This Topic

    The advantage of an add-in is that it is called from within the context of a running EPLAN version and can access the currently selected objects. This can be achieved by using the SelectionSet class. The class provides a number of methods for retrieving a list of items currently selected by the user. 

    You can either get the project the user is currently working on using the  SelectionSet::GetCurrentProject  method, or you can get the currently selected page(s) using the  SelectionSet::GetSelectedPages  method. Depending on whether the graphical editor or the page overview dialog currently has the focus, one or more pages can be selected. 

    Most importantly, you can get any set of objects selected from any focused (non-modal) dialog through the  SelectionSet.Selection  property. The objects are returned by the function as an array of StorableObjects. You can loop over the array and determine the types (and any other information) about the objects. 

    The following example shows how to access the selection. 

    SelectionSet selectionSet = new SelectionSet();
    StorableObject[] storableObjects = selectionSet.Selection;
    if (storableObjects.Length == 0)
    {
        Console.WriteLine("No current selection!");
    }
    else
    {
        foreach(StorableObject so in storableObjects)
        {
            if(so is Function)
               Console.WriteLine(" StorableObject is a function: " + ((Function) so).Name);
            else
                Console.WriteLine(" StorableObject: " + so.ToString());
        }
    }
    
    Dim selectionSet As New SelectionSet()
    Dim storableObjects As StorableObject() = selectionSet.Selection
    If storableObjects.Length = 0 Then
       Console.WriteLine("No current selection!")
    Else
       Dim so As StorableObject
       For Each so In  storableObjects
          If TypeOf so Is Function Then
             Console.WriteLine((" StorableObject is a function: " + CType(so, Function).Name))
          Else
             Console.WriteLine((" StorableObject: " + so.ToString()))
          End If
       Next so
    End If