Is the "Design" workspace active when you run your program? If you have something else, like MANUFACTURE, SIMULATION or DRAWING active when your program runs then it will fail because the active product isn't a Design object. Here's some simple code I used to test it. It first reports what the active product is. Then it gets the active product, assuming it is a Design. If it's not then that call will fail. It then does some work using the returned Design object.
Ptr<Application> _app;
Ptr<UserInterface> _ui;
extern "C" XI_EXPORT bool run(const char* context)
{
_app = Application::get();
if (!_app)
return false;
_ui = _app->userInterface();
if (!_ui)
return false;
_ui->messageBox("Active product type: " + _app->activeProduct()->productType());
Ptr<Design> des = _app->activeProduct();
Ptr<Component> root = des->rootComponent();
_ui->messageBox("Sketch Count: " + std::to_string(root->sketches()->count()));
return true;
}
---------------------------------------------------------------
Brian EkinsInventor and Fusion 360 API Expert
Website/Blog:
https://EkinsSolutions.com