Overview
A model object can either be selected or not. The ISelection interface provides methods to query the IDs of selected objects and select sets of objects by their IDs.
How to select objects
For example, to select all walls in the scene:
C++
Renga::IApplicationPtr pApplication = Renga::CreateApplication();
if (pApplication == nullptr)
return;
Renga::IProjectPtr pProject = pApplication->GetProject();
if (pProject == nullptr)
return;
Renga::IModelPtr pModel = pProject->GetModel();
Renga::IModelObjectCollectionPtr pModelObjectCollection = pModel->GetObjects();
ATL::CComSafeArray<int> modelObjectIds = pModelObjectCollection->GetIds();
std::vector<int> wallObjectIds;
for (int i = 0; i < modelObjectIds.GetCount(); ++i)
{
int objectId = modelObjectIds.GetAt(i);
Renga::IModelObjectPtr pModelObject = pModelObjectCollection->GetById(objectId);
if (pModelObject == nullptr)
continue;
continue;
wallObjectIds.push_back(objectId);
}
CComSafeArray<int> wallObjectIdsSafeArray(wallObjectIds.size());
for (int i = 0; i < wallObjectIds.size(); ++i)
wallObjectIdsSafeArray.SetAt(i, wallObjectIds[i]);
Renga::ISelectionPtr pSelection = pApplication->GetSelection();
pSelection->SetSelectedObjects(wallObjectIdsSafeArray);
const GUID Wall
Wall object type.
Definition EntityTypes.h:470
C#
Renga.IApplication application = new Renga.Application();
Renga.IProject project = application.Project;
if (project == null)
return;
Renga.IModel model = project.Model;
Renga.IModelObjectCollection modelObjectCollection = model.GetObjects();
int[] modelObjectIds = (int[])modelObjectCollection.GetIds();
var wallObjectIds = new List<int>();
foreach (int objectId in modelObjectIds)
{
Renga.IModelObject modelObject = modelObjectCollection.GetById(objectId);
if (modelObject == null)
continue;
if (modelObject.ObjectType != Renga.EntityTypes.Wall)
continue;
wallObjectIds.Add(objectId);
}
Renga.ISelection selection = application.Selection;
selection.SetSelectedObjects(wallObjectIds.ToArray());
How to handle selection changes
C++ and C# SDK provide the SelectionEventSource helper class for handling selection events. For more information see this page.
For example, to handle changes in selection and do something with selected objects when the selection changes:
C++
Renga::ISelectionPtr pSelection = pApp->Selection;
m_pSelectionEventSource = std::make_unique<Renga::SelectionEventSource>(pSelection);
m_pSelectionEventSource->SubscribeModelSelectionChanged([] { });
C#
Renga.ISelection selection = app.Selection;
m_selectionEventSource = new Renga.SelectionEventSource(selection);
m_selectionEventSource.ModelSelectionChanged += () => { };
See also
Related samples