Python Modules and Maya


#43

The second suggestion worked. I didn’t look in the init.py; learned something new, as well as how to find little issues, hopefully when running python scripts :slight_smile:


#44

How do I add my series of custom maya environment variables to the userSetup.py so I can cease to use Maya.env.

I assume, when updating Maya, you can simply toss the userSetup.py file into the default path for Maya; or a custom MAYA_APP_DIR path and all environment variables and shelves are setup, instantly ?

That is hoping you can also cease to use the system environment variable MAYA_APP_DIR and place that as well into the userSetup.py file, as you mentioned you use a batch script.


#45

You are kidding to me, aren’t you? We already told you how to set environment variables with python.


#46

Calm down, I haven’t dug into it :slight_smile:


#47

Concerning your problem with the NSUV (night shade uv editor):

Instead of placing the scritps directly into your scripts directory, you placed them in your own path.
This results in a few problems:

1.) the preferences files. Maya expect them in the default locations, e.g. in your documents/maya/Maya2016 directory. They will not be fount if they are placed elsewhere (unless you change some environment variables).

2.) The mel scripts. They are expected in a path like scripts/NSUV. So if you have aen extra scripts path called “c:/myscripts”, all scripts (mel an py) have to be placed in “c:/myscripts/NSUV”.

I’d suggest to place the prefs in your default prefs folder and set the python path as shown above. Then it works.


#48

1.) the preferences files. Maya expect them in the default locations, e.g. in your documents/maya/Maya2016 directory. They will not be fount if they are placed elsewhere (unless you change some environment variables).

The preferences folder within the NSUV compressed file; contains a sub-folder of only icons. As I have a custom icons folder in my, Maya.env file, why can’t I place those icons in the custom icon folder, as I’ve done and have them work or within a custom path such as C:\myscripts\NSUV\icons ?

2.) The mel scripts. They are expected in a path like scripts/NSUV. So if you have aen extra scripts path called “c:/myscripts”, all scripts (mel an py) have to be placed in “c:/myscripts/NSUV”.

I’ve tried placed NSUV within a custom scripts & python path, not both at the same time. Within the NSUV folder structure this is how it’s exists whether it was placed in my custom scripts or custom python path; c:\myscript\NSUV
\icons
\panel <MEL files
\scripts\NSUV <strictly python files.

Here is the current error I get when running NSUV from a custom scripts path

# Error: ImportError: file <maya console> line 1: No module named NSUV # 

This is the error I get when run from a custom python path;

// Error: source "NSUV/panel.mel"; // 
// Error: Line 1.24: Cannot find file "NSUV/panel.mel" for source statement. // 
# Error: MelError: file C:\Program Files\Autodesk\Maya2015\Python\lib\site-packages\pymel\core\language.py line 835: Error during execution of MEL script: source "NSUV/panel.mel";
Line 1.24: Cannot find file "NSUV/panel.mel" for source statement.
Script:
  source "NSUV/panel.mel"; # 

#49

Indeed, if you only need icons, Maya can find them in any path with the correct environment variable.

There is no reason to seperate the scripts into mel and python files. Especially if you do not know how the python files accesses the mel files. Your approach cannot work unless you modify content of the python files.

Sorry, but the whole thing is really simple:

Extract the NSUV zip file into a directory.
Set the python search path (for python files) and the maya scripts path (for mel files) correctly, import the NSUV, form the popping up window create a shelf button - done.

And meanwhile after the whole discussion, you should know what that means:

# Error: ImportError: file <maya console> line 1: No module named NSUV # 

You simply set the path wong or the import.


#50

I didn’t understand what you meant. This is how I want it, and what I want to know is the way I want it, is it possible strictly speaking of this script or impossible; and if it’s possible what am I doing wrong ? It may be simple, but until I understand, it’s not simple.

Going back a few steps; I have a custom python path; c:\ or c:/myscripts/NSUV within the NSUV sub-folder the follow sub-folders exist:

  • icons
  • panel
  • scripts

Remember we are strictly talking about this one script. When I run the command import NSUV I get the following error;

// Error: source "NSUV/panel.mel"; // 
// Error: Line 1.24: Cannot find file "NSUV/panel.mel" for source statement. // 
# Error: MelError: file C:\Program Files\Autodesk\Maya2015\Python\lib\site-packages\pymel\core\language.py line 835: Error during execution of MEL script: source "NSUV/panel.mel";
Line 1.24: Cannot find file "NSUV/panel.mel" for source statement.

I want to run the script in the path mentioned above, not in Maya default script path etc. I read your second last and last post a few times and I couldn’t extract what you’re saying, one example is;

2.) The mel scripts. They are expected in a path like scripts/NSUV. So if you have aen extra scripts path called “c:/myscripts”, all scripts (mel an py) have to be placed in “c:/myscripts/NSUV”.

And that is exactly what my path is setup as for the script files, but it is not working.


#51

Set the python serach path to “c:/myscripts/NSUV” and set the mel search path to “c:/myscripts/NSUV”. That’s all, really.


#52

Son of a :banghead:
I appended the paths for NSUV in userSetup.py for both Python & MEL, I’m getting the error; # Error: ImportError: file <maya console> line 1: No module named NSUV # but the paths are correct. Considering the scripts are located in c:\myscripts\NSUV\scripts I added the sub-folder “scripts” but I continue to get the No module named NSUV, :argh:


#53

And in your “scripts” folder exists another folder called NSUV?

NSUV/scripts/NSUV

If so, I can’t help any more. It works fine here.


#54

NOT this:

Do this:

And stop using the backslash all the time. This \ is BAD… This / is good.

If it works for haggi and you have the same scripts then the error is your path setting, no matter how many times you tell us it is not. :banghead:

David


#55

I wrote backslashes in the forum, but in the Python search path I’m using forward slashes. I appended the Python search path with the NSUV path which is; c:\myscripts\program\python\NSUV. Restarted Maya, and now, not only does NSUV continue not to work, but all my Python scripts don’t work ?


#56

Well, I suppose you did not add the path but set it. Your userSetup.py should look like this:

import sys
sys.path.append("c:/myscripts/program/python/NSUV")

import os
os.environ["MAYA_SCRIPT_PATH"] += ";c:/myscripts/program/python/NSUV"

#57

I can’t append a new path with a semi-colon as in.

import sys
sys.path.append('C:/myscripts/program/maya/python/";‘C:/myscripts/program/maya/nsuv’)

My “MAYA_SCRIPT_PATH” is set as ENV = “MAYA_SCRIPT_PATH” for MEL scripts, not Python.


#58

C:\scripts\maya\pythonscript\NSUV

within this folder structure exists;

-icons
-panels
-scripts

In other words;

C:\scripts\maya\pythonscript\NSUV\icons
C:\scripts\maya\pythonscript\NSUV\panels
C:\scripts\maya\pythonscript\NSUV\scripts


#59

This:

is nonsense. It has the wrong syntax.
sys.path is a list. You can add elements to a list with append(x). If you want to add multiple paths, do this:

sys.path.append('C:/myscripts/program/maya/python')
sys.path.append('C:/myscripts/program/maya/nsuv')

Yes, and that’s exactly why the NSUV mel scripts cannot be found in your setup. As you may have seen, the NSUV directory contains mel scripts and python scripts. If you want to access the mel scripts for this tool correctly then the MAYA_SCRIPT_PATH has to be extended to the directory above the NSUV directory (above the one which contains the mel scripts because the mel scripts are loaded like this “source NSUV/xxx.mel”).


#60
import sys
sys.path.append("C:/scripts/maya/pythonscript/NSUV/scripts")
import os
os.environ["MAYA_SCRIPT_PATH"] += ";C:/scripts/maya/pythonscript/NSUV/scripts"


#61

Alright, let me try this.


#62

Well, simply set the paths as I wrote in my last post. It should work. Ah… too late, I wrote it before your last posting. Yes, please try it.