Professional Documents
Culture Documents
//returns an array containing the start and end times for the current timeline
selection
global proc float[] zooGetSelectedRange() {
global string $gPlayBackSlider;
float $range[] = `timeControl -q -ra $gPlayBackSlider`;
int $rangeTrue = 1;
return $dirs;
}
return $dirs;
}
//just a safeguard
if( $n>100000 ) {
warning "zooUtils::zooGetRecursedSubDirs() has searched 100000
directories, aborting...";
break;
}
}
return $pathsFound;
}
//deals with reliably copying a file - if the target directory path doesn't exist
//it gets created
global proc int zooCopyFileTo( string $fromPath, string $toPath ) {
if( !`filetest -f $fromPath` ) return 0;
$toPath = `fromNativePath $toPath`;
string $toks[] = `zooTokenize $toPath "/"`;
$toks = `zooIndexCrop_str $toks ":-1"`;
string $tgtDir = `zooArrayToStr_str $toks "/"`;
if( !`filetest -d $tgtDir` ) sysFile -makeDir $tgtDir;
return `sysFile -copy $toPath $fromPath`;
}
//------
//loads a file with optional new line stripping
//
// to strip newline characters, use
// -strip [bool] if true, will strip the newline character from each line
//------
global proc string[] zooReadFile( string $file, string $optionStr ){
//------
//parse optionStr to determine which flags are enabled for this proc
//------
int $strip = 0;
fclose $fileId;
return $fileContents;
}
//unlike the get script path, this proc takes a file name including extension
global proc string zooGetIconLocation( string $iconFileName ) {
string $paths[] = `zooListEnv XBMLANGPATH`;
string $buffer[] = {};
string $iconName;
string $ext;
string $scriptPath = "";
return $scriptPath;
}
return $rounded;
}
//is the first arg less than the second within a tolerance?
global proc int zooEqTol( float $leftSide, float $rightSide, float $tolerance ) {
if( abs($leftSide-$rightSide) <= $tolerance ) return 1;
return 0;
}
//turns all viewports on or off - speeds up procs that have to use current time
//changes as the viewports no longer need to refresh
global proc zooAllViews( int $state ) {
string $modelPanels[] = `getPanel -vis`;
string $emptySelConn = `selectionConnection`;
//sometimes maya needs a little bump to update a window correctly - often this
//is only nessecary with formlayouts
global proc zooBumpWindow( string $windowName ) {
int $w = `window -q -w $windowName`;
evalDeferred( "window -e -w "+ ($w+1) +" "+ $windowName +";" );
evalDeferred( "window -e -w "+ $w +" "+ $windowName +";" );
}
//given a list of stuff (usually just from the ls command), this proc will filter
//out all the components (given a component string) in the list and return them.
//for example, if you wanted to list all verticies from a list, you would use:
//zooFilterComponent `ls -sl` "vtx";
//you can do likewise for cvs, edges, faces etc...
global proc string[] zooFilterComponent( string $list[], string $componentStr ) {
string $components[] = {};
int $num = `size $list`;
return $components;
}
// returns a set containing all the quick selection sets in the scene
global proc string[] zoolsqss() {
string $sets[] = `ls -sets`;
string $qssSets[] = {};
return $qssSets;
}
//recursively queries set members. see the zooSetRelatives comments for details
//on the args taken
global proc string[] zooQuerySet( string $set, int $parents, int $recursive ) {
string $sets[] = `zooSetRelatives $set 1 $parents $recursive`;
string $objs[] = {};
return $objs;
}
//like listRelatives for sets. the parents arg tells whether you want to
//query child sets or parent sets. the recursive arg simply tells the script
//whether to perform a recursive listing of members
global proc string[] zooSetRelatives( string $set, int $includeSelf, int $parents,
int $recursive ) {
string $sets[] = {$set};
int $maxRecursion = 250;
int $n = 0;
while( 1 ) {
string $nextSets[] = ls("-type","objectSet",`sets -q $sets[$n]`);
if( $parents ) $nextSets = `listConnections -s 0 -type objectSet
$sets[$n]`;
$sets = `zooAddArray_str $sets $nextSets`;
$n++;
if( !$recursive ) break;
else if( !`size $nextSets` ) break;
else if( $n > $maxRecursion ) break; //just in case - yes this means
you can't have nested sets more than $maxRecursion deep... deal with it
}
return $sets;
}
//this proc "cleans" a given filepath - removed multiple slashes, makes all
//slashes uniform (unix style)
global proc string zooScrubPath( string $path ) {
$path = `fromNativePath $path`;
int $isUNC = `match "^//" $path` == "//"? 1: 0;
while( `match "/{2,}" $path` != "" ) $path = `substitute "/{2,}" $path "/"`;
if( $isUNC ) $path = "/"+ $path;
return $path;
}
//resolves a path string. path strings may contain unresolved env var references
//as well as the .. path op
global proc string zooResolvePath( string $path ) {
$path = `zooScrubPath $path`;
string $paths[] = `zooTokenize $path "/"`;
int $num = `size $paths`;
return $toReturn;
}
//like the distance command above, this is a simple wrapper for creating annotation
nodes,
//and having the nodes you actually want returned to you. whoever wrote these
commands
//should be shot. with a large gun
global proc string[] zooAnnotate( string $obj, string $text ) {
string $end = zooGetElement_str(0,`spaceLocator`);
string $shape = `annotate -p (rand(1000000)) (rand(2000000)) 2364 -tx $text
$end`;
string $start = zooGetElement_str(0,`listRelatives -p $shape`);
string $endShape = zooGetElement_str(0,`listRelatives -s $end`);
delete `parentConstraint $obj $end`;
setAttr ( $start +".t" ) 0 0 0;
setAttr ( $endShape +".v" ) 0;
setAttr -l 1 ( $endShape +".v" );
parent $end $obj;
return {$start,$end,$shape};
}
//zoo.end