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: 

How to correctly delete new workspace in c++

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
lsRDZZQ
549 Views, 2 Replies

How to correctly delete new workspace in c++

Hello,

 

How to correctly delete the new created workspace object in c++? 

If I'm in the new created workspace, then the following code crashes fusion 360. If i go to solid workspace and stop the addin, everything works well. so how to avoid this kind of problems. thanks

 

 

extern "C" XI_EXPORT bool stop(const char* context)
{
	if (!ui)
		return false;

	/**
    * Get global objs
    */
	Ptr<Toolbars> toolbars = ui->toolbars();
	if (!toolbars)
		return false;
	Ptr<CommandDefinitions> cmdDefs = ui->commandDefinitions();
	if (!cmdDefs)
		return false;
	Ptr<Workspaces> workspaces = ui->workspaces();
	if (!workspaces)
		return false;
    
    /*
    * Get and release user def objs
    */
	//Ptr<Workspace> simericsWorkspace = workspaces->itemById(simericsExistWorkspaceId);
    Ptr<Workspace> simericsWorkspace = workspaces->itemById(simericsWorkspaceId);
	if (!simericsWorkspace)
		return false;
	Ptr<ToolbarPanels> tbPanels = simericsWorkspace->toolbarPanels();
	if (!tbPanels)
		return false;
	Ptr<ToolbarPanel> tbPanel = tbPanels->itemById(simericsPanelId);
	if (!tbPanel)
		return false;
	Ptr<ToolbarControls> tbPanelCtrls = tbPanel->controls();
	if (!tbPanelCtrls)
		return false;
	Ptr<ToolbarControl> tbComCtrl = tbPanelCtrls->itemById(simericsComId);
	Ptr<CommandDefinition> cmdDef = cmdDefs->itemById(simericsComId);

    if (tbPanel)
        tbPanel->deleteMe();
    if (simericsWorkspace)
        simericsWorkspace->deleteMe();
	if (tbComCtrl)
		tbComCtrl->deleteMe();
	if (cmdDef)
		cmdDef->deleteMe();

	return true;
}

 

2 REPLIES 2
Message 2 of 3
liujac
in reply to: lsRDZZQ

Hi,

 

Thanks for reporting this issue. I logged a defect (UP-29294) in our internal system. We will fix it.

 

For now, the workaround is to check if the workspace to be deleted is active, activate another workspace (Workspace.activate()) if the workspace to be deleted is active, and then delete your workspace.

 

Thanks,

Jack

Message 3 of 3
lsRDZZQ
in reply to: liujac

Hi liujac,

 

The solution you provided works well. thanks!

 

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