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: 

Using doExecutePreview

Message 1 of 3
801 Views, 2 Replies

Using doExecutePreview

Hi. I am writing a script in Python and would like the user to be able to define an operation in three steps, and at for a preview to be shown at the end of each stage. The CommandInputs are grouped into three sections on my dialog. I am trying to use doExecutePreview, am having difficulties and am struggling with the minimal documentation. I have included an OnPreview event handler but the behaviour is not as expected.


At the moment, the OnPreview event seems to fire when the command inputs in the first group of command inputs have been completed, despite the code not making a doExecutePreview call. But then it does not fire subsequently when my code calls it in response to a button being pressed.


1) what code should be placed in the event handler? should it be all the code associated with what you would like to preview, or will the presence of the handler in itself cause the sequence of features created by the

CommandInputChangedHandler code to be previewed?

2) how does the preview appear on the screen? is the final result shown in light grey (as with the pattern command in Fusion 360) or will the affected bodies be shown with the dark edges as they would when the command is executed?


Unfortunately the documentation is a bit thin (though generally the API Reference is very good). Can anybody provide a link to some working Python code that illustrates how the preview functionality should be used?






Message 2 of 3
in reply to: gavin9537

Here's a link to a sample I wrote a couple of years ago.  I just updated the version on Github to the latest that I have.  It demonstrates showing a preview.


Here are some basic concepts of creating a preview.

  1. You should use the inputChanged event to handle making changes to the dialog, not any geometry changes for the previews.
  2. You should use the executePreview event to do the work that represents the preview.
  3. In most cases, the preview is the same as the final result.  That's what's happening in the sample I referenced.  In the executePreview call you actually perform all of the work needed to create the final work.  It's possible to do anything you want in the executePreview and the do something else in the execute if you can do something that is more "light weight" and faster to create for the preview, but as I already said, typically the preview is the same as the final result.  The preview doesn't display any differently than the rest of the model.  If you want to highlight certain parts of the preview you will need to use custom graphics to draw additional graphics in the style you want over the regular graphics.
  4. Whatever you create in the executePreview event will automatically be deleted when any more changes are made to command inputs, the command is canceled, or the command is executed.  You can assume that you're getting a "clean palette" whenever the executePreview event is fired and don't need to worry about cleaning up anything that might have been created before.
  5. If you are creating the same thing in execute that you are for executePreview, you can set the isValidResult property to True on the CommandEventsArgs object passed into the executePreview event.  This indicates to Fusion that the preview graphics are valid and can be used as the final result, so it won't abort them and will skip the execute event when the command is executed.
Brian Ekins
Inventor and Fusion 360 API Expert
Message 3 of 3
in reply to: BrianEkins

Thanks Brian - that's v helpful indeed

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