PDA

View Full Version : Exporting Selection Sets...


jjburton
07-09-2008, 01:58 AM
I looked around for awhile on this site and Highend3d looking for a script that would export quick selection sets and couldn't find jack. So I wrote one. Hope it's helpful, I learned a lot more about mel working through it. It's not perfect, but it works:)

It's a shame there's not a command to make the selection sets without having that stupid qss window pop up, but ah well...maybe next release of Maya will allow it.

Download it here with icons (http://www.joshburton.com/media/freebies/jbExportQSS.rar)


/*
TITLE: jbExportQSS
VERSION: 1.0
AUTHOR:Josh Burton
www.joshburton.com
DATE: July 3, 2008

DESCRIPTION:
Script to aid in the redundancy of setting up quick selection sets all the time
for the same assets but in different files. Exports a mel script that will set up
the idential quick selection set in another scene.

Exporting:
1) Select a quick selection sets in the outliner to be exported
2) Run script - it will export a mel per qss it is exporting

Importing:
1) Run the mel in your new file you want to set up the quick selection sets in
2) It will ask you want to add a prefix. If you're using a referenced asset
put in the prefix. If not, leave it blank:)
3) Repeat for each selection set

Features:
1) Checks for referencing data and removes it in the exported selection set
2) Can do multiple selection sets at once
3) Will account for prefixes on import if desired
4) Reports selection set name on the export mel window

Thanks: To David Bokser for answering my many questions and Scott Englert for my picking apart some of his scripts
*/


global proc jbExportQSS () {
string $sets[] = `ls -sl`;

for ($set in $sets){

//Checking if it's a set or not
if(`nodeType($set)` == "objectSet") {
string $qssSetToExport = ($set + " is the set being exported");
string $filename = `fileBrowserDialog -m 1 -fc ("getQssData \"" + $set + "\" ") -ft "mel" -an "Export" -om "ExportActive" -in $qssSetToExport`;
// string $filename = `fileDialog -m 1 -dm "*.mel"`;
// getQssData($filename, $set);
print ($set + " exported successfully.\n");
}
else {
warning($set + " is not an exportable set.\n");
}
}
}

global proc getQssData (string $set, string $filename, string $filetype) {
string $RefPrefix;
global string $qssSetToExport;
string $qssMembers[] = `sets -q $set`;

//check to see if it's refereneced
int $isReferenced = `referenceQuery -inr $qssMembers[0]`;
int $i = 0;
string $qssFinalMembers[];
string $qssFinalMembersPrintable;


//Get's our members to export list
if($isReferenced == 1){

for($qssMember in $qssMembers){
//getting reference prefix
string $filename = `referenceQuery -filename $qssMember`;
string $ns = `file -q -ns $filename`;
string $RefPrefix = ($ns + ":");
//Removing prefix from the name if it exists
string $bareMemberName = `substitute $RefPrefix $qssMember ""`;
//adding it to our exporting member name array
$qssFinalMembers[$i] = $bareMemberName;
$i = $i + 1;
}

} else {

for($qssMember in $qssMembers) {
$qssFinalMembers[$i] = $qssMember;
$i = $i + 1;
}
}

//Get's our Final Members in a printable format - Thanks Scott Englert for this bit of code on CGTalk:)
string $qssFinalMembersPrintable = "string $qssBaseObjects[] = {\"" + stringArrayToString($qssFinalMembers,"\", \"") +"\"}; \n";

//start making our mel
$fileId=`fopen $filename "w"`;
fprint $fileId "string $qssBaseObjects[];\n";
fprint $fileId ($qssFinalMembersPrintable+"\n");
fprint $fileId "int $i = 0;\n";
fprint $fileId "string $prefix;\n";
fprint $fileId ("string $result = `promptDialog -title \"Prefix Object Names?\"\n");
fprint $fileId (" -message \"Insert any prefix you would like to add\"\n");
fprint $fileId " -button \"Confirm\" -button \"Cancel\"\n";
fprint $fileId " -defaultButton \"Confirm\" -cancelButton \"Cancel\"\n";
fprint $fileId " -dismissString \"Cancel\"`;\n";
fprint $fileId " if ($result == \"Confirm\") {\n";
fprint $fileId " $prefix = `promptDialog -query -text`;\n";
fprint $fileId " }\n";
fprint $fileId " for($Object in $qssBaseObjects){\n";
fprint $fileId " string $prefixedObject = $prefix + $Object;\n";
fprint $fileId " $qssObjects[$i] = $prefixedObject;\n";
fprint $fileId " $i = $i + 1;\n";
fprint $fileId "}\n";
fprint $fileId "string $qssMissingObjects[];\n";
fprint $fileId "int $i = 0;\n";
fprint $fileId "for($object in $qssBaseObjects) {\n";
fprint $fileId "\n";
fprint $fileId " if(! `objExists $object`) {\n";
fprint $fileId (" print ($object +\" not found\"); \n");
fprint $fileId " $qssMissingObjects[$i] = $object;\n";
fprint $fileId " $i = $i + 1;\n";
fprint $fileId " }\n";
fprint $fileId "}\n";
fprint $fileId "string $qssFoundObjects[]= stringArrayRemove($qssMissingObjects, $qssBaseObjects );\n";
fprint $fileId "\n";
fprint $fileId "select -cl;\n";
fprint $fileId "select $qssFoundObjects;\n";
fprint $fileId "CreateQuickSelectSet;\n";
fclose $fileId;
}

NaughtyNathan
07-09-2008, 08:53 AM
there is a command for 99% of things that happen in Maya.

If you do a: whatIs on CreateQuickSelectSet you will find out that it's a Run Time Command. Checking this tells you that it is an alias for defineCharacter. Doing a whatIs on this tells you it's a MEL proc. Open this proc up and look for the the proc defineCharacter which will show you what Maya is doing to create a quick Selection Set:

sets -text "gCharacterSet" -name $quickSetName;

so there you go. You can learn a lot about Maya and MEL using this tactic.

:nathaN

P.S. I'm curious though, why would anyone need to do this (export sets)?

GiantG
07-09-2008, 09:27 AM
An other easy method ist just to make a set inside maya.
You get this result:

$createSetResult = `sets -name "set1"`;

There you have your command:

sets -name "set1";

A quickselectionset is just a special form of the normal set

Nathan's Stuff written out:

whatIs CreateQuickSelectSet;
runTimeCommand -q -c CreateQuickSelectSet ;
whatIs defineCharacter;

cpan
07-09-2008, 09:43 AM
I think you can simply select the set in Outliner and hit Export Node (as .ma). It should work
as well I hope :)

btw I wrote a script (http://highend3d.com/maya/downloads/mel_scripts/modeling/curve_tools/3958.html) for QSS some years ago, take a look at it too, you may find it useful
if you use QSS a lot:)

NaughtyNathan
07-09-2008, 09:49 AM
I think you can simply select the set in Outliner and hit Export Node (as .ma).

that won't work as sets are connected to the geometry, so the geometry will be exported too. Besides, importing an exported set wouldn't "reattach" it to the same geometry on import.

:nathaN

NaughtyNathan
07-09-2008, 09:56 AM
An other easy method ist just to make a set inside maya.
...
A quickselectionset is just a special form of the normal set

that's right, but don't forget that normal sets are NOT detected as quick selection sets so If you're using quick selection set tools (e.g. Edit > Quick Select Sets), such normal sets won't show up, and will only be visible in the outliner (et al).

:nathaN

cpan
07-09-2008, 10:00 AM
ah, i think you're right Nathan! gotta dip into maya some time to get rid of teh rust eh

all the best to you all:)
calin

jjburton
07-09-2008, 01:50 PM
Thanks all, I'll try to reply...

Quick Selection Sets are a different entity than regular sets or at least Maya sees them differently. I looked at using basic sets as it would have made the exporting easier using many of the suggestions offered. However, I have other scripts for using quick selection sets in my workflow and didn't wanna find or make new ones there.

As to why other methods weren't used
Why not use....


sets -text "gCharacterSet" -name $quickSetName;


Frankly, I didn't know about that flag "-text "gCharacterSet" "

I really appreciate your pointing it out as it will allow me to make my script more robust in handling muliple qss's. Thanks!


whatIs on CreateQuickSelectSet


Thanks, I hadn't known this but was using the less efficient "echo all commands method" to see what it was doing. I'll be using this in the future.:)


I think you can simply select the set in Outliner and hit Export Node (as .ma). It should work
as well I hope :)

btw I wrote a script (http://highend3d.com/maya/downloads/mel_scripts/modeling/curve_tools/3958.html) for QSS some years ago, take a look at it too, you may find it useful
if you use QSS a lot:)

I just tried your method of exporting node and it didn't seem to work as expected.

:) - I use a very similar script for mananging my qss's selections from Zoo's tool box.


P.S. I'm curious though, why would anyone need to do this (export sets)?

In short, to be more efficient. If you don't use qss's much in your workflow, then no it's probably not going to be useful to you:)






While animating - I define qss's for the whole character, and different parts (i.e. lower face, upper face, leftarm etc). Sometimes I'm able to put those qss's in the base character rig. Sometimes I can't. I get tired of setting up the same quick selection sets for each character everytime I open a new scene. It's especially a hassle when I'm selecting every single control on a character and some are FK/IK "hidden" (you can't see some when FK is on or vice versa).
During setup - Somewhat the same as before, when I am able to add them to the base characters. I only have to figure out my set members for each set once, then I can export them to a script that will select all of my set members for me for the other characters (provided they use the same control names).
Selecting odd sets of things - sometimes there aren't controls set up for dummy geometry and qss's are an easy way to select what you want (maybe the top a group instead of a member)
My script doesn't just export the sets, it also removes referencing data in the set member names and adds the ability to add that back for other character for example. I usually use a mix of Character Sets and Quick Selection sets. But they both have their pluses and minuses.


Now with NaughtyNathan's flag, I can do some more things I hadn't been able to:)

jjburton
07-16-2008, 03:31 PM
Thanks to Naughty Nathan's "sets" flag, updated the script to do muliptle selection sets in one mel. Added auto naming of the sets and also fixed some bugs.


/*
TITLE: jbExportQSS
VERSION: 1.5
AUTHOR:Josh Burton
www.joshburton.com

DESCRIPTION:
Script to aid in the redundancy of setting up quick selection sets all the time
for the same assets but in different files. Exports a mel script that will set up
the identical quick selection set in another scene.

Exporting:
1) Select a quick selection sets in the outliner to be exported
2) Run script - it will export a mel file to recreate the sets

Importing:
1) Run the mel in your new file you want to set up the quick selection sets in
2) It will ask you want to add a prefix. If you're using a referenced asset
put in the prefix. If not, leave it blank:)

Features:
1) Checks for referencing data and removes it in the exported selection set
2) Can do multiple selection sets at once
3) Will account for prefixes on import if desired
4) Reports if set members aren't found in imported sets

Thanks:
To David Bokser for answering my many questions and Scott Englert for my picking apart some of his scripts

History
v1.5 - July 14, 2008 - Added the ability to export multiple sets at once into a single mel file, making importing easier. Also,
little quick selection window doesnt' pop up any more due to a flag on the "sets" command I hadn't known about. Several bug fixes
as well
v1.0 - July 3, 2008 - Initial realease
*/

global proc jbExportQSS () {
string $filename = `fileBrowserDialog -m 1 -fc "getQssData" -ft "mel" -an "Export" -om "ExportActive"`;

}

global proc getQssData (string $filename, string $filetype) {
string $sets[] = `ls -sl`;
string $RefPrefix;
string $qssNames[];
string $baseObjectSets[];
int $s = 0;
int $z;

for ($set in $sets){
//Checking if it's a set or not
if(`nodeType($set)` == "objectSet") {

//Add the $set name to our exporting set name list
$qssNames[$s] = $set;

//Gets set members
string $qssMembers[] = `sets -q $set`;


//check to see if it's refereneced
int $isReferenced = `referenceQuery -inr $qssMembers[0]`;
int $i = 0;
string $qssFinalMembers[];
string $qssFinalMembersPrintable;

//Referencing conditionals
if($isReferenced == 1){
for($qssMember in $qssMembers){
//getting reference prefix
string $filename = `referenceQuery -filename $qssMember`;
string $ns = `file -q -ns $filename`;
string $RefPrefix = ($ns + ":");
//Removing prefix from the name if it exists
string $bareMemberName = `substitute $RefPrefix $qssMember ""`;
//adding it to our exporting member name array
$qssFinalMembers[$i] = $bareMemberName;
$i++;
}
} else {
for($qssMember in $qssMembers) {
$qssFinalMembers[$i] = $qssMember;
$i++;
}
}

//Puts out objects in a format we need for exporting and reports success
string $objectsBuffer = stringArrayToString($qssFinalMembers, " ");
$baseObjectSets[$s] = $objectsBuffer;
$s++;
print $baseObjectSets[$s];
print ($set + " exported successfully.\n");

//Clear the array
int $size = size($qssFinalMembers);
for($z=0;$z<$size;$z++){
stringArrayRemoveAtIndex(0, $qssFinalMembers);
}
}
else {
warning($set + " is not an exportable set.\n");
}
}

//Get's our Final Members in a printable format - Thanks Scott Englert for this bit of code on CGTalk:)
string $baseObjectsSetsPrintable = "string $baseObjectSets[] = {\"" + stringArrayToString($baseObjectSets,"\", \"") +"\"}; ";
string $qssNamesPrintable = "string $qssNames[] = {\"" + stringArrayToString($qssNames,"\", \"") +"\"}; ";

//Make Our Mel
$fileId=`fopen $filename "w"`;
fprint $fileId "global proc makeQss() { \n";
fprint $fileId ($baseObjectsSetsPrintable+"\n");
fprint $fileId ($qssNamesPrintable+"\n");
fprint $fileId "string $qssObjects[]; \n";
fprint $fileId "string $qssMissingObjects[]; \n";
fprint $fileId "string $prefix; \n";
fprint $fileId "int $i = 0; \n";
fprint $fileId "int $n = 0; \n";
fprint $fileId "int $m = 0; \n";
fprint $fileId ("string $result = `promptDialog -title \"Prefix Object Names?\" \n");
fprint $fileId (" -message \"Insert any prefix you would like to add\" \n");
fprint $fileId " -button \"Confirm\" -button \"Cancel\" \n";
fprint $fileId " -defaultButton \"Confirm\" -cancelButton \"Cancel\" \n";
fprint $fileId " -dismissString \"Cancel\"`; \n";
fprint $fileId " if ($result == \"Confirm\") { \n";
fprint $fileId " $prefix = `promptDialog -query -text`; \n";
fprint $fileId " } \n";
fprint $fileId " for ($set in $baseObjectSets) { \n";
fprint $fileId " $i = 0; \n";
fprint $fileId " string $currentSet[]; \n";
fprint $fileId " int $numTokens = tokenize($baseObjectSets[$n], $currentSet); \n";
fprint $fileId " for($object in $currentSet) { \n";
fprint $fileId " string $prefixedObject = $prefix + $object; \n";
fprint $fileId " $qssObjects[$i] = $prefixedObject; \n";
fprint $fileId " if(! `objExists $prefixedObject`) { \n";
fprint $fileId (" print ($prefixedObject + \" not found from \" + $qssNames[$n] + \"\\n\"); \n");
fprint $fileId " $qssMissingObjects[$m] = $prefixedObject ; \n";
fprint $fileId " $m++; \n";
fprint $fileId " } \n";
fprint $fileId " $i++; \n";
fprint $fileId " } \n";
fprint $fileId " string $qssFoundObjects[]= stringArrayRemove($qssMissingObjects, $qssObjects); \n";
fprint $fileId " string $nameBuffer = $prefix + $qssNames[$n]; \n";
fprint $fileId " sets -text \"gCharacterSet\" -name $nameBuffer $qssFoundObjects; \n";
fprint $fileId " int $size = size($qssObjects); \n";
fprint $fileId " for($z=0;$z<$size;$z++){ \n";
fprint $fileId " stringArrayRemoveAtIndex(0, $qssObjects); \n";
fprint $fileId " } \n";
fprint $fileId " $n++; \n";
fprint $fileId " } \n";
fprint $fileId " } \n";
fprint $fileId " makeQss; \n";

fclose $fileId;

}

strange_quark
10-21-2008, 10:46 PM
this script = awesome.

thanks.

CGTalk Moderation
10-21-2008, 10:46 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.