Getting started with PyCharm (Windows)
Ben Gruver edited this page Mar 18, 2023
·
5 revisions
This describes how to configure PyCharm and set up a new Fusion 360 project.
Note: An add-in is now required to be installed in Fusion for debugging/running to work. See here for more information.
- Install PyCharm 2021.3.2 or later
- Open PyCharm, and on the welcome screen select Configure (bottom right corner)->Plugins
- Click on the "Marketplace" tab and search for "Fusion 360 Scripting" and install the plugin
- Once installed, restart PyCharm to activate the changes
- Once it restarts, on the PyCharm welcome screen, choose "New Project"
- On the "new project" screen:
- Enter the path where you want the new project created
- Expand the "Project Interpreter" drop down
- Select the "Previously configured interpreter" option
- Press the "Add Interpreter" dropdown next to the "Interpreter" option and select "Add Local Interpreter"
- In the "Add Python Interpreter" dialog
- Select the "System Interpreter" option on the left.
- Expand the "Interpreter" drop down, and choose the interpreter with the orange 'F' (Fusion) icon. The path should be located in the local Fusion 360 installation directory
- Click "OK" to create the new interpreter
- Click on the "Create" button at the bottom of the dialog
- The main PyCharm interface should open with your new project
- Go to File->Settings->Languages & Frameworks->Fusion 360 and check the "Fusion 360 Support Enabled" checkbox.
- Ensure the "Fusion 360 Executable" field is properly populated with the path to the Fusion360.exe executable.
- Click "OK" to apply the changes and exit the settings screen.
- In the "Project" pane on the left, right click on the project folder and select "New->Python File" and enter a filename. For example "helloworld.py"
- Copy and paste the following script:
import adsk.core, adsk.fusion def run(_): print("hello world\n")
- Start Fusion 360 if it hasn't already started
- Install the fusion_idea_addin in Fusion 360 (instructions)
- Right click in the editor pane in pycharm, and select "Debug in Fusion 360" from the context menu (it may be under the "More Run/Debug" entry)
- If you get an error like
Cannot run [project] on '<default>'
, look for the run configuration dropdown in the toolbar. Expand that toolbar and select the fusion process from the list of execution targets. - In order to prevent arbitrary programs from launching scripts in Fusion 360, you must confirm the initial attempt to run/debug a script. Fusion 360 will show a dialog asking for a hash of PyCharm's public key.
- Copy the public key hash from PyCharm's console and enter it in the dialog.
- The script should run in Fusion 360, and you should see output similar to the following in the "Console" pane
Public key hash: 60DDDD8629935CB98BEF1FA8A4EA20966D2D323E Attaching to Fusion 360 process with PID=20972 Connected to pydev debugger (build 201.6668.115) hello world Server stopped.
- Now add a breakproint on the
print("hello world\n")
line, right click and selectDebug in Fusion 360
- The script should immediately start in Fusion 360 and PyCharm should enter debug mode, with execution paused at the breakpoint. At this point, you can debug as per usual.