Community
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.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Now available: Fusion 360 plugin for Intellij IDEA/PyCharm

83 REPLIES 83
Reply
Message 1 of 84
JesusFreke
11954 Views, 83 Replies

Now available: Fusion 360 plugin for Intellij IDEA/PyCharm

I've put together a little plugin for IDEA to add support for developing Fusion 360 python scripts. It allows you to launch and debug fusion scripts in IDEA, similarly to the bundled Spyder IDE.

 

You can find the plugin at https://github.com/JesusFreke/fusionIdea. It should be available in IDEA's built-in plugin repository soon, it's just pending approval.

 

You'll also need to install a small add-in in fusion 360, to help facilitate launching scripts from within IDEA. You can find more info in the README

83 REPLIES 83
Message 61 of 84
JesusFreke
in reply to: adonno

For something like autoTerminate to work, I think it has to be running in the context of a script that's actually registered as a script in fusion 360.

 

I think your best bet in that case is to go ahead and register the script in fusion's "Scripts and Add-Ins" dialog. Then, back in PyCharm, go to "Run->Attach to Process" and select the Fusion 360 process. You can set a breakpoint in your script, and then go back to fusion 360 and run the script from the "Scripts and Add-ins" dialog. The script should run, the autoTerminate method shouldn't throw an error, and the breakpoint in PyCharm should be triggered.

 

Of course, the alternate solution is to just remove the call to autoTerminate if you don't need it. Or, if you do need it, if you can share a minimal script showing the sort of functionality you need it for, I may be able to offer suggestions on how to better accommodate your needs, since the "attach to process" process I describe above is a bit cumbersome.

Message 62 of 84
adonno
in reply to: JesusFreke

To be 100% honest I have no idea what autoTerminate is even used for, I just included it because the samples I looked at included it. For now I have just commented it out and I intend to uncomment it when I finished my development.  Not having it doesn't appear to have any unexpected consequences.

 

That said I  cannot get a breakpoint in PyCharm to trigger. When I hit the little play button in PyCharm the script launches as expected in Fusion but in PyCharm I get a message that says "Connection to Python debugger failed socket closed". If I set a breakpoint and click the run in debugger option in PyCharm I get the same thing and my breakpoint is never hit.  This is still significantly better than Spyder because Spyder's debugger is so useless it isn't worth the effort. I'm much faster just using ui.messageBox to be honest 🙂

 

I see that this is a topic that has come up before. I will read that in more detail shortly but I can confirm that I have the latest Fusion, version 0.5.5 or the tool, and PyCharm Community 2018.3

 

When I try the attach to process approach I get a different response in PyCharm stating that "Connection to the Python debugger failed Accept timed out"

Message 63 of 84
JesusFreke
in reply to: adonno

That method causes the script to not automatically terminate after the run method has returned. It essentially makes the script behave more like an add-on instead.

 

The triangular "play" button just launches the script, it doesn't initiate debugging. You want to use the debug button right beside it instead. Or run->debug, or right click on the script->"Debug in Fusion 360"

 

"Connection to Python debugger failed socket closed" is an innocuous message, that's just related to how the PyCharm plugin runs the script. Or rather, how the debug connection is stopped once the script starts running.

Message 64 of 84
adonno
in reply to: JesusFreke

Yes I know that the Play button doesn't initiate debugging but even clicking the Debugger button (or Run --> Debug) it doesn't work. Please take a look at the screen cast I've uploaded with this reply and let me know if you can see anything that I'm doing wrong. Also note that since I sent my first reply I have upgraded to 2019.2 of PyCharm, the latest Fusion release (2.0.6231) and v0.5.6 of the Fusion 360 Scripting tool.

 

Message 65 of 84
JesusFreke
in reply to: adonno

Can you share the run() method?

 

So, the way script debugging works is that it attaches to the fusion process, it injects some code that loads the script as a module, it calls the run() method, and then it stops debugging.

 

Since you set a breakpoint in an event handler, I suspect the event occurs after the run() method has finished, and so the debugging connection has already been broken. To debug something like this, you can use the "attach to process" functionality instead, and then trigger the script from within fusion via the "scripts and add-ins" dialog.

 

I may be able to add some sort of run configuration option to avoid detaching after the script's run method finishes, which I think would solve your issue.

Message 66 of 84
adonno
in reply to: JesusFreke

Aaaah, ok, now I get it and it is working. Thank you so much!!

Message 67 of 84
Igorva
in reply to: JesusFreke

Hello friends!

 

Advise, who solved a similar problem.
Do according to the instructions:
1. Install the plugin

1.JPG

 

2. Install interpreter

2.JPG

 

3. Switch on support for fusion

3.JPG

 

But when I run the script, you receive a notification in the bottom left corner and nothing happens

4.JPG

 

What am I doing wrong?

Message 68 of 84
akonovalenko
in reply to: JesusFreke

Can anyone explain to me what should I change in my project to attach to Fusion360 from Intellij IDEA, after Fusion360 upgrade to Python 3.7.4 Everything works fine on Python 3.6 by then Fusion360 installs the update and start working on Python 3.7, and now I am getting "Error when injecting code in target process. Error code: 3 (on windows)" Error when trying to debug my project 😞

Screenshot_25.png

 

Message 69 of 84
JesusFreke
in reply to: akonovalenko

I just tried it, and it's working fine for me. Have you tried restarting fusion and/or pycharm/idea?

Message 70 of 84
JesusFreke
in reply to: JesusFreke

Actually, I spoke too soon 🙂 My Fusion 360 hadn't updated to the latest yet. With the new update, I'm getting the same error.

 

I'll have to investigate further. I'll report back what I find.

Message 71 of 84
JesusFreke
in reply to: JesusFreke

I spent some time looking at this this evening. It looks like that is a known issue attaching to a python 3.7 process. It was just recently fixed in IDEA/PyCharm 2019.2.*. With 2019.2.3 I was able to use "attach to process" and debug a script that was started from within fusion, but the run and debug functionality is still broken, but with a different error.

 

I'll have to investigate further. I suspect it's a problem with the script that the fusionIdea plugin injects into the fusion process when it initiates debugging. 

 

Message 72 of 84
JesusFreke
in reply to: JesusFreke

The problem I was having last night seemed to have resolved itself. I'm not sure what the deal was.

 

In any case, you can try updating to the latest version of idea/pycharm, and see if it's working.

Message 73 of 84
JesusFreke
in reply to: JesusFreke

Actually, it's not quite working right. I can successfully debug a script... but only the first time. On any subsequent attempt, it runs fine, but it won't actually hit any breakpoints.

 

*sigh*. Continuing to investigate. I filed https://github.com/JesusFreke/fusionIdea/issues/8 for this issue, and will post any updates there, so I'm not spamming this forum/thread. You can subscribe to the issue on github to get notified of any updates.

Message 74 of 84
Autodesk_AMC
in reply to: JesusFreke

Thank You, same for Me, after updating to the latest version of Intellij IDEA everything start working as it should

Message 75 of 84
JesusFreke
in reply to: Autodesk_AMC

I think I got everything working smoothly again. I've released a new v0.5.7 update to the plugin, which requires IDEA/PyCharm 2019.2.*, due to some needed fixes in the underlying debugging infrastructure that were introduced in that version.

 

The new version of the plugin should be available in IntelliJ's plugin repository soon, and in the meantime, you can get it at https://github.com/JesusFreke/fusionIdea/releases/tag/v0.5.7

Message 76 of 84
akonovalenko
in reply to: JesusFreke

Thank you for a super-fast fix 😀  v0.5.7 plugin seems to work fine. 

Message 77 of 84
JesusFreke
in reply to: akonovalenko

I'm not only the author, I'm a user! 😄 I was in the middle of some design work, and needed to get it sorted out for myself, haha 🙂

Message 78 of 84
dewaine50
in reply to: JesusFreke

Hi, do you have a step by step guide on how to get started? I have PyCharm installed and I've never used it before. How What do I click on to get this started? I have the plugin installed. 

Message 79 of 84
JesusFreke
in reply to: dewaine50

I'll try and write something up this evening.

 

In the meantime, here's some info from the plugin description:

 

PyCharm

You enable Fusion 360 support for a project in PyCharm in Settings->Languages & Frameworks->Fusion 360. Enable the "Fusion 360 Support Enabled" checkbox, ensure the path to Fusion360.exe is set correctly, and then press "Apply".

Once support has been enabled, you can write a Fusion 360 script as per usual. Once you are ready to run it, you can create a new "Fusion 360 Python Script" run configuration, and then run or debug it as you would expect.

As a convenient shortcut, you can right click on the script in the project browser on the left, or directly in the editor pane and choose "Run in Fusion 360" or "Debug in Fusion 360"

Message 80 of 84
dewaine50
in reply to: JesusFreke

Yeah, everything is correct, I just am not getting any Fusion buttons in my context menu...

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report