Adding an item to the caption in the Render View is not so difficult. You can do so using the MEL command renderWindowEditor, if you know the name of the render window.
Writing a script to query, modify and re-write the caption that includes the system time would look something like this:
// get the name of the default Render View window
// query the caption under the image
// query the system time
// modify caption with system time
// write new caption to the Render View
string $rv[] = `getPanel -scriptType "renderWindowPanel"`;
string $caption = `renderWindowEditor -query -pca $rv[0]`;
string $st = `date -time`;
string $newCaption = ($caption+$st);
renderWindowEditor -edit -pca $newCaption $rv[0];
clear $rv;
// end of script
This is all fine, but when do you invoke the script? If you intend to use it as a post-render MEL script, you'll have to find a way to set it up quickly in every new Maya session, or you'll soon give up using it.
I decided to find a way to include the system time as an optional item in the render view diplay menu, just like the camera name and render time.
This is the first of three posts, and deals with adding the system time to the the caption (I'll deal with making it optional in my next post).
1) Copy the Maya default scripts to your user scripts directory
From the directory Autodesk/Maya2009/scripts/others , copy the following scripts to your user Maya scripts directory.
renderWindowCaption.mel
renderWindowCaption.res.melSo, on XP, I would put them here:
C:/Documents and Settings/owen/My Documents/maya/2009/scriptsOn the Mac, they go here:
/users/owen/Library/Preferences/Autodesk/maya/2009/scripts/
2) Add the system time to the caption:
Open your copy of renderWindowCaption.mel and take a look. As the first line states, this script returns the caption under the image or, more accurately: it builds and returns a string to the script that updates the Render View once a render is complete.
A quick scan of the script and it appears that each item is added one at a time to a string variable called $result
Assuming we add our own bit of info to $result then it should get displayed when we render an image, that is to say when Maya calls this script.
Let's get stuck in.
Between the end of //Add the camera name and //Add the layer name, include the following lines:
// Add the system time
string $time = `date -time`;
$result = $result + $time;
Save the script, open Maya and render a sphere.
You will now see the system time included in the caption.
3) Format the system time:
We could end here, but it would be really nice to format the info like the other caption items.
Basically, we want the caption to say "System time: " then the system time.
Open your renderWindowCaption.res.mel. (a .res.mel file groups together variables that define menu items, captions, error messages - these variables are queried using the MEL script uiRes() ).
Following the format for the other entries, add a line for a string identifier called m_renderWindowCaption.kSystemTime:
displayString -replace -value "System Time: ^1s "
m_renderWindowCaption.kSystemTime;
Save the script.
Now, back to the script renderWindowCaption.mel, change your lines to:
// Add the system time
$time = `date -time`;$fmt = (uiRes("m_renderWindowCaption.kSystemTime"));
$msg = `format -s $time $fmt`;$result = $result + $msg;
The middle two lines call the displayString we added called m_renderWindowCaption.kSystemTime and the MEL command format to insert the contents of our variable $time.
It's an elaborate way of adding the string "System Time: " + $time to the variable $result, but this is how Maya does it. And for scripts more complicated than this, grouping all the menu items, error messages, etc, into a seperate file makes them easier to find and therefore easier to edit, say if you were thinking of translating your interface into French.
Save your script again and re-open Maya (or resource both scripts).
The Render View now displays the newly formatted system time.
That's a fair bit to take in, and you'll be wondering why I don't include the if (`optionVar`....) line like all the other items in the script...well, that can wait for my next post, when I'll show you how to add a menu item to the render view menu, so you have the option to include the system time in the caption, or not.
Owen





Subscribe
these pages are of little, here I have discovered many things that really did not know, I thank you for the blog!
Posted by: generic viagra | 17/05/2010 at 06:47 PM
i am starting to love this blog! cool stuff!
Posted by: dwilks | 29/04/2009 at 02:14 AM