// =========================================================================== // 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. // =========================================================================== // // // // // containerCreateBindingSet // // // None // // // This script creates a or updates a binding set on the template // associated with a container. The container is used as reference to // generate the binding set mappings. // // // string $container, the container to use, or "" to use selected // string $bindingSet, the bindingSet to use, or "" have default // bindingSet name determined automatically // int $updateMode when true, indicates that the binding set exists and is // being updated. // int $forceUpdate when true, indicates that the update will replace // existing entries in the binding set. When false, // existing binding set entries will be left as-is. // // // // Create new binding set "MyBindings". // containerCreateBindingSet(myContainer, "MyBindings", 0, 0); // // // Update an existing binding set. // // Since force option is not used, existing bindings will not be replaced, // // only new entries will be added. // containerCreateBindingSet(myContainer, "MyBindings", 1, 0); // // // Update an existing binding set. // // Since force option is used, existing bindings will be refreshed with // // the current bindings of the reference container. // containerCreateBindingSet(myContainer, "MyBindings", 1, 1); // // // Create a new binding set. Since the binding set name is not // // specified, the new binding set will use a default binding set name. // containerCreateBindingSet(myContainer, "", 0, 0); // // // Update the default binding set based on the reference container. // // Since force option is used, all entries will be refreshed. // containerCreateBindingSet(myContainer, "", 1, 1); // // // // global proc containerCreateBindingSet(string $container, string $bindingSetName, int $updateMode, int $updateForce) { // Use default binding set name if one is not passed in string $bsName = $bindingSetName; if (size($bsName) == 0) { $bsName = containerDefaultBindingSet(); } // Check that container has a template associated with it, the template // exists and it is loaded. string $templateName = `getAttr ($container + ".templateName")`; string $templatePath = `getAttr ($container + ".templatePath")`; if( $templateName == "" ) { string $fmt = (uiRes("m_containerCreateBindingSet.kNoTemplateOnContainer")); string $msg = `format -stringArg $container $fmt`; error($msg); } if (! `containerTemplate -exists $templateName`) { containerTemplate -load -fn $templatePath $templateName; } // Check if the named binding set already exists on this template. string $bsList[] = `containerTemplate -q -bsl $templateName`; int $bsExists = stringArrayContains($bsName,$bsList); // In create mode make sure the binding set does not exist yet if (!$updateMode && $bsExists) { string $fmt = (uiRes("m_containerCreateBindingSet.kExists")); string $msg = `format -stringArg $bsName -stringArg $container $fmt`; error ($msg); } // In update mode, make sure it does else if ($updateMode && !$bsExists) { string $fmt = (uiRes("m_containerCreateBindingSet.kNotFound")); string $msg = `format -stringArg $bsName -stringArg $container $fmt`; error ($msg); } // Update or create the binding set if ($updateMode) { if ($updateForce) { containerTemplate -edit -force -updateBindingSet $bsName -fromContainer $container $templateName; } else { containerTemplate -edit -updateBindingSet $bsName -fromContainer $container $templateName; } containerTemplate -save $templateName; } else { // Create it containerTemplate -edit -addBindingSet $bsName -fromContainer $container $templateName; containerTemplate -save $templateName; } }