// =========================================================================== // 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. // =========================================================================== // // Procedure Name: AEshowBlockIfAttrExists // // Description : // Hides Attribute Editor Blocks based on the existence of dynamic attributes to avoid empty blocks. // This command should be placed in an AE template file AFTER the layout you wish to hide. // // Input Value: // A string array containing the names of all the dynamic attributes that will cause the block to show if they exist. // The block will show if any of the named attributes exist. // // Output Value: // None // proc string showBlockGetControlName( string $str ) { // The name used for the hidden panelayout is the list of all dynamic attributes to monitor appended with AEH string $buffer[]; tokenize($str, ".", $buffer); // We strip out the object name from the control name and remove all "." string $name =stringRemovePrefix( $str, ($buffer[0] + ".")); $name = substituteAllString($name, ".", ""); return ($name+"AEH"); } proc showBlockManage( string $nodeAttr, string $controlName ) { // nodeAttr contains all the dynamic attributes we need to test separated by "." string $parent = `control -q -parent $controlName`; string $buffer[]; tokenize($nodeAttr, ".", $buffer); int $visible = false; int $i; for( $i = 1; $i < size( $buffer ); $i++ ){ string $attr = $buffer[0] + "."+$buffer[$i]; if( objExists ($attr) ){ // if any attribute exists then the block should be displayed $visible = true; break; } } // When there is nothing to show, we should hide control's parent column layout // as well. This column layout is created when call editorTemplate -callCustom and // will display some unwanted gap if it's empty. // This is not aesthetically pleasing. So let's hide this column layout when there // is nothing to show. if ($visible == false) { if (`columnLayout -exists $parent`) columnLayout -e -visible false $parent; } else { if (`columnLayout -exists $parent`) columnLayout -e -visible true $parent; } // We now need to find the name of the layout to show or hide tokenize($parent, "|", $buffer); int $bufSize = size($buffer); if( $bufSize > 0 ){ string $myBlock = $buffer[$bufSize-1]; // remove the path from the paneLayout name // Walk all children of the parent layout. When our added layout is found we // then know the previous layout is the block to show/hide. The command // AEshowBlockIfAttrExists must be added AFTER the block to control because // the first time the block is created only early UI elements have been created. $parent = `control -q -parent $parent`; string $child[] = `layout -q -childArray $parent`; if( size($child) > 1 ){ string $controlBlock = ""; for( $i = 1; $i < size($child); $i++ ){ if( $child[$i] == $myBlock ){ $controlBlock = $child[$i-1]; break; } } if( $controlBlock != "" ){ control -e -m $visible $controlBlock; } } } } global proc AEshowBlockIfAttrNew(string $nodeAttr) { string $controlName = showBlockGetControlName( $nodeAttr ); paneLayout -vis false $controlName; setUITemplate -ppt; showBlockManage( $nodeAttr, $controlName ); } global proc AEshowBlockIfAttrReplace(string $nodeAttr) { string $controlName = showBlockGetControlName( $nodeAttr ); int $uiExists = `paneLayout -q -exists $controlName`; if( !$uiExists ){ AEshowBlockIfAttrNew( $nodeAttr ); } else { showBlockManage( $nodeAttr, $controlName ); } } global proc AEshowBlockIfAttrExists(string $attr[]) { // code list of attrs into a single string which is used to uniquely // name a hidden pane layout inserted after the block to control string $str = stringArrayToString($attr, "."); editorTemplate -callCustom "AEshowBlockIfAttrNew" "AEshowBlockIfAttrReplace" $str; }