How can I select an object programmatically?

samMXU5E
Explorer

How can I select an object programmatically?

samMXU5E
Explorer
Explorer

Does anyone know how to select an object without having the user click on it? I am working on a script that generates a BRepBody. I want to invoke the 3D Print command and have my BRepBody to be pre-selected so the user does not have to click on it.

0 Likes
Reply
679 Views
1 Reply
Reply (1)

samMXU5E
Explorer
Explorer

Never mind. I solved the problem by using the following code:

 

app = Application::get();
if (!app)
  return false;

 

ui = app->userInterface();
if (!ui)
  return false;

 

Ptr<Product> product = app->activeProduct();
if (!product)
  return;

 

Ptr<Design> design = product;
if (!design)
  return;

 

Ptr<Component> rootComp = design->rootComponent();
if (!rootComp)
  return;

 

Ptr<BRepBodies> bodies = rootComp->bRepBodies();
if (!bodies)
  return;

 

Ptr<BRepBody> body1 = bodies->item(0);
if (!body1)
  return;

 

Ptr<Selections> selections = ui->activeSelections();
selections->add(body1);

 

1 Like