* Please be careful about the article
Here, it is the content of the investigation to find out "how it actually works" for the functions and operations that are used as usual.
By knowing the mechanism, we will grasp the advantages and disadvantages, prevent troubles that occur in the future, and develop it into an expanded usage method.
It is just a memo of the personal survey. Please note that there may be mistakes and misunderstandings.
Recently (from June 2020) there have been some virus reports for maya. I think there are many people who have been affected. All of these ultimately follow the app behavior via data files. The script that runs at startup is userSetup.py. And userSetup.py is used as a method of normal personal / production environment setting even if it is not a virus story.
Until now, I have often focused on the side that uses it as a general operation, so I wanted to find out how userSetup.py works.
I used to think of it as a black box "somehow", but it's a very simple mechanism.
sys.userSetup under the folder of path.I'm running py with an execfile.
is. This is all.
The relevant .py files are located below.
C:\Program Files\Autodesk\Maya2008\Python\Lib\site-packages\maya\app\startup\basic.py
~
C:\Program Files\Autodesk\Maya2020\Python\Lib\site-packages\maya\app\startup\basic.py
If you extract the necessary parts, it will be as follows.
basic.py
def setupScriptPaths():
# ....abridgement....
# Per-version prefs scripts dir (eg .../maya8.5/prefs/scripts)
prefsDir = cmds.internalVar( userPrefDir=True )
sys.path.append( os.path.join( prefsDir, 'scripts' ) )
# Per-version scripts dir (eg .../maya8.5/scripts)
scriptDir = cmds.internalVar( userScriptDir=True )
sys.path.append( os.path.dirname(scriptDir) )
# User application dir (eg .../maya/scripts)
appDir = cmds.internalVar( userAppDir=True )
sys.path.append( os.path.join( appDir, 'scripts' ) )
def executeUserSetup():
# ....abridgement....
try:
for path in sys.path:
scriptPath = os.path.join( path, 'userSetup.py' )
if os.path.isfile( scriptPath ):
import __main__
execfile( scriptPath, __main__.__dict__ )
except Exception, e:
sys.stderr.write( "Failed to execute userSetup.py\n" )
sys.stderr.write( str( e ) )
These functions are called and executed from within basic.py (in recent versions batch.py gui.py).
basic.py
# ....abridgement....
# Set up sys.path to include Maya-specific user script directories.
setupScriptPaths()
if not os.environ.has_key('MAYA_SKIP_USERSETUP_PY'):
# Run the user's userSetup.py if it exists
executeUserSetup()
executeUserSetup () will not be executed if MAYA_SKIP_USERSETUP_PY is set in the environment variable
The details depend on your environment, but the folders are roughly as follows.
1. 1. Script folder in module path (plural)
2. Maya's python-based base folder (plural)
3. 3. User environment script folder (plural)
As a result of checking in the Maya 2018 environment at hand, it is as follows. (Excluding special ones)
sys.path confirmation code
import sys
for path in sys.path:
if not path:
continue
print (i)
Execution example
C:\Program Files\Autodesk\Maya2018\plug-ins\ATF\scripts
C:\Program Files\Autodesk\Maya2018\plug-ins\MASH\scripts
C:\Program Files\Autodesk\Maya2018\plug-ins\fbx\scripts
C:\Program Files\Autodesk\Maya2018\plug-ins\camd\scripts
C:\solidangle\mtoadeploy\2018\scripts
C:\Program Files\Autodesk\Maya2018\plug-ins\substance\scripts
C:\Program Files\Autodesk\Maya2018\plug-ins\xgen\scripts
C:\Program Files\Autodesk\Maya2018\bin\python27.zip
C:\Program Files\Autodesk\Maya2018\Python\DLLs
C:\Program Files\Autodesk\Maya2018\Python\lib
C:\Program Files\Autodesk\Maya2018\Python\lib\plat-win
C:\Program Files\Autodesk\Maya2018\Python\lib\lib-tk
C:\Program Files\Autodesk\Maya2018\bin
C:\Program Files\Autodesk\Maya2018\Python
C:\Program Files\Autodesk\Maya2018\Python\lib\site-packages
C:\Program Files\Autodesk\Maya2018\bin\python27.zip\lib-tk
C:/Users/rdj/Documents/maya/2018/prefs/scripts
C:/Users/rdj/Documents/maya/2018/scripts
C:/Users/rdj/Documents/maya/scripts
It seems that you need to pay attention to the following.
1.userSetup.The execution order of py is sys.in path order
2.Documents/maya/userSetup in the user folder such as scripts.py is not a special treatment
To the last sys.userSetup at path.Running alongside the others as one of the py
3. 3. A python script is running in execfile
The mechanism is open to the public for both good and problematic parts, which is amazing. .. ..
Recommended Posts