Debugging in Spyder

Debugging in Spyder

Anonymous
Not applicable
4,995 Views
7 Replies
Message 1 of 8

Debugging in Spyder

Anonymous
Not applicable

Dear Fusion Community,

I just started using Fusion 360 and I would like to make use of its Python scripting functionality. Unfortunately, the build-in Spyder editor does not let me set break-points. Also, Fusion freezes if I execute a demo script in debugging mode.

Is this a known issue or is there something wrong with my set-up?

Thank you for your support.

0 Likes
Accepted solutions (1)
4,996 Views
7 Replies
Replies (7)
Message 2 of 8

ekinsb
Alumni
Alumni
Accepted solution

Debugging Python scripts and add-ins using Spyder isn't as easy as we would like it to be but once you figure out the process it's not too bad.  I know I had a similar experience to what you're seeing when I first starting using it.  Here's are some steps to debugging a script.  The steps for debugging an add-in are slightly different.

 

Scripts

There are two ways to start the debugging process for a script.  You can start debugging from the "Scripts and Add-Ins" dialog or from Spyder.

 

From the "Scripts and Add-Ins" Dialog

    1. Run the "Scripts and Add-Ins" command.
    2. Choose the script from the list of scripts.
    3. Click the drop-down button beside the "Run" button and choose "Debug".
    4. If Spyder isn't running, it will be started and a break point will be automatically set at the first line in the program and the execution will break at that point.
    5. If Spyder is already running you'll get one of two responses.  If you haven't already run the script, Spyder will activate and the program will execute but will stop at a break point at the top of the program, like in step 4.  If you've already run or debugged the script from Spyder a dialog like the one shown below will appear.  Clicking "Yes" will then start execution with it stopped at the break point at the top of the program.  This is likely what's happening to you and you think Fusion 360 has locked up.  In reality there's a dialog up waiting for you to respond.  It doesn't always pop to the front but I believe if you activate Spyder you'll see it.

AlreadyRunning.png

 

 

From Spyder

You can also start the debugging process for a script directly from Spyder by using the button I've highlighted below.  If you don't see it, you can go to the "View" menu and make sure the "Debug toolbar" is visible.

PythonDebug.png

 

This will result in the same behavior as previously described in that you might first have the dialog appear that you need to dismiss and then execution will start but will be stopped at a break point on the first line.

 

Add-Ins

To debug an Add-In you always need to start the debugging process from the "Scripts and Add-Ins" dialog and never from within Spyder.  You should also stop execution from the "Scripts and Add-Ins" dialog.  Besides that, debugging is the same.

 

Debugging

To debug an Add-In you always need to start the debugging process from the "Scripts and Add-Ins" dialog and never from with in Spyder.  You should also stop execution from the "Scripts and Add-Ins" dialog.  Besides that, debugging is the same.  You can add break points at any time by selecting a line pressing F12 or by double-clicking in the border of the code window to the left of the code line.  Using the other buttons on the debug toolbar you can continue running (until the next break point) or step through line-by-line.  it's also useful to use the Console window to check the values of variables.

 

Hopefully this helps.

 

 


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 3 of 8

Anonymous
Not applicable

Many thanks for your explanation. 

I understand now that for a script Spyder simply breaks at the first line and that one can manually continue from there. I was indeed able to manually step through an entire script in this way. As I also understand it then, the setting of custom break points [using F12 in Spyder] is only supported for Add-ins but not for scripts.

Now that I think there is nothing wrong my installation, I am happy to continue to explore Fusion's scripting features. 

0 Likes
Message 4 of 8

ekinsb
Alumni
Alumni

Break points can be manually set for scripts and add-ins.  Once you're in the debugging process there's not difference between scripts and add-ins.


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
0 Likes
Message 5 of 8

Anonymous
Not applicable

Unfortunately, that doesn't work for me. Pressing F12, double clicking in the left area before the line number, or via the debug menu dropdown all do not result in adding a breakpoint.

0 Likes
Message 6 of 8

ekinsb
Alumni
Alumni

Here's a Screencast that demonstrates what I'm seeing.  You'll see that it's a script and that I'm able to set breakpoints using any one of three methods.

https://screencast.autodesk.com/Embed/Timeline/eb69758c-7a97-4d9b-beff-eb42e7c2816e


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
0 Likes
Message 7 of 8

eric
Contributor
Contributor

The "screencast" link is broken.

 

How does one examine variables in the debugger?  I print(ui) and it gives me some output which is less than useful.

 

How can I dot off of variables and examine the variables members?

 

Is it possible to see member variables of an object?  Say I don't know what the member variables of UI are, as I didn't write it....can I 'open' the ui variable and see the members inside?

 

 

0 Likes
Message 8 of 8

hpekristiansen
Advocate
Advocate

Are the Fusion 360 API dead? I mean nothing has changed in years. The Spyder editor is horrible outdated, and basic functionality like debugging is not working properly.

0 Likes