PDA

View Full Version : Script to save screenshot + fluidContainer Attrs?


eaclou
09-23-2010, 08:20 PM
Hi, I only have a pretty cursory knowledge of MEL so far, but while doing some work with Maya fluids I came up with a script idea that i'd really like to implement:

When I run the script, it should take a screenshot, save that, and at the same time, look at the fluid container/emitter and print out all the settings into like a .txt or something.

I can handle the printing attributes, but haven't really worked with system commands. how difficult is it to take a screengrab of the current camera (or render, but screengrab is probably better (instant)). and save it as a .jpg?

Additionally, would it be possible to, from within Maya/MEL, create a powerpoint .ppt and place the image on the slide and the attribute data in the notes field for that slide, so I could scroll along the slides and see the screengrab along with all the settings?

I just say powerpoint because it's the only program I can think of that would handle picture+text easily. I'd be just as happy with a program that does what some digital cameras do where they overlay the photo settings onto the image itself for review.

Will this be a do-able project? Thanks,

NaughtyNathan
09-23-2010, 10:42 PM
That should all be fairly easily doable Eric, there is a python windows module that allows you to access things like printscreen and the clipboard, but to be honest I wouldn't bother going that sophisticated... playblast is an instant hardware viewport dumper and it's easy to specify the exact output file and format (do a CGTalk search for playblast and .jpg).

rather than .ppt (which is a binary file format) you could very easily auto-generate a HTML web page instead. This could still display/do all the stuff you want, is ASCII, platform/software independant, very quick to view, and is scalable as you like in terms of functional complexity.

:nathaN

eaclou
09-27-2010, 03:59 AM
Thanks Nathan, I'll definitely give that a shot. Playblast actually sounds better than a screenshot because it doesn't save the UI.

I had also considered html after posting. That could work well for reviewing the images. I guess if I was even more ambitious I could save the data in an .xml and build a custom viewer with Flash.

ewerybody
09-28-2010, 11:27 AM
Or just html ans JavaScript. There are tons of good image viewing scripts with JS :D

eaclou
09-29-2010, 12:39 AM
So i'm getting there after some trial and error.

-Figured out how to query the current project folder and create folders inside there to hold the files.
-Got playblast to work
-fopen is correctly creating new .html files.

However, looking ahead, I need a good way to keep track of how many snapshots have been taken in order to correctly name the files, because by default they just overwrite the last one.

I thought about just using a simple $int counter, but I'm getting an error saying 'undefined variable' which makes no sense to me because I declared it outside of the proc, so it should be global. Anyway, here is the relevant part of the code in bold and underlined:


button -label "Take Snapshot!" -bgc .65 1 .75 -c "snapShot()";

showWindow $win_UI;

int $snapCount = 0;

global proc snapShot() {

print "running snapShot\n";
string $name = `textField -q -text setName`;
print ($name + "\n");

string $currentWorkDir = `pwd`;
string $folderMain = ($currentWorkDir + "/attrCompare");
sysFile -md $folderMain;
string $folderData = ($folderMain + "/attrData");
string $folderImg = ($folderMain + "/img");
sysFile -md $folderData;
sysFile -md $folderImg;

$fileName = ($folderData + "/" + $name + ".html");
print ($fileName + "\n");

setAttr "defaultRenderGlobals.imageFormat" 8;
int $curTime = `currentTime -q`;
string $snap = `playblast -cf ($folderImg + "/" + $name + ".jpg") -frame $curTime -format "image" -f "playblast_script" -showOrnaments 0 -viewer 0 -wh 640 640 -percent 100`;

$fileId=`fopen $fileName "w"`;
fprint $fileId "Hello there\n";
fclose $fileId;

print $snapCount;
}


Should I create a null group and create a custom attribute on that and use it?

I'm confused by how MEL handles continuity of variables, because I don't know when it considers a script done executing

Any good ideas on how to keep track of how many snapshots the user has taken (and within a particular "set" of snapShots) i.e I havea set of shots of a Volcano project, and also a set of shots from a candle flame project in the same workspace.

What is the best way to parse a String to check if a file already exists? For example i have a file called "volcano.01.jpg" and want to check to see if it's root is equal to "volcano" (which it is in this case). Can I strip everything after a period out?

*And yeah, JS would work, I just need to learn it, heh - there's no shortage of languages

Thanks everyone.

NaughtyNathan
09-29-2010, 10:02 AM
no variable is considered global by a proc unless explicitely declared as such. and variable scope is defined by the { and } characters (that is entirely the point of having them!) Read this post Eric:

http://forums.cgsociety.org/showpost.php?p=6538895&postcount=17

:nathaN

ewerybody
09-29-2010, 10:08 AM
you need to define it as global from the outside first and then in the scope of your procedure as well:global int $sdfgsdagsdf = 0;

global proc dfasdfsdfasdf()
{
global int $sdfgsdagsdf;
print("$sdfgsdagsdf: \"" + $sdfgsdagsdf + "\"\n");
}

dfasdfsdfasdf;

eaclou
09-30-2010, 02:42 AM
Thanks guys, I didn't realize i had to redeclare a global variable to get it to recognize it.

Anyway, I'm probably not going to go that route anyway because it's not very reliable if I was doing multiple sessions. I've found containing as many things as I can in procedures seems to be working the best so far.

At this point, i'm aiming to have Maya produce an .xml file for each "snapShot" and then a primary .html file will dynamically populate itself (using javascript - have to brush up on that, haven't used it much). This way I can do cool things eventually like Highlighting the attributes that differ between two .xml's, to make it easy to see what variables are different.

I'm running into a weird issue, that isn't hugely fatal, because it's still a working .xml, but when i use fprint and include a "\n", it's not moving to the next line. I've been placing /n all over the place with no effect.

here's some code:


$tempVal = `getAttr ($emit + ".fluidDensityEmission")`;
string $tempLine = writeLine("EMIT", "densityEmission", $tempVal);
appendToFile($tempLine);

global proc appendToFile(string $line) {
string $userSetName = `textField -q -text setName`;
string $currentWorkDir = `pwd`;
$fileNameXML = ($currentWorkDir + "/attrCompare/attrData/" + $userSetName + ".xml");
print ("\nAPPENDTOFILE: " + $fileNameXML + "\n" + $line + "\n");
$fileActive=`fopen $fileNameXML "a"`;
fprint $fileActive ($line + "\n");
fclose $fileActive;

}

global proc string writeLine(string $type, string $attrName, string $value) {
//print("***running appendFile; type= " + $type + ", name= " + $attrName + ", val= " + $value + "\n");
string $element = ("\n<" + $type + " name=\"" + $attrName + "\">" + $value + "</" + $type + ">");
//print $element;
return $element;
}




Thanks again

ewerybody
09-30-2010, 10:25 AM
cannot confirm.The code from the fprint (http://download.autodesk.com/us/maya/2009help/Commands/fprint.html) docs work for me *shrug*
a little modified:
{
$exampleFileName = ( `internalVar -usd` + "example.tmp" );
$fileId=`fopen $exampleFileName "a"`;
fprint $fileId "<Hello value=\"there\" />\n";
fclose $fileId;
}

eaclou
09-30-2010, 04:19 PM
It's weird, I brought the script to another computer to check it (WinXP 32 as opposed to Win7 64) and it prints out the \n as a box symbol...

Not sure what's going on. At least it works though, as .xml doesn't need the carriage returns, but it's easier to read.

I've got the script working, and the JS is parsing the .xml correctly. The last hurdle is going to be handling multiple .xml's and keeping them organized / keeping track of how many are already created.

I'm sure I'll run into some issues, heh.

eaclou
10-05-2010, 03:43 AM
Thought i'd post an update:

I've got a working (albeit ugly, and unpolished) version now. It's my first medium-sized mel script, so the coding is pretty awful, but it works. The Maya mel script prints out a .jpg and an .xml each time you click the snapshot button.

Then I made an .html file that uses javascript to parse two .xml's at a time. It will display in red any attribute that differs between the two currently compared files, and will initially hide attributes which are the same (you can still click on a category to look at the values.

Here are some screens and code if anyone wants to use it or make their own modifications.

http://www.loreaxe.com/WebPosting/attrCompareUI.jpg

http://www.loreaxe.com/WebPosting/attrCompare.jpg

Thanks for the help everyone, I'm going to continue to polish it and make it more user-friendly, but it's nice to have it sort of working.

http://www.loreaxe.com/WebPosting/attrCompareScript.txt
http://www.loreaxe.com/WebPosting/doubleView_05_troubleshoot.html

To use:
1. load mel Script into script editor
2. set project
3. run mel - select your emitter(s) and fluid(s) - click on "Snapshot" (keep set name as "default" for now.)
4. It will create a folder called "AttrCompare". Place the .html file in there to view your snapshots.

thematt
10-05-2010, 04:33 PM
looks really cool and usefull! good job

cheers

CGTalk Moderation
10-05-2010, 04:33 PM
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.