ExecutePreview Event Without Full Rebuild

ExecutePreview Event Without Full Rebuild

commonmandan
Contributor Contributor
672 Views
1 Reply
Message 1 of 2

ExecutePreview Event Without Full Rebuild

commonmandan
Contributor
Contributor

I'm creating a new component with a couple sketches, extrudes, and revolves. Currently my Python Add-In is rebuilding all of the geometry after every user input change. It's even doing it while a multi-digit number is being entered into an input field. This causes a lot of lag. Is there a way to keep the previous preview and just edit what changed? I added an if statement to the ExecutePreview function, but the preview disappears on the second event call when I don't build the geometry.

 

Could I save the component to a global variable, then re-insert it somehow? It doesn't make sense to recreate all the sketch lines and constraints when the user only changed the extrude length.

0 Likes
Accepted solutions (1)
673 Views
1 Reply
Reply (1)
Message 2 of 2

ekinsb
Alumni
Alumni
Accepted solution

The way commands work is that whatever you construct in the executePreview is all built within a single transaction.  When the next executePreview is fired that transaction is aborted (the equivalent of an undo) so you can construct the next preview.  There isn't a way to preserve any created entities from one executePreview to another.  One option is to create a simplified preview in the executePreview event and then create the final, more expensive, result in the execute event.  The isValidResult property of the CommandEventArgs object passed into the executePreview event indicates if the geometry you build in the executePreview is to be used as the final result when the command is executed.  If this is set to False, the result created in the executePreview is aborted and the execute event is called.  If it is set to True then the execute event is skipped and the last result of the executePreview is used as the final result.


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
0 Likes