// =========================================================================== // 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. // =========================================================================== global proc addAEFilters( string $nodes[] ) // // Description: // Given an array of nodes, build an array of node types, and add a // corresponding filter based on that type, if one does not already exist. // { // First, determine active filter types // string $oldFilterTypes[]; if( `optionVar -exists activeAEShowFilterTypes` ){ $oldFilterTypes = `optionVar -query activeAEShowFilterTypes`; } int $numOldTypes = size($oldFilterTypes); int $oldFilterStates[]; if( `optionVar -exists activeAEShowFilterStates` ){ $oldFilterStates = `optionVar -query activeAEShowFilterStates`; } int $numOldStates = size($oldFilterStates); // Next, determine new filter types that user wants to add // string $nodeTypes[]; int $numNodes = size($nodes); int $nodeIndex = 0; int $typeIndex = 0; while( $nodeIndex < $numNodes ){ $currNode = $nodes[$nodeIndex]; $currType = `nodeType $currNode`; if( !`stringArrayContains $currType $nodeTypes` && ( ($numOldTypes == 0) || !`stringArrayContains $currType $oldFilterTypes` ) ){ $nodeTypes[$typeIndex] = $currType; $typeIndex++; } if( $currType == "transform" ){ // User probably meant the child of this transform // string $children[] = `listRelatives $currNode`; int $numChildren = size($children); int $childIndex = 0; while( $childIndex < $numChildren ){ $currNode = $children[$childIndex]; $currType = `nodeType $currNode`; if( !`stringArrayContains $currType $nodeTypes` && ( ($numOldTypes == 0) || !`stringArrayContains $currType $oldFilterTypes` ) ){ $nodeTypes[$typeIndex] = $currType; $typeIndex++; } $childIndex++; } } $nodeIndex++; } // No new one? Bail... // if( $typeIndex == 0 ){ warning( (uiRes("m_addAEFilters.kNoNewFilterTypes")) ); return; } int $numNewTypes = $typeIndex; string $newFilterTypes[] = sort( $nodeTypes ); // Get confirmation before going ahead // string $yes = (uiRes("m_addAEFilters.kYes")); string $cancel = (uiRes("m_addAEFilters.kCancel")); string $listOfTypes; $listOfTypes = $newFilterTypes[0]; $typeIndex = 1; while( $typeIndex < $numNewTypes ){ $listOfTypes = $listOfTypes + ", " + $newFilterTypes[$typeIndex]; $typeIndex++; } string $confirmFmt = (uiRes("m_addAEFilters.kConfirmFmt")); string $confirmTxt = `format -s $listOfTypes $confirmFmt`; string $result = `confirmDialog -message $confirmTxt -button $yes -button $cancel -defaultButton $yes`; // If the result was "yes", then proceed // if ( $result == $yes ) { // We generally need to rebuild the entire list... // if( $numOldTypes > 0 ){ optionVar -remove activeAEShowFilterTypes; } if( $numOldStates > 0 ){ optionVar -remove activeAEShowFilterStates; } if( $numOldTypes == 0 ){ // We need to add "other" first // optionVar -sva activeAEShowFilterTypes ""; optionVar -iva activeAEShowFilterStates 1; } // Add one more entry to old & new list, so we can read one beyond the // array, without having to check bounds. One more is sufficient, // because we'll never let the index get any bigger than the true // number of entries in the array. // $oldFilterTypes[$numOldTypes] = ""; $newFilterTypes[$numNewTypes] = ""; int $oldIndex = 0; int $newIndex = 0; string $oldType; if( $numOldTypes > 0 ){ $oldType = $oldFilterTypes[0]; } string $newType = $newFilterTypes[0]; while( ($oldIndex < $numOldTypes) || ($newIndex < $numNewTypes) ){ int $addOldType = true; if( $oldIndex == $numOldTypes ){ $addOldType = false; } else if( $newIndex < $numNewTypes ){ $addOldType = (strcmp( $oldType, $newType ) < 0); } int $state = 1; string $typeToAdd; if( $addOldType ){ // Add the old one // $typeToAdd = $oldType; if( $oldIndex < $numOldStates ){ $state = $oldFilterStates[$oldIndex]; } $oldIndex++; $oldType = $oldFilterTypes[$oldIndex]; } else { // Add the new one // $typeToAdd = $newType; $newIndex++; $newType = $newFilterTypes[$newIndex]; } optionVar -sva activeAEShowFilterTypes $typeToAdd; optionVar -iva activeAEShowFilterStates $state; } updateAEshowAllButton(); } global string $gAEFocusNode; if( $gAEFocusNode != "" ){ updateAE $gAEFocusNode; } }