Is there a direct way to select an object by its name in C++ ?
Hi @inetbob,
You can select objects by their user-defined name like this:
CRhinoCommand::result CCommandTest::RunCommand(const CRhinoCommandContext& context)
{
CRhinoGetString gs;
gs.SetCommandPrompt(L"Object name to select");
gs.GetLiteralString();
if (gs.CommandResult() != CRhinoCommand::success)
return gs.CommandResult();
ON_wString name = gs.String();
name.TrimLeftAndRight();
if (name.IsEmpty())
return CRhinoCommand::nothing;
CRhinoObjectIterator it(CRhinoObjectIterator::normal_objects, CRhinoObjectIterator::active_and_reference_objects);
const CRhinoObject* obj = nullptr;
for (obj = it.First(); nullptr != obj; obj = it.Next())
{
if (!obj->Attributes().m_name.IsEmpty())
{
if (obj->Attributes().m_name.WildCardMatchNoCase(name))
obj->Select(true, true, true);
}
}
context.m_doc.Redraw();
return CRhinoCommand::success;
}
– Dale
Thanks Dale. This is the info I needed. -Bob