current status: Scientific Coder at Weta Digital
 
 
knowledge sharing
if you want to share or comment, send me an email
prman.Init() within Maya
a python pill by Paolo Emilio Selva
As many of you probably knows, Pixar Renderman 15 comes with a python interface which allows users to create rendering pipelines directly in python.
It's pretty useful due to the fact that Maya is 100% python compliant and using the prman python API we can create RIB filter and Ri calls directly in the Maya script editor.
There is just a little problem. If you develop in python for Maya you probably know the problem of reloading a module while developing it. Well, same problem with prman module.
Let me show you what I was trying to do.
Once you've installed prman for python, try to create a file prmantest.py with the following code:

import prman
_prmancall = "-catrib output.rib";
_ribfile = "/path/to/my/file.rib";
prman.Init(_prmancall.split());
ri = prman.Ri()
ri.Begin(ri.RENDER)
ri.ReadArchive(_ribfile)
ri.End()

Now, if you execute the file from a shell with:
python prmantest.py

you'll get the RIB file generated from the catrib option, without any problem.
If you try now to execute the script from a Maya python shell using:
execfile("/full/path/to/your/file/prmantest.py");

you'll get the same output but then if you try to modify the row:

it will reuse the previous defined arguments. Why ?
If you have a look at the code inside
/path/to/your/prman/bin/prman.py
you see, in the function
def Init()
, there is the check:
if not __private.prmanInit:

Well, this is set as False we you import the prman module and then it's set to True after the first Init call.
After that, if you recall the script again, the prman it's already loaded and the Init call doesn't change the arguments you are passing to the function again.
At this point you think simply adding a
reload(prman);
will fix this issue. Not precisely.
You must use the
Cleanup()
call after the end.
So, at the end, how we are going to change the code to make it executable for both, Maya and terminal ?
Here is the code correct:

import prman
reload(prman);
_prmancall = "-catrib output.rib";
_ribfile = "/path/to/my/file.rib";
prman.Init(_prmancall.split());
ri = prman.Ri()
ri.Begin(ri.RENDER)
ri.ReadArchive(_ribfile)
ri.End()
prman.Cleanup();

PS: I know, don't say anything about my C++ coding style used in python as well. It works and I'm coding in this way.

tags