// =========================================================================== // 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. // =========================================================================== // // // // // // clipTrimAfter(string $scheduler, int $clipIndex) // // // None // // // Script for trimming the part of a clip that is after the current time. // // // string $scheduler the scheduler containing the clip // // string $clipIndex the clip index in the scheduler // // // clipTrimBefore joeScheduler1 10; // // Via the UI, you can trim by selecting the clip and using the RMB // menu item named "Trim After". // // ///////////////////////////////////////////////////////////////////////// global proc clipTrimAfter (string $sch, int $clipIndex) { float $time = `currentTime -q`; string $clipName = `clipSchedule -ci $clipIndex -q -n $sch`; if (size($clipName)) { float $clipStartPos = `clipSchedule -ci $clipIndex -q -s $sch`; float $clipPreCycle = `clipSchedule -ci $clipIndex -q -preCycle $sch`; float $clipPostCycle = `clipSchedule -ci $clipIndex -q -postCycle $sch`; float $clipScale = `clipSchedule -ci $clipIndex -q -scale $sch`; float $clipOrigStart = `clipSchedule -ci $clipIndex -q -sourceStart $sch`; float $clipOrigEnd = `clipSchedule -ci $clipIndex -q -sourceEnd $sch`; float $clipDuration = ($clipOrigEnd - $clipOrigStart); float $clipHold = `getAttr ($clipName+".hold")`; float $basicClipStart = $clipStartPos; float $basicClipEnd = $clipStartPos + ($clipDuration * $clipScale); float $clipStart = $basicClipStart - ($clipPreCycle * $clipDuration * $clipScale); float $clipEnd = $basicClipEnd + ($clipPostCycle * $clipDuration * $clipScale) + $clipHold; // Verify that the time is within the range of the clip if ($time < $clipStart || $time > $clipEnd) { string $errmsg = (uiRes("m_clipTrimAfter.kTimeIsNotBetween")); error(`format -s $time -s $clipName $errmsg`); } if ($clipPreCycle > 0.0) { error((uiRes("m_clipTrimAfter.kCantTrimAfter"))); } // Compute the amount to trim the clip string $cmd; if ($time > $basicClipEnd) { if ($time > ($clipEnd - $clipHold)) { float $newHold = $time - ($clipEnd - $clipHold); $cmd = ("setAttr "+$clipName+".hold "+$newHold); } else { float $newCycle = ($time - $basicClipEnd) / ($clipDuration * $clipScale); $cmd = ("setAttr "+$clipName+".postCycle "+$newCycle); $cmd += ("; setAttr "+$clipName+".hold 0.0"); } } else if ($time > $basicClipStart) { if ($clipPostCycle > 0.0) { $cmd = ("setAttr "+$clipName+".postCycle 0.0; "); } float $newEnd = $clipOrigEnd - ($basicClipEnd - $time) / $clipScale; $cmd += ("setAttr "+$clipName+".sourceEnd "+$newEnd); } evalEcho $cmd; } else { error((uiRes("m_clipTrimAfter.kClipNotFound"))); } } global proc cacheClipTrimAfter (string $clipName, float $time) { if (size($clipName)) { float $clipStartPos = `getAttr ($clipName+".startFrame")`; float $clipPreCycle = `getAttr ($clipName+".preCycle")`; float $clipPostCycle = `getAttr ($clipName+".postCycle")`; float $clipScale = `getAttr ($clipName+".scale")`; float $clipOrigStart =`getAttr ($clipName+".sourceStart")`; float $clipOrigEnd = `getAttr ($clipName+".sourceEnd")`; float $clipDuration = ($clipOrigEnd - $clipOrigStart); float $clipHold = `getAttr ($clipName+".hold")`; float $basicClipStart = $clipStartPos; float $basicClipEnd = $clipStartPos + ($clipDuration * $clipScale); float $clipStart = $basicClipStart - ($clipPreCycle * $clipDuration * $clipScale); float $clipEnd = $basicClipEnd + ($clipPostCycle * $clipDuration * $clipScale) + $clipHold; // Verify that the time is within the range of the clip if ($time < $clipStart || $time > $clipEnd) { string $errmsg = uiRes("m_clipTrimAfter.kTimeIsNotBetween"); error(`format -s $time -s $clipName $errmsg`); } if ($clipPreCycle > 0.0) { error( uiRes("m_clipTrimAfter.kCantTrimAfter") ); } // Compute the amount to trim the clip string $cmd; if ($time > $basicClipEnd) { if ($time > ($clipEnd - $clipHold)) { float $newHold = $time - ($clipEnd - $clipHold); $cmd = ("setAttr "+$clipName+".hold "+$newHold); } else { float $newCycle = ($time - $basicClipEnd) / ($clipDuration * $clipScale); $cmd = ("setAttr "+$clipName+".postCycle "+$newCycle); $cmd += ("; setAttr "+$clipName+".hold 0.0"); } } else if ($time > $basicClipStart) { if ($clipPostCycle > 0.0) { $cmd = ("setAttr "+$clipName+".postCycle 0.0; "); } float $newEnd = $clipOrigEnd - ($basicClipEnd - $time) / $clipScale; $cmd += ("setAttr "+$clipName+".sourceEnd "+$newEnd); } evalEcho $cmd; } else { error( uiRes("m_clipTrimAfter.kClipNotFound") ); } } global proc shotTrimAfter (string $clipName, float $time) { if (size($clipName)) { float $clipStartPos = `getAttr ($clipName+".sequenceStartFrame")`; float $clipEndPos = `getAttr ($clipName+".sequenceEndFrame")`; float $clipScale = `getAttr ($clipName+".scale")`; float $clipOrigStart =`getAttr ($clipName+".startFrame")`; float $clipOrigEnd = `getAttr ($clipName+".endFrame")`; float $clipDuration = ($clipOrigEnd - $clipOrigStart); float $clipPostHold = `getAttr ($clipName+".postHold")`; float $clipPreHold = `getAttr ($clipName+".preHold")`; float $basicClipStart = $clipStartPos + $clipPreHold; float $basicClipEnd = $clipPreHold + $clipStartPos + ($clipDuration * $clipScale); // Verify that the time is within the range of the clip if ($time < $clipStartPos || $time > $clipEndPos) { string $errmsg = uiRes("m_clipTrimAfter.kTimeIsNotBetween"); error(`format -s $time -s $clipName $errmsg`); } // Compute the amount to trim the clip string $cmd; if ($time > $basicClipEnd) { // inside the post-hold float $newHold = $time - $basicClipEnd; $cmd = ("setAttr "+$clipName+".postHold "+$newHold); }else if ($time > $basicClipStart) { // inside the basic clip float $newEnd = $clipOrigEnd - ($basicClipEnd - $time) / $clipScale; $cmd += ("setAttr "+$clipName+".endFrame "+$newEnd); $cmd += ("; setAttr "+$clipName+".postHold 0.0"); } else { // inside pre-hold only... $cmd += ("; setAttr "+$clipName+".endFrame "+$clipOrigStart); $cmd += ("; setAttr "+$clipName+".scale 1.0"); float $newPreHold = $time - $clipStartPos; $cmd += ("; setAttr "+$clipName+".preHold "+$newPreHold); $cmd += ("; setAttr "+$clipName+".postHold 0.0"); } evalEcho $cmd; } else { error( uiRes("m_clipTrimAfter.kClipNotFound") ); } }