Relative Import is broken? Python API

Relative Import is broken? Python API

ryan27XKQ
Explorer Explorer
907 Views
3 Replies
Message 1 of 4

Relative Import is broken? Python API

ryan27XKQ
Explorer
Explorer

Hey Everyone, I'm wanting to split my add-in into multiple modules for organization purposes. I've used relative imports as suggested in every single post I could find on importing modules into an addin/script, and VS Code is able to resolve the imports properly, however, when I run the add-in in Fusion it doesn't work unless all of the code I've written is in the Test.py file that was created when I created the Add-in through Fusion. I'm kind of lost here, and I hope that someone will be able to help me figure out what's going on.

I have two PATH system variables on my system for some reason, they are as follows:

%AppData%\Roaming\Autodesk\Autodesk Fusion 360\API\Python\defs

%AppData%\Roaming\Autodesk\Autodesk Fusion 360\API\AddIns

 

Below is a screenshot of VSCode

RelativeImport.PNG

 
0 Likes
908 Views
3 Replies
Replies (3)
Message 2 of 4

kandennti
Mentor
Mentor

Hi @ryan27XKQ .

 

It was not clear from the image alone.

I tried it here, and was able to call it.


I've attached the add-in I tested.

Message 3 of 4

ryan27XKQ
Explorer
Explorer

Accidentally replied to the post and not kandennti

0 Likes
Message 4 of 4

ryan27XKQ
Explorer
Explorer

Alright, so from what I understand after perusing your code, it looks like every single module must have a function that instantiates objects you intend to use and that the API does not allow for the instantiation of objects in your Test.py file that were imported from another file. Honestly that seems like a major limitation on how add-ins can be written and will prevent me from using many modules, packages, and libraries.

0 Likes