Is it possible to run and debug Fusion 360 API scripts and add-ins from Visual Studio Code (VSCode)?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I've been trying to optimize my workflow in creating Fusion 360 API scripts and add-ins, and I'm still confused about what the "correct" approach is. It used to be that we would use Spyder which would connect to Fusion, allowing you all of the tools and amenities you'd expect from an IDE.
However, now Fusion uses VSCode. I love VSCode so theoretically this would be a change for the better, but the problem is that Fusion doesn't really connect to VSCode completely. When I click Edit in the add-ins menu, it does open the python file in VSCode, but that's about where the connection seems to end. VSCode doesn't recognize the adsk module or any other Fusion specific modules, commands or libraries. So, if you try to run a script or add-in from VSCode, of course it won't work and you'll just get errors. As far as I can tell, you instead have to go into Fusion 360 and open the add-ins menu and run it from there.
The problem with this is that you're coding blind. You can't print to console or use a debugger like normal, and when a script fails, there's no error messages printed in VSCode or in Fusion, so you just have to fill your code with ui.messageBox messages which is messy and slow. If there is a syntax error in your code, when you try to run it, just nothing happens with no info as to why.
I did find that there are two extensions for VSCode, called Autodesk Fusion 360 Post Processor Utility and Fusion 360 Addin Helper. The second one is the most relevant, but still there are significant issues. The main issue is that it often doesn't recognize a file as being a Fusion 360 script or add-in, so it won't activate at all. From the description, it says it only recognizes Fusion files that have a manifest file.
The problem with that is that Autodesk also changed the entire architecture of how add-ins and commands are handled with python. Previously, the brunt of the code would be in one the myAddinName.py python file in the root directory of the add-in, and there would be a manifest file like myAddinName.manifest. The Fusion 360 extension for VSCode handles these oldschool add-ins just fine and brings very helpful functionality like auto-complete and information about Fusion 360 objects.
However, now when you make a new add-in, you get a much more complicated folder structure, where every command in your add-in has its own folder within a commands folder. Now, the myScriptName.py file is just boilerplate run and stop functions and you're not even supposed to touch that file at all. This makes the Fusion 360 Addin Helper extension pretty much useless because that's the only file it will recognize, since that's the only one that has a manifest file. I have tried making manifest files for the entry.py files in the command folders but it doesn't work.
There just seems to be a huge lack of communication between teams about this stuff. I haven't found a single official Autodesk tutorial about how we're supposed to integrate VSCode and Fusion 360 and it's sorely needed. Autodesk, please get on this!