// =========================================================================== // 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. // =========================================================================== // // // // // lockContainer // // // None // // // This script locks the unpublished attributes and nodes // in the container associated with the selected nodes, // as well as locking the container itself. // // // int $val if 1, lock the unpublished attributes and nodes // in the container and the container itself, if 0 unlock // // // // lock the container that locator1 is in // select -r locator1; // lockContainer 1; // // // global proc lockContainer(int $val) { string $containersToLock[]; string $sel[] = `ls -sl`; string $lastContainer = ""; for ($obj in $sel) { string $container; if (`container -q -isContainer $obj`) { $container = $obj; } else { $container = `container -q -fc { $obj }`; } if ("" != $container && $lastContainer != $container) { if (! stringArrayContains($container,$containersToLock)) { $containersToLock[size($containersToLock)] = $container; $lastContainer = $container; } } } int $count = size($containersToLock); if ($count == 0) { error((uiRes("m_lockContainer.kMustSelectContainer"))); } int $successCount = 0; for ($container in $containersToLock) { int $locked[] = `lockNode -q -lu $container`; if ($val == $locked[0]) { string $format; if ($val) { $format = (uiRes("m_lockContainer.kAlreadyLockedContainer")); } else { $format = (uiRes("m_lockContainer.kAlreadyUnlockedContainer")); } $msg = `format -stringArg $container $format`; warning $msg; } else { string $cmd = ("lockNode -lockUnpublished "+$val+" "+$container); evalEcho $cmd; int $locked[] = `lockNode -q -lu $container`; if ($val == $locked[0]) { $successCount++; $cmd = ("lockNode -lock "+$val+" "+$container); eval $cmd; } } } if ($successCount > 0) { string $format; string $msg; if ($count == 1) { if ($val) { $format = (uiRes("m_lockContainer.kLockedContainer")); } else { $format = (uiRes("m_lockContainer.kUnlockedContainer")); } $msg = `format -stringArg $containersToLock[0] $format`; } else { if ($val) { $format = (uiRes("m_lockContainer.kLockedSomeContainers")); } else { $format = (uiRes("m_lockContainer.kUnlockedSomeContainers")); } $msg = `format -stringArg $successCount $format`; } print $msg; } }