Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Unhandled exception while importing and running script" #16

Open
NyxCode opened this issue Mar 22, 2022 · 8 comments
Open

"Unhandled exception while importing and running script" #16

NyxCode opened this issue Mar 22, 2022 · 8 comments

Comments

@NyxCode
Copy link

NyxCode commented Mar 22, 2022

Fusion throws this error at me when running / debugging:

Unhandled exception while importing and running script.
Traceback (most recent call last):
  File "C:/Users/morit/AppData/Roaming/Autodesk/Autodesk Fusion 360/API/AddIns/fusion_idea_addin/fusion_idea_addin.py", line 331, in notify
    module = importlib.util.module_from_spec(spec)
  File "<frozen importlib._bootstrap>", line 580, in module_from_spec
AttributeError: 'NoneType' object has no attribute 'loader'
@JesusFreke
Copy link
Owner

hmm. It looks like importlib.util.spec_from_file_location is returning None when creating an import spec for the script that's being run.

I was able to reproduce this if I created a script with a non-standard extension (e.g. no extension) and overrode the file type in IDEA, and tried to run that. Does the script you're trying to run have a non-standard file extension or anything?

I just pushed JesusFreke/fusion_idea_addin@a4d43cb which fixes the problem for that specific case at least.

@NyxCode
Copy link
Author

NyxCode commented Mar 24, 2022

Hey, thanks for the quick response!
I now updated the fusion addin as well as PyCharm and the fusionIdea plugin.
When I either do "Run in Fusion 360" or "Debug in Fusion 360", my addin is started within fusion after I enter the key hash. However, I do not see any console output, and the debugger is not attached.
When I do "Run in Fusion 360", i just see

Public key hash: 65E9F2D25E79AA8B9EC13D12BB27D4191547202D
Server stopped.

When I debug, I just see

Public key hash: 65E9F2D25E79AA8B9EC13D12BB27D4191547202D
Attaching to Fusion 360 process with PID=7036
Connected to pydev debugger (build 213.7172.26)
Server stopped.

@NyxCode
Copy link
Author

NyxCode commented Mar 24, 2022

Maybe I am missing something here - Are Fusion addons even supported?

@JesusFreke
Copy link
Owner

When running/debugging from IDEA/PyCharm, it will import the script into Fusion's python environment, run the "run" method, and then disconnect once the run method returns.

I'm not actually sure what happens if you try to register for events or add buttons or stuff, like an add-in normally would. Since the add-in code is actually running in the context of the fusion_idea_addin as far as Fusion is concerned, I would guess it should probably work, but the events and such would just be associated with the fusion_idea_addin addin.

Another approach would be to install your add-in as an actual add-in in fusion, and then set a breakpoint in an event handler or whatever in IDEA/PyCharm, and attach to the fusion process (Run->Attach to process in IDEA). Then, when the event is triggered, it should hit the breakpoint in IDEA/PyCharm and you can continue debugging from there.

@NyxCode
Copy link
Author

NyxCode commented Mar 24, 2022

@JesusFreke I see, makes sense!

Another approach would be to install your add-in as an actual add-in in fusion, and then set a breakpoint in an event handler or whatever in IDEA/PyCharm, and attach to the fusion process (Run->Attach to process in IDEA). Then, when the event is triggered, it should hit the breakpoint in IDEA/PyCharm and you can continue debugging from there.

I somehow can't get PyCharm to connect to the Fusion process like VSCode does, no matter what I do.

@NyxCode
Copy link
Author

NyxCode commented Mar 24, 2022

I don't know much/anything about how python debugging works, but I suspect the "Debug" button within Fusion starts a debugging server to which VSCode then connects. No idea how to set this up in pycharm though. Through the "Attach to Process.." dialog in PyCharm, I cannot connect to any process

@JesusFreke
Copy link
Owner

JesusFreke commented Mar 24, 2022

Hmm. Attach to process works for me in pycharm.

First, make sure fusion 360 support is enabled for the project (Settings -> Languaged & Frameworks -> Fusion 360 -> Fusion 360 Support Enabled).

Then Run->Attach to Process, and you should see the fusion process in the "Fusion 360 Processes" section

image

And then, when it attaches, this is the console output:

Public key hash: xxxxxxxx
Attaching to a process with PID=23044 and port=61572
Connected to pydev debugger (build 213.6777.50)

@NyxCode
Copy link
Author

NyxCode commented Mar 24, 2022

@JesusFreke
After I enter the hash in the Fusion popup, Fusion freezes and nothing happens in the debugger. The freeze is only resolved by restarting Fusion, stopping the debugger does not help.
Are there logs somewhere I could share with you?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants