Basic Python Scripting Help

Basic Python Scripting Help

Anonymous
Not applicable
1,282 Views
4 Replies
Message 1 of 5

Basic Python Scripting Help

Anonymous
Not applicable

Hello, I'm fairly new to using Maya 2016 and I need some help regarding two things:

 

1) In a Python script, how would you write it so that you could just run the script from terminal (on Mac) and have a newly created maya file without ever having to have opened Maya?

 

2) How do you create a file texture/shader and apply it to an object in your scene through Python?

Any help would be appreciated. Thank You

0 Likes
1,283 Views
4 Replies
Replies (4)
Message 2 of 5

morten_bohne
Advocate
Advocate

The easiest way is probably mayapy: http://help.autodesk.com/cloudhelp/2016/CHS/Maya-Tech-Docs/PyMel/standalone.html

and:

http://help.autodesk.com/cloudhelp/2016/CHS/Maya-Tech-Docs/PyMel/install.html#install-system-env

 

you might also want to look into setting up an environment variable called PYMEL_SKIP_MEL_INIT

 

Don't remember the details, but i think i ran in to some crashes when maya standalone tried to pre-load some melscripts and then pymel choking on them, but setting that environment variable fixed that

0 Likes
Message 3 of 5

morten_bohne
Advocate
Advocate

made this quick example, that creates a cube, assigns a red lambert, and saves it in your userWorkspaceDir as shadedCube.mb

Hope it helps:

 

http://mortenbohne.dk/maya/python_examples/mayapy_create_red_cube.py

0 Likes
Message 4 of 5

Anonymous
Not applicable

Hmm this doesn't seem to be working. This what I get when I run the code:

 

 

 

Initialized VP2.0 renderer {

  Version : 6.3.1.0. Feature Level 3.1.

  Adapter : NVIDIA GeForce GT 650M OpenGL Engine

  Vendor ID: 4318. Device ID : 0xFD5

  Driver : 2.1 NVIDIA-10.17.5 355.10.05.45f01.

  API : OpenGL V.2.1.

  Max texture size : 16384 * 16384.

  Max tex coords : 8

  Shader versions supported (Vertex: 3, Geometry: 3, Pixel 3).

  Shader compiler profile : (Best card profile)

  Active stereo support available : 0

  GPU Memory Limit : 1024 MB.

  CPU Memory Limit: 15564.8 MB.

###############################################################################

Begin attempted read of a script fragment XML file.

Attempting to read fragment XML code from: mayaSimpleBlitScript.xml

Errors loading XML:

-------------------------------------------------------------------------------

Could not find file: mayaSimpleBlitScript.xml

-------------------------------------------------------------------------------

End attempted read of fragment XML.

###############################################################################

###############################################################################

Begin attempted read of a script fragment XML file.

Attempting to read fragment XML code from: mayaSimpleTextureBlitScript.xml

Errors loading XML:

-------------------------------------------------------------------------------

Could not find file: mayaSimpleTextureBlitScript.xml

-------------------------------------------------------------------------------

End attempted read of fragment XML.

###############################################################################

}

OpenCL evaluator is attempting to initialize OpenCL.

Detected 1 OpenCL Platforms:

0: Apple. Apple. OpenCL 1.2 (Apr  4 2017 19:07:42).

Supported extensions: cl_APPLE_SetMemObjectDestructor cl_APPLE_ContextLoggingFunctions cl_APPLE_clut cl_APPLE_query_kernel_names cl_APPLE_gl_sharing cl_khr_gl_event

OpenCL evaluator choosing OpenCL platform Apple.

1095

Choosing OpenCL Device GeForce GT 650M.  Device Type: GPU  Device is available.

OpenCL device does not support out of order execution

 

Error: file: /Applications/Autodesk/maya2016/plug-ins/xgen/scripts/igInitialize.mel line 63: ImportError: file <maya console> line 1: No module named xgenm

Error: Unable to execute igInitialize.mel.

Unable to execute igInitialize.mel.Error: line 0: ImportError: file <maya console> line 1: No module named xgenm

Error: Unable to execute xgen.mel.

Unable to execute xgen.mel.xgmNurbsPatch [u'containerBase', u'entity', u'dagNode', u'shape', u'geometryShape', u'deformableShape', u'controlPoint', u'surfaceShape', u'THsurfaceShape', u'xgmPatch', u'containerBase', u'entity', u'dagNode', u'shape', u'geometryShape', u'deformableShape', u'controlPoint', u'surfaceShape', u'THsurfaceShape', u'xgmNurbsPatch']

pymel.internal.apicache : WARNING : lineage for node xgmNurbsPatch is cyclical: [u'containerBase', u'entity', u'dagNode', u'shape', u'geometryShape', u'deformableShape', u'controlPoint', u'surfaceShape', u'THsurfaceShape', u'xgmPatch', u'containerBase', u'entity', u'dagNode', u'shape', u'geometryShape', u'deformableShape', u'controlPoint', u'surfaceShape', u'THsurfaceShape', u'xgmNurbsPatch']

xgmSubdPatch [u'containerBase', u'entity', u'dagNode', u'shape', u'geometryShape', u'deformableShape', u'controlPoint', u'surfaceShape', u'THsurfaceShape', u'xgmPatch', u'containerBase', u'entity', u'dagNode', u'shape', u'geometryShape', u'deformableShape', u'controlPoint', u'surfaceShape', u'THsurfaceShape', u'xgmSubdPatch']

pymel.internal.apicache : WARNING : lineage for node xgmSubdPatch is cyclical: [u'containerBase', u'entity', u'dagNode', u'shape', u'geometryShape', u'deformableShape', u'controlPoint', u'surfaceShape', u'THsurfaceShape', u'xgmPatch', u'containerBase', u'entity', u'dagNode', u'shape', u'geometryShape', u'deformableShape', u'controlPoint', u'surfaceShape', u'THsurfaceShape', u'xgmSubdPatch']

xgmArchiveGuide [u'containerBase', u'entity', u'dagNode', u'shape', u'geometryShape', u'deformableShape', u'controlPoint', u'surfaceShape', u'THsurfaceShape', u'xgmGuide', u'containerBase', u'entity', u'dagNode', u'shape', u'geometryShape', u'deformableShape', u'controlPoint', u'surfaceShape', u'THsurfaceShape', u'xgmArchiveGuide']

pymel.internal.apicache : WARNING : lineage for node xgmArchiveGuide is cyclical: [u'containerBase', u'entity', u'dagNode', u'shape', u'geometryShape', u'deformableShape', u'controlPoint', u'surfaceShape', u'THsurfaceShape', u'xgmGuide', u'containerBase', u'entity', u'dagNode', u'shape', u'geometryShape', u'deformableShape', u'controlPoint', u'surfaceShape', u'THsurfaceShape', u'xgmArchiveGuide']

xgmCardGuide [u'containerBase', u'entity', u'dagNode', u'shape', u'geometryShape', u'deformableShape', u'controlPoint', u'surfaceShape', u'THsurfaceShape', u'xgmGuide', u'containerBase', u'entity', u'dagNode', u'shape', u'geometryShape', u'deformableShape', u'controlPoint', u'surfaceShape', u'THsurfaceShape', u'xgmCardGuide']

pymel.internal.apicache : WARNING : lineage for node xgmCardGuide is cyclical: [u'containerBase', u'entity', u'dagNode', u'shape', u'geometryShape', u'deformableShape', u'controlPoint', u'surfaceShape', u'THsurfaceShape', u'xgmGuide', u'containerBase', u'entity', u'dagNode', u'shape', u'geometryShape', u'deformableShape', u'controlPoint', u'surfaceShape', u'THsurfaceShape', u'xgmCardGuide']

xgmSphereGuide [u'containerBase', u'entity', u'dagNode', u'shape', u'geometryShape', u'deformableShape', u'controlPoint', u'surfaceShape', u'THsurfaceShape', u'xgmGuide', u'containerBase', u'entity', u'dagNode', u'shape', u'geometryShape', u'deformableShape', u'controlPoint', u'surfaceShape', u'THsurfaceShape', u'xgmSphereGuide']

pymel.internal.apicache : WARNING : lineage for node xgmSphereGuide is cyclical: [u'containerBase', u'entity', u'dagNode', u'shape', u'geometryShape', u'deformableShape', u'controlPoint', u'surfaceShape', u'THsurfaceShape', u'xgmGuide', u'containerBase', u'entity', u'dagNode', u'shape', u'geometryShape', u'deformableShape', u'controlPoint', u'surfaceShape', u'THsurfaceShape', u'xgmSphereGuide']

xgmSplineGuide [u'containerBase', u'entity', u'dagNode', u'shape', u'geometryShape', u'deformableShape', u'controlPoint', u'surfaceShape', u'THsurfaceShape', u'xgmGuide', u'containerBase', u'entity', u'dagNode', u'shape', u'geometryShape', u'deformableShape', u'controlPoint', u'surfaceShape', u'THsurfaceShape', u'xgmSplineGuide']

pymel.internal.apicache : WARNING : lineage for node xgmSplineGuide is cyclical: [u'containerBase', u'entity', u'dagNode', u'shape', u'geometryShape', u'deformableShape', u'controlPoint', u'surfaceShape', u'THsurfaceShape', u'xgmGuide', u'containerBase', u'entity', u'dagNode', u'shape', u'geometryShape', u'deformableShape', u'controlPoint', u'surfaceShape', u'THsurfaceShape', u'xgmSplineGuide']

AbcExport v1.0 using Alembic 1.5.4 (built May  9 2014 15:43:11)

AbcImport v1.0 using Alembic 1.5.4 (built May  9 2014 15:43:11)

BifrostMain plug-in loaded (built Feb 26 2015 18:00:13)

Error: file: /Applications/Autodesk/maya2016/Maya.app/Contents/bin/../scripts/startup/autoLoadPlugin.mel line 46: ImportError: file /Applications/Autodesk/maya2016/plug-ins/xgen/plug-ins/xgenMR.py line 9: No module named xgenm

Warning: file: /Applications/Autodesk/maya2016/Maya.app/Contents/bin/../scripts/startup/autoLoadPlugin.mel line 46: Failed to run file: /Applications/Autodesk/maya2016/plug-ins/xgen/plug-ins/xgenMR.py

pymel : ERROR : Failed to get controlCommand list from xgenMR

pymel : ERROR : Failed to get modelEditorCommand list from xgenMR

pymel : ERROR : Failed to get command list from xgenMR

pymel : ERROR : Failed to get constraintCommand list from xgenMR

pymel.core : ERROR : Failed to get depend nodes list from xgenMR

Error: file: /Applications/Autodesk/maya2016/Maya.app/Contents/bin/../scripts/startup/autoLoadPlugin.mel line 46:  (xgenMR)

0 Likes
Message 5 of 5

morten_bohne
Advocate
Advocate

woops my mistake, I accidentally set it to save the the file directly to your default workspace directory (on mac i think would be something like: Users/Shared/Autodesk/maya/projects) instead of the scenes-folder in your current workspace. As far as i can see, there's nothing in the log you posted that has caused it to crash before saving the file, so it should be there somewhere 😉

But of cause you should try to get rid of those errors

 

 

 

By default, in a standalone interpreter, pymel will attempt to do a full initialization of your MEL environment, such
as sourcing userPrefs.mel, pluginPrefs.mel, and userSetup.mel.
If this is undesirable, uncomment this option.  Alternately, you can set the environment variable PYMEL_SKIP_MEL_INIT
to any value.

 

 

So setting an environment-variable named PYMEL_SKIP_MEL_INIT to 1 should fix the errors. (Or you could just unload the xgen plugin causing the problem, and only load it if it's needed)

0 Likes