/* // // Dids - Boneyard // by Didier Donne // 2007 // // This script will search your scene for joints and map out the entire // skeleton. Joint and parent names are stored along side of every translate // XYZ coordinate. This way you can create your own skeleton (or bone) collection // and recall them in the future by one click only. I wrote this script with // the idea of adding several more scripts which will hugely cut down your // (and mine!) rigging time. I know, I know. There's already tons of those out // there. But this one is (Sort of) special! Besides it's also an exercise for me. // // ~Didier Donne // www.didierdonne.com // */ global proc BoneYard() { // FILE AND DIRECTORY CHECK // // first check if the directory and file for saving bone collections is available string $userAppDir = `internalVar -userAppDir`; // store th user application dir $userAppDir+= "Dids/Boneyard/"; // append "Dids/" at the end $myfiletest = `filetest -d $userAppDir`; // does it exist? o=no 1=yes // if the directory does not exist, create it ! if($myfiletest == 0){ sysFile -makeDir $userAppDir; }; // check for the bones file collection $userAppDir+= "mybones.txt"; $myfiletest = `filetest -f $userAppDir`; if($myfiletest == 0){ $fileId=`fopen $userAppDir`; fprint $fileId "Dids Boneyard Collection File\n\n"; fclose $fileId; }; // Main WINDOW // if(`window -query -exists didsBoneYardWindow`) deleteUI didsBoneYardCollectorWindow; if(`window -query -exists didsBoneYardWindow`) deleteUI didsBoneYardFetchWindow; if(`window -query -exists didsBoneYardWindow`) deleteUI didsBoneYardWindow; window -title "Dids Boneyard" didsBoneYardWindow; rowColumnLayout -numberOfColumns 1 -columnWidth 1 300; button -label "Create Collection" -c "didsBoneYardCollectorWindow"; button -label "Fetch Collection" -c "didsBoneYardFetchWindow"; button -label "Cancel" -c "deleteUI didsBoneYardWindow"; showWindow; } // Collector WIDNOW // proc didsBoneYardCollectorWindow(){ if(`window -query -exists didsBoneYardWindow`) deleteUI didsBoneYardWindow; if(`window -query -exists didsBoneCollectorYardWindow`) deleteUI didsBoneYardCollectorWindow; window -title "Dids Boneyard" didsBoneYardCollectorWindow; rowColumnLayout -numberOfColumns 2 -columnWidth 1 150 -columnWidth 2 150; text -label "Collection Name: "; string $myTextFieldPath = `textField`; //string $name = `textField -q $myTextField`; button -label "Save" -c ("didsBoneYardCollector " +$myTextFieldPath); button -label "Cancel" -c "deleteUI didsBoneYardCollectorWindow"; showWindow; } proc didsBoneYardCollector(string $myTextFieldPath){ // COLLECT THE JOINTS // int $i = 0; string $myParents[]; string $myJoints[]; string $tempParent[]; string $myJointsSaveLine = ""; string $myParentsSaveLine = ""; string $xSaveLine = ""; string $zSaveLine = ""; string $ySaveLine = ""; string $x[]; string $y[]; string $z[]; string $myerror; string $name = `textField -q -tx $myTextFieldPath`; string $jointFilter = `itemFilter -byType joint`; //create a search filter string $foundJoints[0] = `lsThroughFilter $jointFilter`; // find all the joints with the search filter if ($name != "" && size($foundJoints) > 0 ){ for ($i=0;$i 0 ) { $nextLine = `fgetline $fileId`; if($nextLine == "START\n"){ $nextLine = (`fgetline $fileId`); $j = size($nextLine) - 1; $nextLine = `substring $nextLine 1 $j`; $collectionName[$i] = $nextLine; $i++; } } fclose $fileId; // Create joint collection if(`window -query -exists didsBoneYardWindow`) deleteUI didsBoneYardWindow; if(`window -query -exists didsBoneYardFetchWindow`) deleteUI didsBoneYardFetchWindow; window -title "Dids Boneyard" didsBoneYardFetchWindow; rowColumnLayout -numberOfColumns 1 -columnWidth 1 300; string $didsScrollList = `textScrollList -numberOfRows 10 -height 150 -allowMultiSelection false`; rowColumnLayout -numberOfColumns 2 -columnWidth 1 150 -columnWidth 2 150; text -label "Give your rig a name : "; string $myTextFieldPath = `textField`; button -label "Create" -c ("didsBoneYardFetch " + $myTextFieldPath + " " + $didsScrollList); button -label "Cancel" -c "deleteUI didsBoneYardFetchWindow"; textScrollList -e -ra $didsScrollList; // clear scroll list for ($myAppend in $collectionName){ textScrollList -edit -append $myAppend $didsScrollList; // add bone collection names to scroll list } showWindow; } // Create bone/joint collection from file proc didsBoneYardFetch(string $myTextFieldPath, string $didsScrollList){ string $myfile=(`internalVar -userAppDir` + "/Dids/Boneyard/mybones.txt"); string $name = (`textField -q -tx $myTextFieldPath` + "_"); // add a lil underscore for readability string $myCollection[] = `textScrollList -q -si $didsScrollList`; int $i = 0; int $jointDuplicateCheck = 0; string $x[]; string $y[]; string $z[]; string $myParents[]; string $myJoints[]; string $myError; // check for duplicate joints in the scene // loads all the elements of a collection first $fileId=`fopen $myfile "r"`; string $nextLine = `fgetline $fileId`; while (size( $nextLine ) > 0 ) { $nextLine = `fgetline $fileId`; if($nextLine == ($myCollection[0] + "\n")){ // find the selected collection and put all the info into arrays $nextLine = `fgetline $fileId`; $x = stringToStringArray($nextLine, ","); // the x $nextLine = `fgetline $fileId`; $y = stringToStringArray($nextLine, ","); // the y $nextLine = `fgetline $fileId`; $z = stringToStringArray($nextLine, ","); // you guessed it - the z $nextLine = `fgetline $fileId`; $myJoints = stringToStringArray($nextLine, ","); // the joints $nextLine = `fgetline $fileId`; $myParents = stringToStringArray($nextLine, ","); // the joint parents // I'll put it in a loop later... int $u = (size($x) - 1); int $t = (size($x[$u]) - 1); $x[$u] = `substring $x[$u] 1 $t`; int $u = (size($y) - 1); int $t = (size($y[$u]) - 1); $y[$u] = `substring $y[$u] 1 $t`; // remove \n from last value in the arrays int $u = (size($z) - 1); int $t = (size($z[$u]) - 1); $z[$u] = `substring $z[$u] 1 $t`; int $u = (size($myJoints) - 1); int $t = (size($myJoints[$u]) - 1); $myJoints[$u] = `substring $myJoints[$u] 1 $t`; int $u = (size($myParents) - 1); int $t = (size($myParents[$u]) - 1); $myParents[$u] = `substring $myParents[$u] 1 $t`; } } fclose $fileId; // do the actual joint name check for($i=0;$i