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;
}
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;
}
