variable 'design' is returning null C++ add-in

DWhiteley
Advisor

variable 'design' is returning null C++ add-in

DWhiteley
Advisor
Advisor

Sample API is returning NULL for design:


// get active design
Ptr<Product> product = app->activeProduct();
if (!product)
return false;

 

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

 

Any help would be appreciated.

 

Dave Whiteley

0 Likes
Reply
Accepted solutions (1)
295 Views
1 Reply
Reply (1)

BrianEkins
Mentor
Mentor
Accepted solution

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 Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
1 Like