Python import command, for a file in a subfolder

Python import command, for a file in a subfolder

grendizerus
Enthusiast Enthusiast
2,028 Views
2 Replies
Message 1 of 3

Python import command, for a file in a subfolder

grendizerus
Enthusiast
Enthusiast

Hello, in my Documents\Maya\scripts folder, I have a python file called "rr_main_curves.py".

To start this script, in Maya, I paste these 2 lines of code and then I run the script:

import rr_main_curves
rr_main_curves.window_creation()

 

But now, I want to put this script and all attached scripts in a subfolder of Documents\Maya\scripts : this subfolder would be called "RigBox".

 

So that's what I did, but now my "import" command does not work. I tried many things but they don't work:

import RigBox/rr_main_curves

import RigBox\rr_main_curves

import ./RigBox/rr_main_curves

import .\RigBox\rr_main_curves

 

HELP!!

Thanks 🙂

DS

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

Kahylan
Advisor
Advisor
Accepted solution

Hi!

 

If RigBox is in your script folder you should be able to import it using:

import RigBox.rr_main_curves

Unless you are in a Maya version prior to 2022, in which case the normal import command should work since Python 2.7 doesn't need the sub directory if there is only one module in the scripts folder with this name.

 

I hope this helps!

0 Likes
Message 3 of 3

grendizerus
Enthusiast
Enthusiast

amazing! thanks!

I do have many module in the scripts folder , many *.py files linked to the main one.

0 Likes