Accessing Renderman Attributes From Python

501 views
Skip to first unread message

sahasranaman

unread,
Jul 21, 2008, 9:37:52 AM7/21/08
to python_inside_maya
Hi

Is it possible to add RenderMan attributes like Subdiv Scheme
(rman__torattr___subdivScheme) to objects through Maya Python or MEL??
I tried googling, but I couldn't find anything helpful

Thanks

Sahasranaman

Chadrik

unread,
Jul 21, 2008, 8:17:08 PM7/21/08
to python_inside_maya

take a look at the addAttr command under in maya's mel command
documentation

kurian os ™ ®കോപ്പിയടിച്ചാല്©ഗോതമ്പുണ്ട!

unread,
Jul 22, 2008, 3:20:37 AM7/22/08
to python_in...@googlegroups.com
code

catch( `addAttr -ln "rman__torattr___subdivScheme" -nn "Subdivision Scheme" -at "enum" -en "Catmull-Clark:Loop:None:" objectShape` );
--
സ്നേഹിക്കയില്ല ഞാന്‍
നോവുമാത്മാവിനെ സ്നേഹിച്ചിടാത്തൊരു
തത്വശാസ്ത്രത്തെയും

Olivier Renouard

unread,
Jul 22, 2008, 3:30:57 AM7/22/08
to python_in...@googlegroups.com

Sahasranaman M S

unread,
Jul 21, 2008, 11:26:14 PM7/21/08
to python_in...@googlegroups.com
Well thanks for the reply, Chad. the addAttr method can add only maya
attributes right? Or can it add attributes to plugins too? If yes, is
there a special usage? RenderMan for Maya is a maya plugin, and i'm
not sure how to add attributes to that


--
Sahasranaman
http://sahasranaman.com

sahasranaman

unread,
Jul 22, 2008, 12:31:45 AM7/22/08
to python_inside_maya
Well thanks for the reply, Chad. the addAttr method can add only maya
attributes right? Or can it add attributes to plugins too? If yes, is
there a special usage? RenderMan for Maya is a maya plugin, and i'm
not sure how to add attributes to that

sahasranaman

unread,
Jul 22, 2008, 12:23:16 AM7/22/08
to python_inside_maya
Well thanks for the reply, Chad. the addAttr method can add only maya
attributes right? Or can it add attributes to plugins too? If yes, is
there a special usage? RenderMan for Maya is a maya plugin, and i'm
not sure how to add attributes to that

On Jul 22, 5:17 am, Chadrik <chad...@gmail.com> wrote:

John Creson

unread,
Jul 22, 2008, 4:46:08 PM7/22/08
to python_in...@googlegroups.com
addAttr adds attributes to nodes, it doesn't mind if the nodes were
created by plugins.

Sahasranaman M S

unread,
Jul 23, 2008, 2:05:36 AM7/23/08
to python_in...@googlegroups.com

Ok. I figured out this much:

In MEL, to add the Subdiv Scheme Renderman attribute, all we have to do is this:

if( !`attributeExists "rman__torattr___subdivScheme" $shape` )
{
string $cmd = ("rman addAttr \"" + $shape + "\" \"rman__torattr___subdivScheme\"");
eval($cmd);
}

In Python for Maya, I'm not able to figure out how to use the rman() method:

I tried the following, none of which worked:

1)

from maya import cmds
cmds.rman('addAttr "objectShape" "rman__torattr___subdivScheme"')

This gave me an error saying that the argument to rman() was invalid.

2)

from maya import cmds
cmds.rman('addAttr', "objectShape", "rman__torattr___subdivScheme")

3)

from maya import cmds
cmds.select("object")
cmds.rman('addAttr', "\"objectShape\" \"rman__torattr___subdivScheme\"")

4)

from maya import cmds
cmds.select("object")
cmds.rman('addAttr', "objectShape rman__torattr___subdivScheme")

5)

from maya import cmds
cmds.select("object")
cmds.rman("addAttr", "rman__torattr___subdivScheme")

The second to the fifth attempts didn't give error messages but didn't work either. And I'm not able to get any documentation for the maya.cmds.rman() method. I tried cmds.rman('render') and it worked, but complex commands don't seem to work.

Could someone tell me how to translate the mel code into python?




2008/7/22 Olivier Renouard <o.ren...@attitude-studio.com>:



--
Samuel Goldwyn  - "I don't think anyone should write their autobiography until after they're dead."

Olivier Renouard

unread,
Jul 23, 2008, 6:06:12 AM7/23/08
to python_in...@googlegroups.com
Hi,

I think the problem is that setting environment variables like LD_LIBRARY_PATH will only affect subprocesses.

So you need to spawn a subprocess after doing so.

Here is an example of running Maya from and with the external interpreter (only know about Linux way of doing so ) :

First you should have the following in a file named "sub.py" in a place python can find it (where you started python from or in PYTHONPATH)

sub.py :

import os, sys
print "Python version:", sys.version
print "LD_LIBRARY_PATH:", os.environ['LD_LIBRARY_PATH']
print "sys.path:", sys.path
try :
    import maya.standalone
    maya.standalone.initialize()
    print "maya is up!"
    import maya.cmds as cmds
    cmds.select(cmds.polySphere())
    print cmds.ls(selection=True)
except :
    print "mayainit failed"
exit()

Then start a python shell and type :

Python 2.5.2 (r252:60911, May  7 2008, 15:21:12)
[GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import os, sys, subprocess
>>> os.environ['LD_LIBRARY_PATH'] = '/usr/autodesk/maya2008-x64/lib/'
>>> os.environ['PYTHONHOME']='/usr/lib/python2.5'
>>> os.environ['PYTHONPATH']='/usr/autodesk/maya2008-x64/lib/python2.5:/usr/autodesk/maya2008-x64/lib/python25.zip:/usr/autodesk/maya2008-x64/lib/python2.5/lib-dynload:/usr/autodesk/maya2008-x64/lib/python2.5/site-packages'
>>> sub =  subprocess.Popen(['python', 'sub.py'], stdout=sys.stdout, stderr=sys.stdout)
>>> Python version: 2.5.2 (r252:60911, May  7 2008, 15:21:12)
[GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)]
LD_LIBRARY_PATH: /usr/autodesk/maya2008-x64/lib/
sys.path: ['/home/orenouard', '/usr/autodesk/maya2008-x64/lib/python2.5', '/usr/autodesk/maya2008-x64/lib/python25.zip', '/usr/autodesk/maya2008-x64/lib/python2.5/lib-dynload', '/usr/autodesk/maya2008-x64/lib/python2.5/site-packages', '/usr/lib/python2.5/lib/python25.zip', '/usr/lib/python2.5/lib/python2.5', '/usr/lib/python2.5/lib/python2.5/plat-linux2', '/usr/lib/python2.5/lib/python2.5/lib-tk', '/usr/lib/python2.5/lib/python2.5/lib-dynload']
maya is up!
[u'pSphere1', u'polySphere1']

>>>

Note : sys.path += ['whatever'] would do no good in the caller process as it won't be carried over, you can do it in the child process though before importing any maya module.

There were minor compatibility issues when using an external interpreter instead of Maya's one (especially since Ubuntu bumped it from 2.5.1. to 2.5.2), but nothing big. Maya's own interpreter has its own quirks like the inability to import md5 unless some library links are provided, Chad posted a solution some time ago on that list.

Now you can also spawn Maya's own standalone interpreter directly (all that the autodesk mayapy shell script does is setting the env var for you), so that you actually run in Maya's provided Python version :

Python 2.5.2 (r252:60911, May  7 2008, 15:21:12)
[GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import os, sys, subprocess
>>> os.environ['LD_LIBRARY_PATH'] = '/usr/autodesk/maya2008-x64/lib/'
>>> os.environ['PYTHONHOME']='/usr/autodesk/maya2008-x64/lib/python2.5'
>>> os.environ['PYTHONPATH']='/usr/lib/python2.5:/usr/lib/python2.5/site-packages'
>>> sub =  subprocess.Popen(['/usr/autodesk/maya2008-x64/bin/python-bin', 'sub.py'], stdout=sys.stdout, stderr=sys.stdout)
>>> Python version: 2.5.1 (r251:54863, Jun  5 2007, 12:01:59)
[GCC 4.1.2]
LD_LIBRARY_PATH: /usr/autodesk/maya2008-x64/lib/
sys.path: ['/home/orenouard', '/usr/lib/python2.5', '/usr/lib/python2.5/site-packages', '/usr/autodesk/maya2008-x64/lib/python2.5/lib/python25.zip', '/usr/autodesk/maya2008-x64/lib/python2.5/lib/python2.5', '/usr/autodesk/maya2008-x64/lib/python2.5/lib/python2.5/plat-linux2', '/usr/autodesk/maya2008-x64/lib/python2.5/lib/python2.5/lib-tk', '/usr/autodesk/maya2008-x64/lib/python2.5/lib/python2.5/lib-dynload', '/usr/local/lib/python2.5/site-packages']
maya is up!
[u'pSphere1', u'polySphere1']

>>>

Here the PYTHONPATH is used the other way round, to add the standard system /usr/lib/python2.5/site-packages to path so that you can import external extension in Maya's interpreter for instance

Of course both these are the same as doing it from a shell, it's just if you want to run that from an already running python script / session. I'ts actually easier to set LD_LIBRARY_PATH / PYTHONHOME / PYTHONPATH before calling a python interpreter as you can avoid the need to spawn a sub process :

orenouard@newhon:~$ export LD_LIBRARY_PATH='/usr/autodesk/maya2008-x64/lib/'; python
Python 2.5.2 (r252:60911, May  7 2008, 15:21:12)
[GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import maya.standalone
>>> maya.standalone.initialize()
>>>


I guess there should be a way to correctly redirect the stdin and stdout of the subprocess to be able to get an interractive shell on the subprocess but didn't find it...

Olivier
-- 
Olivier Renouard

Olivier Renouard

unread,
Jul 23, 2008, 6:09:24 AM7/23/08
to python_in...@googlegroups.com
Sorry that was meant to be a reply to [Maya-Python Club:903] Re: maya.standalone doesn't fill maya env vars, replied to the wrong thread

Olivier Renouard wrote:
-- 
Olivier Renouard
  




-- 
Olivier Renouard

katrin schmid

unread,
Jul 24, 2008, 11:58:01 AM7/24/08
to python_in...@googlegroups.com
hi,
i am a bit puzzled about the absence of "attribute exists" in maya.cmds.
It is neither in the docs nor does maya understand.
I want to check if nodes have a custom attribute or not.
Do i miss something here?
Best Regards,
katrin

--
Psssst! Schon das coole Video vom GMX MultiMessenger gesehen?
Der Eine für Alle: http://www.gmx.net/de/go/messenger03

katrin schmid

unread,
Jul 24, 2008, 12:01:29 PM7/24/08
to python_in...@googlegroups.com
ah,
just discovered attributeQuery, nevermind....
--
GMX Kostenlose Spiele: Einfach online spielen und Spaß haben mit Pastry Passion!
http://games.entertainment.gmx.net/de/entertainment/games/free/puzzle/6169196

Adam Cobabe

unread,
Jul 25, 2008, 2:05:11 AM7/25/08
to python_in...@googlegroups.com
cmds.objExists(obj + '.attr')
Reply all
Reply to author
Forward
0 new messages