Here's the code to just bake down your layers;
animLayerMerge( `ls -type animLayer` )
But... why not just add that into the main maya ui? It's easy!Firstly, the script that has the layer tab's creation scripts, useful to have a look through so you know what you are going to try and attach your shiny new button to;
C:\Program Files\Autodesk\Maya2015\scripts\startup\layerEditor.mel
To add a new button we need to know a couple of things, what layout to put it in and possibly what other button to align it to.
Looking through that file, you'll eventually find this lot at around line 287
string $lanimLayerWeightTextName = $toolName + "WeightText";
string $lanimLayerWeightFieldName = $toolName + "WeightField";
string $lanimLayerWeightSliderName = $toolName + "WeightSlider";
string $lanimLayerWeightButtonName = $toolName + "WeightButton";
string $lanimLayerMoveUpButtonName = $toolName + "MoveUpButton";
string $lanimLayerMoveDownButtonName = $toolName + "MoveDownButton";
Some button names!You can then find UI elements in maya via mel, find their parent layout and stick in a new button. Lucky you I've done the hard part and you can just run the scripts at the bottom of this page. Once you have run those, execute this line:
addButton("*MoveUpButton*", "animLayerMerge( `ls -type animLayer` )" , "refresh.png" , "merge all the layers" );
It should add a green refresh icon next to the move
layers up/down buttons. Pressing this should merge all your animation
layers down to the base layer.The addButton command can be used to add other functions by changing the second argument. CHange the third one for the icon filename and finally the last one is an annotation. Right now this only works on formlayouts but I will amend that in the future if anyone ever reads this page :p
The actual scripts
Find the ui element based on a name given
global proc string findUI(string $name)
{
//takes a name of a possible ui element and looks through all the ui to try to find it
string $allUI[] = `lsUI -controls`;
string $result;
for($each in $allUI)
{
if (`gmatch $each $name`)
{
print ("found matching UI :: " + $each +"\n");
$result = $each;
}
}
return $result;
}
Adds a button to a formlayout and attaches it to the left of the button you searched for global proc addButton(string $UI, string $cmd, string $icon, string $annotation)
{
string $uiElement = `findUI( $UI )`;
string $type = `objectTypeUI $uiElement`;
print ($type+"\n");
string $parent = eval($type + " -query -parent " + $uiElement);
print ("parent layout " + $parent+"\n");
$mergeAnimLayerButton = `symbolButton -image $icon -annotation $annotation -parent $parent`;
//attach to the layout, your boned if it's not a formlayout tho
formLayout -edit
-attachForm $mergeAnimLayerButton "top" 1
-attachControl $mergeAnimLayerButton "right" 1 ($parent+"|"+$uiElement)
-attachNone $mergeAnimLayerButton "bottom"
-attachNone $mergeAnimLayerButton "left"
$parent;
symbolButton -edit -command ($cmd) $mergeAnimLayerButton;
}
}
No comments:
Post a Comment