Object match error when running a Python script from command line Maya

81 views
Skip to first unread message

Juan Pablo

unread,
Nov 16, 2016, 12:18:42 AM11/16/16
to Python Programming for Autodesk Maya

I have this script in Python which I'm running into a maya file from a command line:

import maya.standalone
maya.standalone.initialize("Python")
import maya.cmds as cmds
from maya import cmds
import maya.mel as mel
import glob


def importFile(i):
    cmds.file(i, i=True, groupReference=True, groupName="myobj")


def materialFile():
    if cmds.objExists('Panel*'):
        cmds.select("Panel*", replace=True)
        myMaterial = "BlueGlass"
        cmds.sets( e=True, forceElement= myMaterial + 'SG' ) 

    if cmds.objExists('Body*'):
        cmds.select("Body*", replace=True)
        myMaterial3 = "Silver"
        cmds.sets( e=True, forceElement= myMaterial3 + 'SG' )

But I get this error when I try to run the batch file:

File "/Users/../Scripts/MayaVectorScript.py", line 23, in materialFile
        cmds.sets( e=True, forceElement= myMaterial + 'SG' ) 
TypeError: No object matches name: BlueGlassSG

In the Hypershade, the shader BlueGlass is connected to a shader group (SG) with the same name BlueglassSG and the script works from the UI inside maya.

Do I need to load a plugin or something in the script to make it run in the batch file?

jonn

unread,
Nov 17, 2016, 10:36:46 PM11/17/16
to Python Programming for Autodesk Maya

subprocess ?
在 2016年11月16日星期三 UTC+8下午1:18:42,Juan Pablo写道:

Marcus Ottosson

unread,
Nov 18, 2016, 3:35:00 AM11/18/16
to python_in...@googlegroups.com

If you show us which commands you use, along with a complete example we could run on our end, it would make it a little easier pinpointing the problem for you.

For example, are you running it like this?

$ python my_script.py

Or like this?

$ maya my_script.py

Or like this?

$ mayapy my_script.py

And what does the scene look like, like this?

from maya import cmds
cmds.polyCube(name="BlueGlass")

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/53f3453e-e7c8-41fb-9d07-7114bd08f603%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Marcus Ottosson
konstr...@gmail.com

Juan Pablo

unread,
Dec 28, 2016, 5:07:18 AM12/28/16
to Python Programming for Autodesk Maya
I'm no running like any of the ways you show. 

I have a batch file like this:

"/Applications/Autodesk/maya2016/Maya.app/Contents/bin/mayapy" "/Users/MyComp/Documents/maya/projects/Test/New_Project/scripts/my_script.py" "/Users/MyComp/Documents/maya/projects/Test/New_Project/scenes/Simple-scene-script-test2.mb" "/Users/MyComp/Documents/maya/projects/Test/New_Project/images"

Where should I place these  $ python my_script.py or $ maya my_script.py or $ mayapy my_script.py commands? 


  "BlueGlass" is actually the shader. Now it's called "BlueDiamond" because the files are rings.

The problem is, it works inside maya but it doesn't work from the batch file it says the SG doesn't exist

Juan Pablo

unread,
Dec 28, 2016, 5:18:22 AM12/28/16
to Python Programming for Autodesk Maya
m no running like any of the ways you show. 

I have a batch file like this:

"/Applications/Autodesk/maya2016/Maya.app/Contents/bin/mayapy" "/Users/MyComp/Documents/maya/projects/Test/New_Project/scripts/my_script.py" "/Users/MyComp/Documents/maya/projects/Test/New_Project/scenes/Simple-scene-script-test2.mb" "/Users/MyComp/Documents/maya/projects/Test/New_Project/images"

Where should I place these  $ python my_script.py or $ maya my_script.py or $ mayapy my_script.py commands? 


  "BlueGlass" is actually the shader. Now it's called "BlueDiamond" because the files are rings.

The problem is, it works inside maya but it doesn't work from the batch file it says the SG doesn't exist






Reply all
Reply to author
Forward
0 new messages