Module Not Found Error

Module Not Found Error

MrBradB
Participant Participant
1,317 Views
2 Replies
Message 1 of 3

Module Not Found Error

MrBradB
Participant
Participant

I'm trying to get into python scripting. I have created and ran the mandatory "Hello there" script. It runs fine from Fusion. When I try to run it from Visual Studio Code I get an error.

I have read through here and found this to appear to be a fairly common problem. Unfortunately all the answers deal with going to another thread on the forum, leading to another thread on the forum and so on and so fourth. It all ends up looking Greek (so to speak). Any help will be greatly appreciated.

 

Here is the code:

 

 

#Author-
#Description-

import adsk.core, adsk.fusion, adsk.cam, traceback

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface

        ui.messageBox(" This a a test")

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

 

When I run it I get the following error:

 

Exception has occurred: ModuleNotFoundError
No module named 'adsk'
  File "/Users/bradbumgarner/Library/Application Support/Autodesk/Autodesk Fusion 360/API/Scripts/TestScript/TestScript.py", line 4, in <module>
    import adsk.core, adsk.fusion, adsk.cam, traceback
ModuleNotFoundError: No module named 'adsk'

 

My app and system specs:

Fusion 360 2.0.15299 x86_64 [Native]
Active Plan: Personal
macOS 12.6.3 (21G419) on MacBookAir7,2

 

My Visual Studio Code specs:

Version: 1.75.1 (Universal)
Commit: 441438abd1ac652551dbe4d408dfcec8a499b8bf
Date: 2023-02-08T21:34:59.000Z
Electron: 19.1.9
Chromium: 102.0.5005.194
Node.js: 16.14.2
V8: 10.2.154.23-electron.0
OS: Darwin x64 21.6.0
Sandboxed: No

 

 

0 Likes
Accepted solutions (1)
1,318 Views
2 Replies
Replies (2)
Message 2 of 3

BrianEkins
Mentor
Mentor
Accepted solution

You need to run it from VS Code that's started from Fusion when you select the script in the "Scripts and AddIns" command and click the "Edit" button. From that instance of VS Code, you run the "Start Debugging" command or "F5", and it will run your script and stop at any breakpoints you've added. 

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
0 Likes
Message 3 of 3

MrBradB
Participant
Participant

I was clicking the Run button in the VSCode window, not using the menu at the top. Thanks for that.

0 Likes