// =========================================================================== // 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: 2001 // // Procedure Name: // setNotesAttribute // // Input Value: // Node name, attribute names and type, and new attribute value // // Output Value: // None // global proc setNotesAttribute( string $nodeName, string $longAttrName, string $shortAttrName, string $attrType, string $newAttrValue ) { if( !`objExists $nodeName` ) { return; } // Description: Sets the given "Notes" attribute on the node // to be the new value. If the attribute doesn't exist, // then create it as a dynamic attribute, and set it. // Warning! $newAttrValue is not really used here even though // it's passed in. It's checked a few times, but ultimately // `scrollField -q -text AENotesScrollFIeld` is used. // If you replace the scrollField query to use $newAttrValue // (which is the proper way to do things), then multi-line // entry into the notes area behaves strangely and // doesn't preserve carriage returns. // If the Notes attribute exists, then just update it // If the newAttrValue attribute is empty, that means // that this attribute is to be deleted. // if( `attributeQuery -exists -n $nodeName $longAttrName` ) { if( !`getAttr -lock ($nodeName + "." + $longAttrName)`) { if( size($newAttrValue) > 0 ) { // Update the Notes only if it's changed string $currentNotes = `getAttr ($nodeName + "." + $longAttrName)`; if( $currentNotes != $newAttrValue ) { $editCmd = ("setAttr " + "-type \"" + $attrType + "\" " + $nodeName + "." + $longAttrName + " `scrollField -q -text AENotesScrollField`"); if( catch( eval($editCmd)) ) { string $msgFormat = (uiRes("m_setNotesAttribute.kCantSetAttribute")); error(`format -s $nodeName -s $longAttrName $msgFormat`); } } } else { // Delete this attribute from the node // but only if the attribute is a dynamic one // string $dynamicAttrs[] = `deleteAttr -q $nodeName`; int $i; int $numAttrs = size($dynamicAttrs); for( $i = 0; $i < $numAttrs; $i ++ ) { if( $dynamicAttrs[$i] == $longAttrName ) { if( catch( deleteAttr ($nodeName + "." + $longAttrName))) { // Problem deleting attribute, // possibly because a script job still refers // to this attribute warning (uiRes("m_setNotesAttribute.kCantDelAttr")); } break; } } } } } else { // If the Notes attribute doesn't exist, then create it and set it // if( size($newAttrValue) > 0 ) { if( catch(`addAttr -dt $attrType -ln $longAttrName -sn $shortAttrName $nodeName`) ) { string $msgFormat = (uiRes("m_setNotesAttribute.kCantCreateDynAttr")); error(`format -s $nodeName -s $longAttrName -s $nodeName -s $shortAttrName $msgFormat`); } else { // Do same as above and update the Notes attr // $editCmd = ("setAttr " + "-type \"" + $attrType + "\" " + $nodeName + "." + $longAttrName + " `scrollField -q -text AENotesScrollField`"); if( catch( eval($editCmd)) ) { string $msgFormat = uiRes("m_setNotesAttribute.kCantSetAttribute"); error(`format -s $nodeName -s $longAttrName $msgFormat`); } } } } }