Successfully debugged Fusion 360 python script in Intellij IDEA :)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Yes!
After a number of hours of digging around, I finally managed to find a really really hacky way of getting intellij idea to attach to the python instance running in the fusion 360 process.
I'll continue to investigate more, and hopefully find a better solution. But for now, here is what I did.
Hold on to your horses, this is ugly 🙂
- Find the local directory containing the Fusion360.exe. For me, this is something like: C:\Users\<user>\AppData\Local\Autodesk\webdeploy\production\e99d5d109cb5b98e5cbbe63c19bb4468b3ad2199. Let's call that directory <FusionHome>.
- Copy <FusionHome>/Python/python.exe to <FusionHome>/python.exe
- Open IDEA (or PyCharm or whatever), and create a new python project containing your fusion script. Go to the module settings (F4)->SDKs and add a new python SDK. Select "System Interpreter", and choose the <FusionHome>/python.exe that we created in step 2.
- Choose ok and go back to the module settings. Navigate to "Project Settings->Project", and select the new python sdk as the project sdk. Click apply and ok to exit out of the settings windows.
- delete <FusionHome>/python.exe, and copy <FusionHome>/Fusion360.exe to <FusionHome>/python.exe
- Run <FusionHome>/python.exe. This will launch fusion 360.
- Rename <FusionHome>/python.exe to something different. The name doesn't matter.
- Copy <FusionHome>/Python/python.exe to <FusionHome>/python.exe
- In fusion 360, go to "Scripts and Addons" and edit one of the python scripts (doesn't matter which). This will cause fusion 360 to load the python dll into its process.
- Back in IDEA, set a breakpoint in your script. Then go to Run -> Attach to Process. You should see the "python.exe" process, which is actually the fusion 360 process. Attach to that process.
- In fusion 360, run the script you want to debug, that you've set a breakpoint for in IDEA. IDEA should hit the breakpoint and at that point, you can step, inspect values, etc. as per usual.
I told you it was ugly 🙂
The problem is that IDEA only shows processes in the "attach to process" screen based on the python sdk that is currently configured in the project. And you can't directly add "Fusion360.exe" as a python sdk, because it apparently does some pattern checks on the name of the executable you select, and complains if you try to choose Fusion360.exe.
Also, you don't really want to point IDEA at the Fusion360.exe (or even the copy we made and named python.exe), because it will try to run it as soon as you add as it as sdk. To get version information maybe? Unsure. But in any case, that just launches fusion 360, which is obviously not what IDEA was expecting. So you have to go through the dance of making <FusionHome>/python.exe a real python executable to set up the sdk, then the fusion executable to launch fusion, and then back to the real python executable so IDEA won't just re-launch fusion360 when it runs that python.exe.
I'll look into some possible solutions to make this... less ugly :). One possibility would be to write a little IDEA add-on that lets you choose an arbitrary process to attach to.