5.2. How to get all the selected objects of a given classΒΆ

In this example we will show how to get all the selected objects of the class Channel.

First, perform the import statements:

from OrsLibraries.workingcontext import WorkingContext
from ORSModel import Channel
from ORSModel import OrsSelectedObjects

Then, request the selected objects of the class Channel, kept in the entity named with the tag OrsSelectedObjects:

allSelectedDatasets = WorkingContext.getEntitiesOfClass(aPluginInstance, OrsSelectedObjects, Channel.getClassNameStatic())

where aPluginInstance is a plugin instance. This plugin instance is used to determine from what context this information should be taken from (since there is a dictionary of entities per context); the information is taken from the context in which this plugin instance belongs. However, in the situation where there is only one context or the request is made for the current context, None can be used instead of aPluginInstance:

allSelectedDatasets = WorkingContext.getEntitiesOfClass(None, OrsSelectedObjects, Channel.getClassNameStatic())

allSelectedDatasets is a Python list of the selected objects (as contained in the dictionary of entities kept by WorkingContext).