// =========================================================================== // 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. // =========================================================================== // // // // // // clipTrimBefore(string $scheduler, int $clipIndex) // // // None // // // Script for trimming the part of a clip that is before 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 Before". // ///////////////////////////////////////////////////////////////////////// global proc clipTrimBefore (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 $basicClipStart = $clipStartPos; float $basicClipEnd = $clipStartPos + ($clipDuration * $clipScale); float $clipStart = $basicClipStart - ($clipPreCycle * $clipDuration * $clipScale); float $clipEnd = $basicClipEnd + ($clipPostCycle * $clipDuration * $clipScale); // 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 ($clipPostCycle > 0.0) { error( (uiRes("m_clipTrimBefore.kCantTrimBefore")) ); } // Compute the amount to trim the clip string $cmd; if ($time < $basicClipStart) { float $newCycle = ($basicClipStart - $time) / ($clipDuration * $clipScale); $cmd = ("setAttr "+$clipName+".preCycle "+$newCycle); } else if ($time < $basicClipEnd) { if ($clipPreCycle > 0.0) { $cmd = ("setAttr "+$clipName+".preCycle 0.0; "); } float $newStart = $clipOrigStart + ($time - $basicClipStart) / $clipScale; $cmd += ("setAttr "+$clipName+".sourceStart "+$newStart+"; "); $cmd += ("setAttr "+$clipName+".startFrame "+$time+"; "); } evalEcho $cmd; } else { error( uiRes("m_clipTrimAfter.kClipNotFound") ); } } global proc cacheClipTrimBefore (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 $basicClipStart = $clipStartPos; float $basicClipEnd = $clipStartPos + ($clipDuration * $clipScale); float $clipStart = $basicClipStart - ($clipPreCycle * $clipDuration * $clipScale); float $clipEnd = $basicClipEnd + ($clipPostCycle * $clipDuration * $clipScale); // 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 ($clipPostCycle > 0.0) { error( uiRes("m_clipTrimBefore.kCantTrimBefore") ); } // Compute the amount to trim the clip string $cmd; if ($time < $basicClipStart) { float $newCycle = ($basicClipStart - $time) / ($clipDuration * $clipScale); $cmd = ("setAttr "+$clipName+".preCycle "+$newCycle); } else if ($time < $basicClipEnd) { if ($clipPreCycle > 0.0) { $cmd = ("setAttr "+$clipName+".preCycle 0.0; "); } float $newStart = $clipOrigStart + ($time - $basicClipStart) / $clipScale; $cmd += ("setAttr "+$clipName+".sourceStart "+$newStart+"; "); $cmd += ("setAttr "+$clipName+".startFrame "+$time+"; "); } evalEcho $cmd; } else { error( uiRes("m_clipTrimAfter.kClipNotFound") ); } } global proc shotTrimBefore (string $clipName, float $time) { if (size($clipName)) { float $clipStartPos = `getAttr ($clipName+".sequenceStartFrame")`; float $clipEndPos = `getAttr ($clipName+".sequenceEndFrame")`; float $clipScale = `getAttr ($clipName+".scale")`; float $clipOffset = `getAttr ($clipName+".czo")`; float $clipOrigStart =`getAttr ($clipName+".startFrame")`; float $clipOrigEnd = `getAttr ($clipName+".endFrame")`; float $clipDuration = ($clipOrigEnd - $clipOrigStart); float $clipPreHold = `getAttr ($clipName+".preHold")`; float $clipPostHold = `getAttr ($clipName+".postHold")`; float $basicClipStart = $clipStartPos + $clipPreHold; float $basicClipEnd = $clipEndPos - $clipPostHold; // 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 < $basicClipStart) { // inside pre-hold float $newHold = $basicClipStart - $time; $cmd += ("setAttr " + $clipName+".preHold "+$newHold); $cmd += ("; setAttr " + $clipName+".sequenceStartFrame "+$time); evalEcho $cmd; } else if ($time < $basicClipEnd) { float $newStart = $clipOrigStart + ($time - $basicClipStart) / $clipScale; $cmd = ("setAttr "+$clipName+".startFrame "+$newStart+"; "); $cmd += ("; setAttr "+$clipName+".sequenceStartFrame "+$time+"; "); $cmd += ("; setAttr "+$clipName+".preHold 0; "); // Do the trim evalEcho $cmd; // Align the clip to the newly trimmed shot float $delta = $time - $clipStartPos + $clipOffset; $cmd = ("setAttr " + $clipName + ".czo " + $delta ); evalEcho $cmd; }else{ // inside post-hold $cmd = ("setAttr "+$clipName+".preHold 0; "); $cmd += ("; setAttr "+$clipName+".startFrame"+$clipOrigEnd); $cmd += ("; setAttr "+$clipName+".scale 1.0"); float $newPostHold = $clipEndPos - $time; $cmd += ("; setAttr "+$clipName+".postHold "+$newPostHold); $cmd += ("; setAttr "+$clipName+".sequenceStartFrame "+$time+"; "); evalEcho $cmd; // how to offset the clip? float $delta = $basicClipEnd - $basicClipStart + $clipOffset; $cmd = ("setAttr " + $clipName + ".czo " + $delta ); evalEcho $cmd; } } else { error( uiRes("m_clipTrimAfter.kClipNotFound") ); } }