My API script won't run with imported modules?

My API script won't run with imported modules?

esumft
Advocate Advocate
866 Views
4 Replies
Message 1 of 5

My API script won't run with imported modules?

esumft
Advocate
Advocate

I've tried to import some additional modules into an API script, but when I run in Fusion it doesn't run the script? I have a feeling this is to do with relative imports, but I find it confusing about what I need to put where for using that.

 

import adsk.core, adsk.fusion, adsk.cam, traceback, time, os, serial
0 Likes
867 Views
4 Replies
Replies (4)
Message 2 of 5

marcinszydlowski.1984
Enthusiast
Enthusiast

All dependent modules must be inside your plugin/script directory. Assuming such structure:

plugindir
 ├ Modules
 │  └ SomeUtils.py
 └ somethingmaker.py

You need to include imports as relative paths (it doesn't work as global in F360) in somethingmaker.py:

import adsk.core, adsk.fusion, ...
from .Modules import SomeUtils  # custom modules here

 

Message 3 of 5

esumft
Advocate
Advocate

It's an odd one because this is my structure:

plugindir
 ├ Modules
 │  └ Second.py
 └ Main.py

 

In main.py:

 

from .Modules import Second

 

This returns the error in VS code, Fusion just doesn't run the addin:

 

Attempted relative import beyond top-level packagepylint(relative-beyond-top-level)

 

0 Likes
Message 4 of 5

marcinszydlowski.1984
Enthusiast
Enthusiast

Script which needs to be run as an addin should contain *.manifest file. I've prepared two test plugins - one as a script and another as a plugin.

Script must be added in the first tab of the "Scripts and Add-Ins" window:

Screenshot_10.png

Then choose a directory with the script.

 

Plugin as addin must be added in the second tab (also choose the folder):

Screenshot_11.png

When you run the plugin, you should see its icon in the bottom of "SOLID" space "CREATE" panel.

 
 

Both zips contains nearly the same code which uses custom module. Main differences between the script and the plugin are:

- script has "DestroyHandler" whereas addin "stop(context)" method,

- script is executed (command is created) immediately in the "run(context)" method,

- addin uses *.manifest file with the same name as the ONLY script in the folder,

- command created in addin must be added to the interface - "run(context)" method.

 

If you want to create plugins and put them to the store, remember to attach *.pyc files of your modules, otherwise, they will be created in the runtime and during uninstallation they won't be deleted.

 

 

 

0 Likes
Message 5 of 5

esumft
Advocate
Advocate

Thanks for your reply and for the examples! I'm still struggling to see what the link is to my relative import problem?

0 Likes