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: 

CommandControl index property bug

6 REPLIES 6
Reply
Message 1 of 7
rolandas.vegis
391 Views, 6 Replies

CommandControl index property bug

Hello,

index property of CommandControl object doesn't work correctly. After changing the order of controls in the toolbar, index property doesn't update - it shows the old index.

6 REPLIES 6
Message 2 of 7
goyals
in reply to: rolandas.vegis

Hi,

 

Please share the script so I can try on my side.

 

Regards,

Shyam Goyal



Shyam Goyal
Sr. Software Dev. Manager
Message 3 of 7
rolandas.vegis
in reply to: goyals

Here is the code and the screencast to show exactly what I mean.

#include <Core/CoreAll.h>
#include <Fusion/FusionAll.h>
#include <CAM/CAMAll.h>


using namespace adsk::core;
using namespace adsk::fusion;
using namespace adsk::cam;

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;

 const auto controls = ui->activeWorkspace()->toolbarPanels()->item(0)->controls();
 const auto sketch = controls->item(0);
 auto sketchId = sketch->id();
 auto sketchIndex = sketch->index();

 const auto rectangle = controls->item(2);
 auto rectangleId = rectangle->id();
 auto rectanglendex = rectangle->index();
 
 return true;
}

extern "C" XI_EXPORT bool stop(const char* context)
{
 const auto controls = ui->activeWorkspace()->toolbarPanels()->item(0)->controls();
 const auto sketch = controls->item(0);
 auto sketchId = sketch->id();
 auto sketchIndex = sketch->index();

 const auto rectangle = controls->item(2);
 auto rectangleId = rectangle->id();
 auto rectanglendex = rectangle->index();

 return true;
}


#ifdef XI_WIN

#include <windows.h>

BOOL APIENTRY DllMain(HMODULE hmodule, DWORD reason, LPVOID reserved)
{
 switch (reason)
 {
 case DLL_PROCESS_ATTACH:
 case DLL_THREAD_ATTACH:
 case DLL_THREAD_DETACH:
 case DLL_PROCESS_DETACH:
  break;
 }
 return TRUE;
}

#endif // XI_WIN

 

 

Message 4 of 7
rolandas.vegis
in reply to: goyals

Here is a screencast so you could better understand what I mean: https://autode.sk/2vVil8o.

And code:

#include <Core/CoreAll.h>
#include <Fusion/FusionAll.h>
#include <CAM/CAMAll.h>


using namespace adsk::core;
using namespace adsk::fusion;
using namespace adsk::cam;

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;

	const auto controls = ui->activeWorkspace()->toolbarPanels()->item(0)->controls();
	const auto sketch = controls->item(0);
	auto sketchId = sketch->id();
	auto sketchIndex = sketch->index();

	const auto rectangle = controls->item(2);
	auto rectangleId = rectangle->id();
	auto rectanglendex = rectangle->index();
	
	return true;
}

extern "C" XI_EXPORT bool stop(const char* context)
{
	const auto controls = ui->activeWorkspace()->toolbarPanels()->item(0)->controls();
	const auto sketch = controls->item(0);
	auto sketchId = sketch->id();
	auto sketchIndex = sketch->index();

	const auto rectangle = controls->item(2);
	auto rectangleId = rectangle->id();
	auto rectanglendex = rectangle->index();

	return true;
}


#ifdef XI_WIN

#include <windows.h>

BOOL APIENTRY DllMain(HMODULE hmodule, DWORD reason, LPVOID reserved)
{
	switch (reason)
	{
	case DLL_PROCESS_ATTACH:
	case DLL_THREAD_ATTACH:
	case DLL_THREAD_DETACH:
	case DLL_PROCESS_DETACH:
		break;
	}
	return TRUE;
}

#endif // XI_WIN
Message 5 of 7
goyals
in reply to: rolandas.vegis

Hi,

 

I am able to see the problem you described. In my opinion index property serve very little purpose on ToolbarControl. If you are looking for a particular control in a toolbarpanel then search using its id then index. Let me know if there is any specific problem which can be solved using only index and not by its ID.

 

Regards,

Shyam Goyal



Shyam Goyal
Sr. Software Dev. Manager
Message 6 of 7
rolandas.vegis
in reply to: goyals

I was trying to save the position of my commands, so when re-running the addin Fusion would create them in the way user left them. Found a workaround using promotedControls collection. Thanks for your assistance.

Message 7 of 7
goyals
in reply to: rolandas.vegis

I think it should be working by default. I just reordered few controls in a toolbar panel and restarted the Fusion. I found them how I left in my previous session so in my opinion it should be working by default for you.



Shyam Goyal
Sr. Software Dev. Manager

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