Announcements

The Autodesk Community Forums has a new look. Read more about what's changed on the Community Announcements board.

How to correctly delete new workspace in c++

lsRDZZQ
Participant

How to correctly delete new workspace in c++

lsRDZZQ
Participant
Participant

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;
}

 

0 Likes
Reply
Accepted solutions (1)
754 Views
2 Replies
Replies (2)

liujac
Alumni
Alumni
Accepted solution

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

0 Likes

lsRDZZQ
Participant
Participant

Hi liujac,

 

The solution you provided works well. thanks!

 

0 Likes