PDA

View Full Version : Python: Scene Time laps/ Hardware 2.0 Batch render


cwisbg
12-09-2012, 06:57 AM
I thought it would be cool to do a modeling time laps and thought it would be easy. The idea would be to make a camera and animate it floating around the scene watching the modeling.

The camera would be rendering viewport quality images every x seconds and save them to a destination while you model and do whatever in your scene in the perspective camera creating a timelaps of the scene. Im stuck at the render/save from camera stage.

I tried a so manny different commands and could not get what I wanted.
The ones I tried were-
glRender, ogsRender, hwRender and playblasting but that required you to be looking though the camera, as far as I know.
I got the closest with hwRender, which was getting an image to save out to the maya tmp directory with the scene name. So not very far unfortunately :banghead:
I just need help with a way to save out a image from a camera. Any insight?

zoharl
12-09-2012, 08:22 PM
I think you can get the gl context from M3dView or just use the winapi to get the current wgl context, and then read the gl buffer (look for my previous post on independent opengl plugin), but if you are able to render a file to the temporary directory, why not copy it to where you want it?

cwisbg
12-09-2012, 11:53 PM
I have scratched together a working version of the script here
http://pastebin.com/raw.php?i=S97kbv09
It works well enough to convince me to do this right.

My first priority is to change the timing funchion. Been looking around and found a couple options, like sockets and possibly scriptjob. not sure yet. I was thinking something that could run outside maya and just tell maya every 10 seconds to run a script.

If anyone has any insight into how to set up a timed function I would love to hear!Thanks

cwisbg
12-09-2012, 11:55 PM
I think you can get the gl context from M3dView or just use the winapi to get the current wgl context, and then read the gl buffer (look for my previous post on independent opengl plugin), but if you are able to render a file to the temporary directory, why not copy it to where you want it?
I couldn't find this, but i am interested

zoharl
12-10-2012, 06:33 AM
Info about opengl:

http://lmgtfy.com/?q=M3dView
http://lmgtfy.com/?q=wgl+context

If you want to send commands to maya from the outside look into commandPort.

cwisbg
12-10-2012, 04:41 PM
http://lmgtfy.com/?q=M3dView
http://lmgtfy.com/?q=wgl+context


LOL thats awesome. Unfortunately my api knowledge is lacking a bit to really make easy use of those, so I may need to ask you how to peace these together when i get to that stage.

For now Im working on the getting the commands to run in maya. I have the commandPort section working and communicating with the terminal. I guess the best way to handle it from here will be a scriptJob? I havent messed with the commandPort enough to know if i can just send the commands directly though this. Ill have to play with it tonight.

zoharl
12-10-2012, 05:26 PM
I'm glad that you liked it, people sometimes get offended ;)
If you aren't familiar with the API (OpenMaya module), then it won't be trivial, but since you mentioned gl at the beginning I wrongly assumed C++.

If you got the commandPort working, then I'm not sure why you need the scriptJob. Set a timer on the external (non maya) script and just send commands to maya.

zoharl
12-11-2012, 07:06 AM
If you don't need a precise time, people use jobScript to set a RecentCommandChanged or SelectionChanged events, and check their timer on these events. For example:

http://www.creativecrash.com/maya/downloads/scripts-plugins/interface-display/c/auto-save/

It would save you the hassle of an external script with commandPort.

cwisbg
12-14-2012, 05:57 PM
After messing with the commandPort and Its definitely the way to go (for what i want).
I am sending a command to maya to run my "takePicture" script, but im running into problems with the naming (or passing a variable). I want to be able to pass a variable to the command im sending to maya but it donst want to work form my script. Im sure its something simple but admittedly I haven't done to much of this so im sure its something simple.
right now im using the following in idle

i = "testName"
maya.send(bytes("from takePicture import *", "UTF-8"))# to import the script

maya.send(bytes("reload(takePicture)", "UTF-8"))# reload if running the script again

maya.send(bytes("takePicture(0)".format(i),'UTF-8'))# take picture command



and my takePicture.py looks something like this

def takePicture(name):
print "testing", name


I have a feeling im just handling the import and running the script wrong, so it would be nice if someone could steer me in the right direction.

zoharl
12-14-2012, 09:07 PM
Are you sending the commands line-by-line or are you executing a full script?
Please provide a full source that can be tested.

Since I found communicating through tcp with the commandPort buggy, I just prefer to execute whole scripts with a small commandPort.exe util. See for example:

http://forums.cgsociety.org/showthread.php?f=89&t=1055175&page=1&pp=15

post #14.

cwisbg
12-15-2012, 07:07 PM
Im executing a full script. For the set up in maya I have a little ui that makes a file for the outside script to check, so i have the ability to stop the script within maya.
here
http://pastebin.com/raw.php?i=0myEm6En

And the outside of maya scirpt im running in idle
http://pastebin.com/raw.php?i=GYKY24EV
Currently just using and if statement, but that will turn into a while once i get this working.

And the script to be exicuted
I have most of it commented out for testing purposes. The goal is to just pass the variable

# timeLaps
#timeLaps.py
def takePicture(fileName):
print "testing", fileName
"""
tmpDirectory = (os.path.expanduser("~/Documents/maya/projects/default/images/tmp/timeLaps.iff"))
filePath = (os.path.expanduser("~/Desktop/"+fileName+".iff"))
hwRender(cam="camera1", cf=1, fnp = 1)
s.copy2(tmpDirectory, filePath)
"""

zoharl
12-15-2012, 10:02 PM
Let's call the inside script in.py, and the outside script out.py.

1. I'm not sure which external external python interpreter you use, but I use python 2.7 and it complained on:

print bytes("from timeLaps import *", "UTF-8")
TypeError: str() takes at most 1 argument (2 given)

so I used instead

print bytes("from timeLaps import *")

2. In out.py when you format the string, you forgot the curly brackets:

maya.send(bytes("timeLaps({0})\n".format(i)))

3. After each send you should check maya's output:

maya.send(bytes("timeLaps({0})\n".format(i)))
res = maya.recv(10000)
print "Result:", res


4. You will notice that you need to end your commands with "\n":

maya.send(bytes("from timeLaps import *\n"))
maya.send(bytes("reload(timeLaps)\n"))


and I think that each line (each send) is executed independently, so you should first format a command string that includes your whole script, then send it. Else I think you are executing line-by-line.

cwisbg
12-16-2012, 12:45 AM
Finally got it!!! Much thanks zoharl!

heres a little test of the script set at 1 fps

http://www.youtube.com/watch?v=R_F9_irK7Ts



Im running it though the terminal but Im going to work on getting to be an .exe or something.
Then I want to figure out how to tell the .exe to run from within maya.

zoharl
12-16-2012, 01:09 AM
You model quite fast... ;)

I'm not sure why you need .exe for, but if you don't want to be dependent on python you can always write your code in C++.

To execute an external app from maya you can use:

import os
os.system("calc.exe")


unless you meant something else.

cwisbg
12-16-2012, 03:58 AM
If I can get the terminal to open/run my script from maya then I dont need the .exe.

any chance you know the command to open the terminal? Iv been searching around and cant find any info on os.system

tried "Terminal.app" and also tried with the file path with no luck

And i dont have any C++ experience, so its all python for now.

zoharl
12-16-2012, 09:00 AM
Forget .cpp, forget .exe, python is more than enough.

Did you try to copy/paste my os.system example to the script editor and run it? The command is quite straight forward, you put in the string the command you want to execute in the cmd. If you need formal doc:

http://docs.python.org/2/library/os.html#os.system

So to run an external script c:\8\out.py that contains the following code:

# out.py
print 'hi'
raw_input("press")


from maya:

import os
os.system("start /b python -E /8/out.py")


or if you want to use maya's python:

import os
os.system("start /b mayapy -E /8/out.py")

CGTalk Moderation
12-16-2012, 09:00 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.