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: 

Python environment to use another editor

15 REPLIES 15
SOLVED
Reply
Message 1 of 16
Le_Bear
2032 Views, 15 Replies

Python environment to use another editor

I would love to be able to use Microsoft Code as Editor, instead of Spider2. Would it be possible to know what are the different environment settings needed? 

I see there is a possibility to use another editor, doing some modifications to the .manifest file, for C++. Any way to do the same for Python?

Any help would be great.

Thanks,

Bernard

Bernard Grosperrin

Autodesk Certified Instructor

FaceBook Group | Forum | YouTube

Group Network Leader
 
15 REPLIES 15
Message 2 of 16
marshaltu
in reply to: Le_Bear

Hello,

 

Unfortunately there is no easy way to switch to another python IDE yet. Theoretically you can use other python ide (e.g. vscode) by some manual setting. I just give a try to debug python scripts with vscode according to the steps described in https://code.visualstudio.com/docs/python/debugging. It works. Please refer to following screencast. Some other manual settings will be also needed to enable code hint.

 

http://autode.sk/2CM5RAu

 

Thanks,

Marshal



Marshal Tu
Fusion 360 Developer
Autodesk, Inc.

Message 3 of 16
Le_Bear
in reply to: marshaltu

Thank you for this, great help!

Bernard Grosperrin

Autodesk Certified Instructor

FaceBook Group | Forum | YouTube

Group Network Leader
 
Message 4 of 16
Le_Bear
in reply to: marshaltu

When I type "import sys" in the console, with Python selected, I don't get anything to display as in your screen cast. What Am I missing?

Bernard Grosperrin

Autodesk Certified Instructor

FaceBook Group | Forum | YouTube

Group Network Leader
 
Message 5 of 16
marshaltu
in reply to: Le_Bear

Hello,

 

No message means it works well. Please make sure the option in right-bottom corner is "Py" in text command window. 

 

The codes I executed in Fusion 360 are to import "ptvsd" so that VSCode can remote debug with Fusion 360(as Python interpreter). The path appended to system path is to let Python know where it can load "ptvsd". Please note the path will be different in your machine. 

 

import sys
sys.path.append("C:\\Users\\tum\\.vscode\\extensions\\ms-python.python-2018.1.0\\pythonFiles\\PythonTools")

import ptvsd
ptvsd.enable_attach("my_secret", address = ('0.0.0.0', 3000))

Meanwhile you have to install Python debug tool and have same settings in launch.json in VSCode project. 

 

    "version": "0.2.0",
    "configurations": [
        {
            "name": "Attach (Remote Debug)",
            "type": "python",
            "request": "attach",
            "localRoot": "${workspaceFolder}",
            "remoteRoot": "${workspaceFolder}",
            "port": 3000,
            "secret": "my_secret",
            "host": "localhost"
        }
    ]

Thanks,

Marshal



Marshal Tu
Fusion 360 Developer
Autodesk, Inc.

Message 6 of 16
Le_Bear
in reply to: marshaltu

I am back trying to use VS Code.

I followed your advice, and screen cast, but I keep getting an error, as the debug process stop immediately. VS Code is so much better than Spider, I would really love to be able to use it.

I was wondering if I need to tell VSCode to use a different Python than the one installed in Windows, to use Fusion 360's Python?

Bernard Grosperrin

Autodesk Certified Instructor

FaceBook Group | Forum | YouTube

Group Network Leader
 
Message 7 of 16
marshaltu
in reply to: Le_Bear

Hello,

 

What was the error you were seeing? It is not necessary to let VS code use the python version inside Fusion. You can give a try if it makes difference. 

 

Thanks,

Marshal



Marshal Tu
Fusion 360 Developer
Autodesk, Inc.

Message 8 of 16
Le_Bear
in reply to: marshaltu

Here is what I get: 

"debugging process interrupted unexpectedly"

2018-03-21 12_02_00-Basic_Add-in_Command.py - Basic_Add-in_Command - Visual Studio Code.png

 

Thanks for your help,
Bernard

Bernard Grosperrin

Autodesk Certified Instructor

FaceBook Group | Forum | YouTube

Group Network Leader
 
Message 9 of 16
marshaltu
in reply to: Le_Bear

Hello,

 

Unfortunately I have no idea what's root cause. I encountered the issue in the past, which was because some configuration was wrong. Meanwhile I got the error when I attached to Fusion 360 again after it was detached. I had to restart Fusion 360 to fix it.

 

So far, debugging experiences with VS code is not so good with Fusion 360. Some improvements will be needed to smooth the experiences. I would recommend you to create a request in our idea station. Let us see how many users have same requirements. Meanwhile our production management team can rank/prioritize it with other requirements together.

 

https://forums.autodesk.com/t5/fusion-360-ideastation-request-a/idb-p/125

 

Thanks,

Marshal



Marshal Tu
Fusion 360 Developer
Autodesk, Inc.

Message 10 of 16
Le_Bear
in reply to: marshaltu

Thanks 


@marshaltuwrote:

Hello,

 

Unfortunately I have no idea what's root cause. I encountered the issue in the past, which was because some configuration was wrong. Meanwhile I got the error when I attached to Fusion 360 again after it was detached. I had to restart Fusion 360 to fix it.

 

So far, debugging experiences with VS code is not so good with Fusion 360. Some improvements will be needed to smooth the experiences. I would recommend you to create a request in our idea station. Let us see how many users have same requirements. Meanwhile our production management team can rank/prioritize it with other requirements together.


Hi Marshal,

Thanks for your answer. I will follow your advice, and put a request in the Idea Station. VS Code is way much better, from my point of view, and works on Mac too. So it would be a good choice. If I am not wrong, something like that is already doable for C++, why not for Python?

Anyway, thanks, and best regards,

Bernard

Bernard Grosperrin

Autodesk Certified Instructor

FaceBook Group | Forum | YouTube

Group Network Leader
 
Message 11 of 16
Le_Bear
in reply to: marshaltu

Getting back to attempting to make it work.

I did switch to Fusion 360 Python, and now when I attempt to attach the debugger, I get an more precise error:
There was an error in starting the debug server. Error = {"code":"ECONNREFUSED","errno":"ECONNREFUSED","syscall":"connect","address":"127.0.0.1","port":3000}

I guess it means python refused the connection. Any idea  what to do to make it accept the connexion?

Thanks,

Bernard

Bernard Grosperrin

Autodesk Certified Instructor

FaceBook Group | Forum | YouTube

Group Network Leader
 
Message 12 of 16
Le_Bear
in reply to: Le_Bear


@Le_Bearwrote:

Getting back to attempting to make it work.

I did switch to Fusion 360 Python, and now when I attempt to attach the debugger, I get an more precise error:
There was an error in starting the debug server. Error = {"code":"ECONNREFUSED","errno":"ECONNREFUSED","syscall":"connect","address":"127.0.0.1","port":3000}

I guess it means python refused the connection. Any idea  what to do to make it accept the connexion?

Thanks,

Bernard


False alert! IT WORKS!!! Yeah!

Looks like I needed to use Fusion360 Python, won't work otherwise. Well, will teste this for a while, but it feels like being upgraded to First class after a long trip in Economy.... 🙂

 

Bernard Grosperrin

Autodesk Certified Instructor

FaceBook Group | Forum | YouTube

Group Network Leader
 
Message 13 of 16
NateAGeek
in reply to: Le_Bear

Are you still able to get it to work? Could you share your launch.json file and what commands you typed into the Fusion 360 console?

 

Thank you

Message 14 of 16
tikuma625HQ
in reply to: marshaltu

Hi,

 

I just successfully set up debugging with VS Code, and I wanted to share my Fusion 360 Python script to enable remote debugging with the latest version of VS Code (1.30.1) & Python (2018.12.1) in Windows.

 

Here is the script, which hopefully be maintenance free for the future version of the extension:

 

# Run this from Fusion 360's Text Command panel each time starting Fusion 360
import os
from os import path

vscodeDir = "C:\\Users\\tikum\\.vscode\\extensions"
vscodeExtDir = ""
# with os.scandir(vscodeDir) as it:
#     for entry in it:
for entry in os.scandir(vscodeDir):
    if entry.name.startswith('ms-python.python') and entry.is_dir():
        vscodeExtDir = entry.path

import sys
sys.path.append(vscodeExtDir + "\\pythonFiles\\lib\\python")

import ptvsd
ptvsd.enable_attach(("0.0.0.0", 3000))

 

 

2 discrepancies in the extension versions that Marshal's and my code was written for:

* The location of ptvsd module has been moved from pythonFiles/PythonTools to pythonFile/lib/python within the extension folder

* ptvsd.enable_attach no longer takes "my_secret" argument

 

I have saved this script as a new custom script in Fusion 360 and run it every time I startup Fusion 360, making it a 3-click process.

 

Also, REMOVE this line from VS Code's launch.json file:

"secret": "my_secret",

 Hope this helps somebody,

Kesh

Message 15 of 16
Anonymous
in reply to: tikuma625HQ

I know this is an old thread, but now that VS Code can the python editor for the API, what is the status for debugging, officially? I mean, what needs to be done to properly debug from VS Code with Fusion 360 API?

Message 16 of 16
BrianEkins
in reply to: Anonymous

Take a look at this help topic.  It goes over the steps to debug a Python script or add-in.

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com

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

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report