Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

Command Dialog remain open after "OK" is clicked?

tim.collins29V9X
Enthusiast

Command Dialog remain open after "OK" is clicked?

tim.collins29V9X
Enthusiast
Enthusiast

I'd like to let the user run and re-run the AddIn in order to see the results of different combinations of dialog command input values. The "OK" could be "Draw Part" which should probably delete the previous result and re-draw the new one. The "Cancel" could be called just "Close".  How do I do this?

0 Likes
Reply
473 Views
5 Replies
Replies (5)

kandennti
Mentor
Mentor

Hi @tim.collins29V9X .

 

It would be a more user-friendly setup to use the executePreview event to display the execution results instead of pressing the OK button.

https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-dbecfaf8-9bb6-4e40-9df3-0a3e48136a4b 

I believe this will probably do the processing you want.


Anything created in the executePreview event will be automatically deleted without having to process the deletion by transaction.

Therefore, even if the executePreview event is fired each time a different one is selected in SelectionCommandInput, there is no need to write a process to delete it.

1 Like

tim.collins29V9X
Enthusiast
Enthusiast

Using preview to avoid deleting a prior "run" makes sense, but doing a preview after every CommandInput update is not practical due to the length of time it takes to run.  This based on a similar addon that does something comparable to what I am attempting.

I am also thinking I would write a bunch of settings to a .json file and maybe I'd want to block closing the dialog until after the user has a chance to save or not save new settings. I know I am abusing the intent of a dialog box, but the value to the user is there nonetheless.

 

What if I have a bool flag to ignore preview events, and but toggle that flag to True in the change handler code for the ButtonRow or DropDown with the word "Preview" on it.  If the user clicked on it, I would (a) toggle the flag to True (b) when eventPreview handler is invoked, (c) run the command and (d) toggle the flag back to False. 

0 Likes

tim.collins29V9X
Enthusiast
Enthusiast

@kandennti Hi! I forgot to tag your name in my reply above. I have an idea to use the preview feature but make it look like I have a preview button.

0 Likes

BrianEkins
Mentor
Mentor

The command framework in Fusion doesn't support the idea of applying the current state and continuing to run the command. Inventor supports this for several of its commands but you won't see this for any Fusion commands.

 

I also wanted behavior like this for a command I wrote that creates a construction point at a defined coordinate. I didn't want to have to invoke the command again for each point so I added a "Create" button on the dialog, which is the equivalent of "Apply". However, it isn't really creating the point when I click "Apply" because the creation of persistent data only happens in the execute, which his only called when the user clicks "OK". Instead, when the user clicks the "Apply" button I add that coordinate to a list and draw custom graphics to show a preview of where that point is. The user can now define another coordinate and click "Apply" and that point will be added to the list so a preview is shown. If they click "Cancel" everything is gone. If they click "OK", then I create a real construction point at each coordinate.

 

Preview.png

I didn't have to use custom graphics for the preview but could have created real construction points but they are heavier to create and they would get aborted with every change to the input and I would have to re-create them. In my case, custom graphics were also more visible to make it easier to see what they had defined so far.  

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
1 Like

tim.collins29V9X
Enthusiast
Enthusiast

@BrianEkins  Thanks, this is helpful.

I am persuaded that the Command Dialog should close when OK is clicked to allow the processing (with Undo, etc) to work properly. In my case a musical instrument will only have one fretboard and if you want two (it happens) then there it is actually easier to run the command again. To say it differently, I don't need this to run multiple times.

The only reason to keep the dialog open is to help with saving modified values to a .json file. The code can keep track of whether a file is unsaved, or modified, and could put up a dialog if there are unsaved changes. That should be close enough. I'm spending more time on housekeeping than drawing at this point.

I have yet to try the preview feature, but I assume that there is some clean way for the previous preview to "go away" automatically. My guess is that anything that happens during this time in the state-transition model of the transaction is counted as such.

Thanks for replying, Tim

0 Likes