Community
Fusion API and Scripts
Got a new add-in to share? Need something specialized to be scripted? Ask questions or share what you’ve discovered with the community.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

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

1 REPLY 1
SOLVED
Reply
Message 1 of 2
DWhiteley
191 Views, 1 Reply

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

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

1 REPLY 1
Message 2 of 2
BrianEkins
in reply to: DWhiteley

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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report