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.
Showing results for 
Show  only  | Search instead for 
Did you mean: 

GUI lifecycle of commands - edit components NOT through the execution event

Message 1 of 3
312 Views, 2 Replies

GUI lifecycle of commands - edit components NOT through the execution event

Many Add-in application require an interactive user experience, but model modifications can only be made on execution.


Is there a way to keep the command GUI "alive" during operations? for example changing a component name by calling functionality on an input change event.. 


to the best of my understanding, currently you can  only preview changes while the GUI is still alive.

Message 2 of 3
in reply to: moshebar

Model modifications can be made both on the execution of a command and also in the executePreview of a command.  The issue is that the changes made in the executePreview will be aborted if you cancel the command or when the execute if finally done, unless you've set the isValidResult property of the ComandEventArgs that's passed into the executePreview to True.  If that's the case then when the command is executed the changes made in the executePreview will be used and the execute event won't be fired.


But I think what you're wanting is for a single command to make as series of changes, saving each one as you go.  This isn't supported by the current Fusion 360 command architecture.  See if you can find any Fusion commands that provides this capability. You might be able to do something that would provide similar functionality by automatically invoking your command again after it's been executed but I haven't tried that to see if it would all work.


The way a command works is that when the user clicks the ribbon button, the command is created which results in the commandCreated event being fired where you define the contents of the command dialog and connect to other command related events. Whenever changes are made to the inputs the inputChanged, validateInputs, and executePreview events are fired. You can do whatever you want in the executePreview to illustrate what the final result will be.  Often times this is doing the actual work to create the final result.  Whatever you do it is encapsulated within a "transaction".  With the next change to any of the inputs that transaction is aborted so all those changes are lost and you're back to the state where the command started.  When the OK button is clicked, the execute event is fired and you can created the final result.  This work done in the execute event is also encapsulated within a single transaction, which is why there is a single item in the undo list.  It's just that this final transaction remains and isn't aborted.


Another option to maybe get the desired effect you're looking for is to use the palette functionality.  A palette isn't associated with a command and can remain visible anytime.  The content of a palette is defined using html so it's entirely different than a command dialog and the various command inputs used to define the content of the dialog.


It could also be that in the future Fusion 360 will support the ability to apply and save the current changes while the command continues to run.  If that should happen I expect that we'll also expose that through the API but for now it's not available.

Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 3 of 3
in reply to: ekinsb

Thanks for the detailed reply.


I think I have solved this and would like to share here for other developers:


step 1:

somewhere in the CommandCreatedEventHandler:


   command->isAutoExecute(false); //do not auto execute on close

   command->isExecutedWhenPreEmpted(false);//do not auto execute when other commands are executed


step 2:

make a global flag to designate running of specific function during execution


   bool runFunX = false;// default false


step 3:

tag the flag on a specific input trigger in InputChangedEventHandler and call execution within that event


   lastInput = eventArgs->input();

   string input_id = lastInput ->id();

    if (input_id  == "my_command_input_id")

          runFunX = true;
          command->doExecute(false); //false - execute without terminating GUI
          runFunX = false;



step 4:

within the execute event CommandEventHandler call the function if the flag is up:


   if (runFunX)


hope someone might find this useful.




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