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: 

Not able to debug scripts/add-ins in Visual Studio Code

21 REPLIES 21
SOLVED
Reply
Message 1 of 22
Anonymous
7730 Views, 21 Replies

Not able to debug scripts/add-ins in Visual Studio Code

Hi,

 

I'm trying to start edit/debug on a script from Fusion360, but when pressing debug or edit nothing happens. I've installed Visual Studio Code and I have Python 3.8.0. Also, when I open the script manually in VS Code I cannot run it because it doesn't find the required modules (e.g. adsk), but it runs fine when run from within Fusion360. Does anyone know how to fix this? 🙂 I suspect there is some path I have to configure somewhere? 

 

Thanks in advance,

Snorre Hukkelås

21 REPLIES 21
Message 2 of 22
Anonymous
in reply to: Anonymous

So I got a step further by following "Problem debugging Python code" and "Cannot debug Python add-in" found here:  https://modthemachine.typepad.com/my_weblog/fusion-360/😊

 

Now Visual studio starts up and the code compiles, but I can't run it:

ModuleNotFoundError: No module named 'adsk'
Message 3 of 22
Anonymous
in reply to: Anonymous

AND now I got further by understanding that you need to run the program from within Fusion360, Tools ->Add-ins->Scripts and add-ins->"your script"->Run.

 

To start a debug session simply place some breakpoints and in VS Code, do Debug->Start Debugging.

Message 4 of 22
Nilesh.Mohite
in reply to: Anonymous

Hi @Anonymous ,

It is issue with latest python extension installed in VSCode.

You need to downgrade the ms-python extension from VScode to lower version 2019.9.34911.

Please refer to the following similar issue.

API debugger doesn't work after Oct 2019 update

Solutions provided by @goyals will work for you. Go to Solution.

The window you are seeing is fusion checks for the extension if it not there it will try to install latest extension.

Please make sure to close fusion when you are doing this. Also restart VScode.

To verify, you can check your directory on windows %HOMEPATH%/.vscode/extensions/ on mac ~/.vscode/extensions/ this directory should contain only one ms-python extension version 2019.9.34911. If it contains another version please delete that folder also in .obsolete file if there is entry for ms-python extension you should remove it.


Nilesh Mohite
LinkedIn

If my answer helped you, please use  ACCEPT SOLUTION .
Also be generous with Likes!  Thank you and enjoy!

Message 5 of 22

Hi @Anonymous ,

Further, to debug or edit scripts, you can select the script from fusion Addins menu and click on "edit" or "debug"(debug option os present in dropdown menu button near Run button).

Once script is opened in VSCode you can hit F5 or greenb in configuration to attach script for debugging. If you are in edit mode you need to add breakpoint manually.

 

If you are missing any modules especially for mac.you can further refere to following post for verifying your settings of python def files(for OSX)

https://forums.autodesk.com/t5/fusion-360-api-and-scripts/code-hints-in-visual-studio-code-howto/m-p...

 

Lets us know if you need further help.


Nilesh Mohite
LinkedIn

If my answer helped you, please use  ACCEPT SOLUTION .
Also be generous with Likes!  Thank you and enjoy!

Message 6 of 22
Mattxer
in reply to: Nilesh.Mohite

Currently there is a bug in the never versions of ms-python for vscode. like mentioned above the best way to fix it is to downgrade the extension. If you're unsure how, here is where you go. Hope this helps 🙂

 

Matt Smith
Software Engineer - MSmithDev - https://msmithdev.com/
CAD/CAM/CNC - Micro Insert Inc. - https://microinsertinc.com/
Message 7 of 22
Anonymous
in reply to: Nilesh.Mohite

Thank you very much, @Nilesh.Mohite ! Maybe I did something wrong, but this workaround still seems to be needed in April, 2020.

Tags (1)
Message 8 of 22
akonovalenko
in reply to: Mattxer

The new build of ms-python.python-2020.5.80290 from 19 May 2020 also does not want to debug Fusion scripts... 

the previous one (ms-python.python-2020.5.78807) works fine 

Message 9 of 22
oafak
in reply to: Nilesh.Mohite

I am still getting these errors. In my case, I receive no errors if I execute my Python script from Fusion 360. Once I start from Fusion 360, I am able to edit the same script in Visual Studio Code and everything works. I want to know if it is possible to run the script in VCS directly without first opening it in Fusion 360. If it can be done, the benefit for me would be to be able to test simpler aspects of I/O that can be done in a VCS terminal before launching the full script graphics. I have added the fusion 360 path to my environment, and I am using version 3.7.6 64 bit of Python on Windows 10

Message 10 of 22
Nilesh.Mohite
in reply to: oafak

Hi @oafak ,

When we launch VS code through fusion 360 it allows us to run python scripts on python module loaded with Fusion.

So some of the internal fusion modules will be loaded by default there. But when we launch independent VCS and try to use separate python module even with valid fusion path. But as python module is not able to find fusion modules it will give you errors.


Nilesh Mohite
LinkedIn

If my answer helped you, please use  ACCEPT SOLUTION .
Also be generous with Likes!  Thank you and enjoy!

Message 11 of 22
Moh_Samy
in reply to: Anonymous

@Anonymous  it is not working that simple for me 😞
when i click (Debug) button from "Script and Add-Ins" window in Fusion 360, Nothing happen
when i click (Edit) button, also nothing happen, so i have to open VS Code manually !
Debugging the script form VS Code also doesn't work, it just stops at this line

def run(context😞

then exit debugging mode when i am trying to step over or add any break points after this line

however, the only thing that works is "Run" button to execute script in Fusion 360
------------------------------------
Code is attached...

Message 12 of 22
JeromeBriot
in reply to: Moh_Samy

Hello,

 

Did you read all the answers in this thread?

 

Actually, you have to downgrade the Python plugin in VS Code to version 2020.6.91350.

 

Message 13 of 22
Anonymous
in reply to: JeromeBriot

Hi Jerome,

I know you have a lot of experience using the API, but for me, it's just like it is for Moh_Samy  clicking on debug does nothing but opening quickly a command windows, where it says installing extension. It does not start VS Code

I have Python extension 2020.6.91350 installed, as recommended 

bernardACK8A_0-1600607188975.png

This has been working for me in the past, with the previous recommended Python extension, and an older version of Fusion, as well as an older version of VS Code

Right now, my versions are:

Fusion 360 2.0.8950
Windows 10 19042
VS Code 1.49.1




Message 14 of 22
Anonymous
in reply to: Anonymous

Well,I fully un-installed Fusion and reinstalled it. Now it works. Don't asl me why, but it may help some other people.

Message 15 of 22
Moh_Samy
in reply to: JeromeBriot

Thank you very much for your fast response ! I really appreciate that

I do read all the thread, but i noticed @Nilesh.Mohite  recommend version 2019.9.34911 of python in VS code, so i do.

any way i installed the exact version you mentioned and now there is somehow communication between VS code and fusion.
Now, when i click "Edit" button in "Scripts and Add-Ins" window, it opens VS code automatically to edit the code
also when i click "Debug" button it do the same but don't start debugging.
when i try to click the debug button in VS code at the upper left corner it show error message:
"Invalid message : Session is not initialized yet"
and have a button called "Open Launch.json" which opens a file with the same name to be edited somehow
what should i do then ?
-------------------------------------------------------
VS code version: 1.49.1 (user setup)
VS code python extension version:  2020.6.91350
Fusion 360 version:  2.0.8950
windows version: Windows 10 (19041)
windows python version: 3.7.6
-------------------------------------------------------

Message 16 of 22
Moh_Samy
in reply to: Anonymous

As @JeromeBriot  kindly said
you must have python extension version 2020.6.91350 in VS code. maybe because of new fusion360 updates need this extension version.
before that i was installing (2019.9.34911) and  this was working well for me since ~2 months, but when i returned now, nothing work at all as you said (Edit & Debug) buttons in the (Scripts and Add-Ins) window don't work.
it just opens a "cmd" window saying "installing extension..." then disappear and nothing happen at all after this.

after installing this version ( 2020.6.91350) as @JeromeBriot  mentioned, a link somehow re-established between fusion 360 and VS Code. now (Edit & Debug) buttons opens VS code window, but debugging still not work as i mentioned i the previous reply.

I hope you will solve this problem soon, and i will reply when it is solved for me.

Message 17 of 22
Nilesh.Mohite
in reply to: Moh_Samy

HI @Moh_Samy ,

Now fusion supports latest vscode extensions and vscode versions.

A. Are you able to debug other sample script like Bottle.py ,Bolt.py ?

If yes then just copy this file with your script  "TH Aluminium Poly Capacitor Sizes.manifest".
This file gets auto generated by fusion when you create new script using fusion. But some how if you relocated your script then you can copy the manifest file and rename to match your script name.
I have added same thing in zip attached.

B. If you are still facing some issue and not able to debug sample scripts also.
Please do following steps.

  1. Close Fusion 360
  2. Uninstall python extensions from vs code
  3. Close vs code
  4. Go to '%homepath%\.vscode\extensions'
  5. Clear any ms-python extension directories like ms-python.python-2019.###
  6. Delete .obsolete file
  7. Start fusion
  8. Go to addins and debug any sample adding script.
  9. You should able to debug it successfully.

Please let me know if you need anymore help.

 


Nilesh Mohite
LinkedIn

If my answer helped you, please use  ACCEPT SOLUTION .
Also be generous with Likes!  Thank you and enjoy!

Message 18 of 22
oafak
in reply to: Nilesh.Mohite

I found out, last week, by accident, that Fusion 360 API now supports not only my Python 3.8.3, but also the latest Python extension 2020.8.109390! Thanks to Nilesh for confirming this. I was able to move to the newest version (previously installed) without re-installing Fusion 360, or Visual Studio Code. There is no need to ask users to downgrade to older versions or extensions any longer if this new compatibility with the API remains stable. Kudos to the Fusion 360 API team and the Python people for making this work. It is a joy to work in this environment!

Message 19 of 22
Moh_Samy
in reply to: Nilesh.Mohite

Thanks you very much for your attention.
regretfully, this method doesn't work for me !
i have uninstalled every thing (Vs Code and Fusion 360 and python) then reinstalled every thing again and it is working for me well right now
now i have these versions:
Fusion 360 : 2.0.9011
Python : 3.7.6
VS Code : 1.50.0 (User Setup)
Python extension in VS code : 2020.6.91350

Windows : 10 (19041)

Message 20 of 22
Moh_Samy
in reply to: Anonymous

Yeah it works for me too
UN-install every thing and re install every thing. that's it 😄

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

Post to forums  

Autodesk Design & Make Report