Skip to content

Instantly share code, notes, and snippets.

@yamahigashi
Last active August 29, 2015 13:57
Show Gist options
  • Save yamahigashi/9737197 to your computer and use it in GitHub Desktop.
Save yamahigashi/9737197 to your computer and use it in GitHub Desktop.
maya のいろいろ支援スニペット mel
global float $BIGNUMBER_MINUS = 100;
global float $BIGNUMBER_PLUS = 1000;
global proc string stripNamespace(string $n){
string $exp = "^.*:";
string $new = `substitute $exp $n ""`;
return $new;
};
global proc locateDummy(string $prefix){
string $sel[] = `ls -sl`;
string $hoge = "";
select -cl;
for ( $s in $sel ) {
$pos = `xform -q -ws -piv $s`;
$hoge = $prefix+(stripNamespace($s));
string $tmp[0] = `spaceLocator -n $hoge`;
xform -t $pos[0] $pos[1] $pos[2] $tmp[0];
}
select $sel;
};
global proc insertDummyDescendant(int $switch, string $prefix){
cycleCheck -e off;
string $sel[] = `ls -sl`;
string $dumN = "";
for ( $s in $sel ) {
$dumN = stripNamespace($s);
if(catch(` delete ($s+"*Cons") `)) {}
if(catch(` delete ($prefix+$dumN+"*Cons") `)) {}
string $mykids[] = `listRelatives -children $s`;
if(catch(` parent ($prefix+$dumN) $s `)) {}
if(catch(` parent $mykids ($prefix+$dumN) `)) {}
}
};
global proc insertDummyAscendant(string $prefix){
cycleCheck -e off;
string $sel[] = `ls -sl`;
string $dumN = "";
for ( $s in $sel ) {
$dumN = stripNamespace($s);
if(catch(` delete ($s+"*Cons") `)) {}
if(catch(` delete ($prefix+$dumN+"*Cons") `)) {}
string $myparent[] = `listRelatives -parent $s`;
if(catch(` parent ($prefix+$dumN) $myparent`)) {}
if(catch(` parent $s ($prefix+$dumN) `)) {}
}
};
global proc swapDummy(int $switch, string $prefix, string $flag){
global float $BIGNUMBER_PLUS;
cycleCheck -e off;
string $sel[] = `ls -sl`;
string $dumN = "";
if ($switch != 0){
for ( $s in $sel ) {
$dumN = stripNamespace($s);
if(catch(` delete ($s+"*Cons") `)) {}
if(catch(` delete ($prefix+$dumN+"*Cons") `)) {}
if ((`match "t" $flag`) == "t"){
cutKey -cl -t ":" -at "tx" -at "ty" -at "tz" ($prefix+$dumN);
consAndFindSetKeys("tx", $prefix+$dumN, $s, $s, 0, $BIGNUMBER_PLUS);
consAndFindSetKeys("ty", $prefix+$dumN, $s, $s, 0, $BIGNUMBER_PLUS);
consAndFindSetKeys("tz", $prefix+$dumN, $s, $s, 0, $BIGNUMBER_PLUS);
if(catch(` pointConstraint ($prefix+$dumN) $s `)) {}
}
if ((`match "r" $flag`) == "r"){
cutKey -cl -t ":" -at "rx" -at "ry" -at "rz" ($prefix+$dumN);
consAndFindSetKeys("rx", $prefix+$dumN, $s, $s, 0, $BIGNUMBER_PLUS);
consAndFindSetKeys("ry", $prefix+$dumN, $s, $s, 0, $BIGNUMBER_PLUS);
consAndFindSetKeys("rz", $prefix+$dumN, $s, $s, 0, $BIGNUMBER_PLUS);
if(catch(` orientConstraint ($prefix+$dumN) $s `)) {}
}
}
} else {
for ( $s in $sel ) {
$dumN = stripNamespace($s);
if(catch(` delete ($s+"*Cons") `)) {}
if(catch(` delete ($prefix+$dumN+"*Cons") `)) {}
if ((`match "t" $flag`) == "t"){
if(catch(` cutKey -cl -t ":" -at "tx" -at "ty" -at "tz" ($s) `)){}
consAndFindSetKeys("tx", $s, $prefix+$dumN, $prefix+$dumN, 0, $BIGNUMBER_PLUS);
consAndFindSetKeys("ty", $s, $prefix+$dumN, $prefix+$dumN, 0, $BIGNUMBER_PLUS);
consAndFindSetKeys("tz", $s, $prefix+$dumN, $prefix+$dumN, 0, $BIGNUMBER_PLUS);
if(catch(` pointConstraint $s ($prefix+$dumN) `)) {}
}
if ((`match "r" $flag`) == "r"){
if(catch(` cutKey -cl -t ":" -at "rx" -at "ry" -at "rz" ($s) `)){}
consAndFindSetKeys("rx", $s, $prefix+$dumN, $prefix+$dumN, 0, $BIGNUMBER_PLUS);
consAndFindSetKeys("ry", $s, $prefix+$dumN, $prefix+$dumN, 0, $BIGNUMBER_PLUS);
consAndFindSetKeys("rz", $s, $prefix+$dumN, $prefix+$dumN, 0, $BIGNUMBER_PLUS);
if(catch(` orientConstraint $s ($prefix+$dumN) `)) {}
}
}
}
};
global proc consAndFindSetKeys (string $attr, string $node, string $source, string $timeSource, float $minFrame, float $maxFrame){
global float $BIGNUMBER_MINUS;
float $tmpTime = $minFrame - $BIGNUMBER_MINUS; // for setkey at start frame.
float $prevTime = 0;
float $hogemage = 1;
float $max = $maxFrame;
while ($hogemage){
$prevTime = $tmpTime;
$tmpTime = findAndSetKey($attr, $node, $source, $timeSource, $tmpTime);
if ($tmpTime == $prevTime) { $hogemage = 0; }
if ($tmpTime > $max) { $hogemage = 0; }
}
};
global proc float findAndSetKey (string $attr, string $node, string $source, string $timeSource, float $tmpTime){
$tmpTime = `findKeyframe -at $attr -time $tmpTime -which next $timeSource`;
//mes($tmpTime+"\n");
currentTime($tmpTime);
//mes($source);
//mes($node);
if(catch(` pointConstraint $source $node `)) {}
if(catch(` orientConstraint $source $node `)) {}
setKeyframe -at $attr -time $tmpTime $node;
if(catch(` delete ($node+ "_pointConstraint1") ` )){}
if(catch(` delete ($node+ "_orientConstraint1") ` )){}
return $tmpTime;
};
global proc selectFilter(string $attr){
string $sel[] = `ls -sl`;
select -cl;
for ($s in $sel) {
select -add ( $s +"."+ $attr );
};
}
global proc dumpCons(string $mdlName){
string $tmp = $mdlName+":*Constraint*";
select $tmp;
string $allCons[] = `ls -sl`;
for ($node in $allCons){
print $node;
print ",";
print `orientConstraint -q -tl $node`;
}
}
global proc dumpRotate() {
string $attrs[] = getAttributes("rotate");
for ($attr in $attrs) mes($attr);
}
global proc dumpTrans() {
string $attrs[] = getAttributes("translate");
for ($attr in $attrs) mes($attr);
}
global proc mes ( string $mes ){
print $mes;
print "\n";
}
/// rename
global proc stripNameSpace ( string $ns ){
string $tmp = $ns + ":*";
select $tmp;
string $sel[];
$sel = `ls -sl`;
select -cl;
$tmp = $ns + ":";
for ( $s in $sel ){
rename $s `substitute $tmp $s ""`;
print "\n";
};
}
global proc string[] getAttributes (string $attr) {
string $sel[] = `ls -sl`;
float $tmp[];
string $tmpS="";
string $res[];
string $hoge;
string $exp = "."+$attr;
int $i = 0;
for ($node in $sel){
$tmpS = $node+$exp;
$tmp = `getAttr $tmpS`;
$hoge = $tmpS+","+$tmp[0]+","+$tmp[1]+","+$tmp[2];
$res[$i] = $hoge;
$i++;
};
return $res;
}
global proc float[] getRot ( string $target) {
string $tmp = $target+".jointOrient";
float $res[] = `getAttr $tmp`;
return $res;
}
proc string getSceneName() {
string $tmpls[] = `file -q -l`;
string $currentScenePath = $tmpls[0];
string $exp = ".*\/";
string $new = `substitute $exp $currentScenePath ""`;
$exp = "\.mb";
$new = `substitute $exp $new ""`;
$exp = "_[a-zA-Z]+";
string $st = `substitute $exp $new ""`;
$st = `substitute $exp $st ""`;
$st = `substitute $exp $st ""`;
$st = `substitute $exp $st ""`;
return $st;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment