// =========================================================================== // 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 saveAEFilterPreset() // // Description: // A callback to save an AE filter preset // { string $OK = (uiRes("m_saveAEFilterPreset.kOK")); string $cancel = (uiRes("m_saveAEFilterPreset.kCancel")); string $result = `promptDialog -title (uiRes("m_saveAEFilterPreset.kSavePreset")) -message (uiRes("m_saveAEFilterPreset.kEnterPresetName")) -text (uiRes("m_saveAEFilterPreset.kPresetName")) -button $OK -button $cancel -defaultButton $OK -cancelButton $cancel -dismissString $cancel`; // If the result was "OK", then proceed // if ( $result == $OK ) { // Get the tag the user entered // string $newPreset = `promptDialog -q`; if( $newPreset == "" ){ warning((uiRes("m_saveAEFilterPreset.kTypeMissing"))); return; } string $filterPresets[]; if( `optionVar -exists AEshowPresets` ){ $filterPresets = `optionVar -query AEshowPresets`; } int $numFilterPresets = size($filterPresets); if( $numFilterPresets == 0 ){ // First one, just add it. // optionVar -sva AEshowPresets $newPreset; } else if( strcmp( $newPreset, $filterPresets[$numFilterPresets-1] ) > 0 ){ // New preset is last, so we can simply append it. // optionVar -sva AEshowPresets $newPreset; } else { // Insert preset, if it hasn't already been added // if( !stringArrayContains( $newPreset, $filterPresets ) ){ // We need to rebuild the option var to keep it sorted // optionVar -remove AEshowPresets; int $addNewPreset = true; int $presetIndex = 0; while( $presetIndex < $numFilterPresets ){ string $currPreset = $filterPresets[$presetIndex]; if( $addNewPreset ){ if( strcmp( $currPreset, $newPreset ) > 0 ){ // We need to add the new preset // optionVar -sva AEshowPresets $newPreset; $addNewPreset = false; } } optionVar -sva AEshowPresets $filterPresets[$presetIndex]; $presetIndex++; } } } string $filterTypesVar = ($newPreset + "AEShowFilterTypes"); string $filterStatesVar = ($newPreset + "AEShowFilterStates"); if( `optionVar -exists $filterTypesVar` ){ optionVar -remove $filterTypesVar; optionVar -remove $filterStatesVar; } string $filterTypes[]; if( `optionVar -exists activeAEShowFilterTypes` ){ $filterTypes = `optionVar -query activeAEShowFilterTypes`; } int $numFilterTypes = size($filterTypes); int $filterStates[]; if( `optionVar -exists activeAEShowFilterStates` ){ $filterStates = `optionVar -query activeAEShowFilterStates`; } int $numFilterStates = size($filterStates); int $filterIndex = 0; while( $filterIndex < $numFilterTypes ){ optionVar -sva $filterTypesVar $filterTypes[$filterIndex]; int $show = 1; // Default value is 1 (i.e., on) if( $filterIndex < $numFilterStates ){ $show = $filterStates[$filterIndex]; } optionVar -iva $filterStatesVar $show; $filterIndex++; } } global string $gAEFocusNode; if( $gAEFocusNode != "" ){ updateAE $gAEFocusNode; } }