When is Add-In code reloaded? What is the best development workflow?

When is Add-In code reloaded? What is the best development workflow?

tiktuk
Advocate Advocate
852 Views
4 Replies
Message 1 of 5

When is Add-In code reloaded? What is the best development workflow?

tiktuk
Advocate
Advocate

Hi,

 

I've started working on my first Add-In and would like to know what is the best workflow for editing and reloading the (Python) Add-In code?

 

It seems like code in the main Add-In file is reloaded every time the Add-In is started and stopped in the Scripts and Add-In dialog. Code imported from a module is not, however.

 

I've created my Add-In boilerplate using @prainsberry's very useful Apper (thanks!).

 

There's not a lot of information on the subject, one thread is here, but it's not conclusive. (That thread mentions using relative imports, which I do, my code is straight from the cookie cutter.)

 

I'm using VS Code and it starts correctly when clicking Edit / Debug in Fusion.

 

0 Likes
Accepted solutions (2)
853 Views
4 Replies
  • API
Replies (4)
Message 2 of 5

tiktuk
Advocate
Advocate
Accepted solution

Ok, I found out that deleting the module in the stop() method does the trick ☺️ .

 

import sys

def stop(context):
    del sys.modules['commands.SampleCommand1']

 

Message 3 of 5

prainsberry
Autodesk
Autodesk
Accepted solution

Hey thanks for the bump, I've added some stuff in one of my apper implementations that handles this and I've been meaning to add it to the cookie cutter template.  Will try to get that done ASAP.  

 

You are correct, because Fusion 360 uses a single python runtime, modules that are previously loaded will not necessarily be reloaded when you restart the add-in.  This is a consequence of the way we use Python.  We are actually looking at some possible alternate solutions, but for now this is the method I use.  

 

Also I actually put that in the beginning before I do the imports, in case the add-in crashed or something didn't shut down correctly.  May or may not be necessary.  



Patrick Rainsberry
Developer Advocate, Fusion 360
Message 4 of 5

tiktuk
Advocate
Advocate

Thanks, will move it to the beginning. And looking forward to the updated cookie cutter, it's super useful ☺️ .

0 Likes
Message 5 of 5

saccade
Contributor
Contributor

Sort of related to this topic - Is it possible to come up with a "one click" method for reloading a Python add-in? Right now the procedure is:

  • Bring up the add-ins panel (Shift-S)
  • Click the add-ins tab
  • Click on your add-in and stop it (if it was running)
  • Switch to VSCode, and disconnect the debugger
  • Switch back to Fusion, Click on your add-in again, and click "Debug"
  • Go back to VSCode, Start the Python debugger
  • Back to Fusion, dismiss the "Add-in started" dialog.

That's a lot of tedious clicking around every time I modify the Add-in's source code and want to restart it. Has anybody found a more streamlined solution?

0 Likes