// =========================================================================== // Copyright 2018 Autodesk, Inc. All rights reserved. // // Use of this software is subject to the terms of the Autodesk license // agreement provided at the time of installation or download, or which // otherwise accompanies this software in either electronic or hard copy form. // =========================================================================== // // // Creation Date: August, 2015 // // // Procedure Name: // cteCreateLayerClip // // Description: // Create layer clip from selection and related functions // // Input Arguments: // clip id. // // Return Value: // None. // proc int teFindLayerPlugIndex(string $clipNode, int $layerId) { int $layerIndexes[] = `getAttr -mi ($clipNode+".layer")`; int $layerPlugIndex; for ($layerPlugIndex in $layerIndexes) { string $id = `getAttr ($clipNode+".layer["+$layerPlugIndex+"].layerId")`; if ($id == $layerId) return $layerPlugIndex; } return -1; } global proc teCreateClipLayerBySelection(int $id, int $mode) { // get the first clip id in current selected int $clipId = teGetFirstClipInSelection($id, 1); if($clipId == -1) return; // get a list of selected objects. string $selectedObjects[] = `ls -selection`; if (size($selectedObjects) == 0) return; // create new layer for the given clip. string $newLayerName = ""; int $layerId = `timeEditorClipLayer -e -clipId $clipId -mode $mode -addLayer $newLayerName`; // get a list of selected attributes. string $selectedAttributes[] = `channelBox -q -sma mainChannelBox`; // if no attributes are selected, add all attributes from that object. if (size($selectedAttributes) == 0) { for ($obj in $selectedObjects) { catchQuiet(`timeEditorClipLayer -e -clipId $clipId -layerId $layerId -addObject $obj`); // need to catch quiet so that if invalid object is selected, the error won't break the loop } } else { // add attributes to the layer. for ($obj in $selectedObjects) { for ($attr in $selectedAttributes) { string $attrStr = $obj + "." + $attr; catchQuiet(`timeEditorClipLayer -e -clipId $clipId -layerId $layerId -addAttribute $attrStr`); // need to catch quiet so that if invalid object or attribute is selected, the error won't break the loop } } } // select the new layer string $clipNode = `timeEditorClip -q -clipNode $clipId`; int $layerPlugIndex = teFindLayerPlugIndex($clipNode, $layerId); if ($layerPlugIndex != -1) { select -add ($clipNode+".layer["+$layerPlugIndex+"]"); } } global proc teAddSelectionToLayer(int $clipId, int $layerId) { global string $gChannelBoxName; string $selectedObjectsArray[] = `channelBox -q -mol $gChannelBoxName`; // get all object used in the channel box string $selectedAttributesArray[] = `channelBox -q -sma $gChannelBoxName`; // get all attributes selected in the channel box if(size($selectedAttributesArray) == 0) // if no attributes selected, we just add all attributes { for($currentObject in $selectedObjectsArray) // loop through every single object in the channel box { catchQuiet(`timeEditorClipLayer -edit -clipId $clipId -layerId $layerId -addObject $currentObject`); } } else // else we only add selected attributes from the object { for($currentObject in $selectedObjectsArray) // loop through every single object in the channel box { for($currentAttribute in $selectedAttributesArray) // loop through every single attributes selected in the channel box { if(catchQuiet(`timeEditorClipLayer -edit -clipId $clipId -layerId $layerId -addAttribute ($currentObject + "." + $currentAttribute)`)) { string $warningMsg = (uiRes("m_teCreateClipLayer.kCTEAddSelectionWarningMsg")); $warningMsg = `format -s $currentObject -s $currentAttribute $warningMsg`; warning($warningMsg); } } } } } global proc teRemoveSelectionFromLayer(int $clipId, int $layerId) { global string $gChannelBoxName; string $selectedObjectsArray[] = `channelBox -q -mol $gChannelBoxName`; // get all object used in the channel box string $selectedAttributesArray[] = `channelBox -q -sma $gChannelBoxName`; // get all attributes selected in the channel box if(size($selectedAttributesArray) == 0) // if no attributes selected, we just remove all attributes { for($currentObject in $selectedObjectsArray) // loop through every single object in the channel box { catchQuiet(`timeEditorClipLayer -edit -clipId $clipId -layerId $layerId -removeObject $currentObject`); } } else // else we only remove selected attributes from the object { for($currentObject in $selectedObjectsArray) // loop through every single object in the channel box { for($currentAttribute in $selectedAttributesArray) // loop through every single attributes selected in the channel box { if(catchQuiet(`timeEditorClipLayer -edit -clipId $clipId -layerId $layerId -removeAttribute ($currentObject + "." + $currentAttribute)`)) { string $warningMsg = (uiRes("m_teCreateClipLayer.kCTERemoveSelectionWarningMsg")); $warningMsg = `format -s $currentObject -s $currentAttribute $warningMsg`; warning($warningMsg); } } } } }