MAXScript Tools and Interaction with 3ds Max > Change Handlers and Callbacks > Trackbar Key Filter Callback Functions >

# Trackbar Keys Filter Callback Function Examples

The following examples show possible ways to implement trackbar key filter functions:

## Visibility Keys Filter Function Examples

In order to register a filter that will display only Visibility keys,

YOU CAN SAY
    fn filterVisibilityKeys theAnim theParent theIndex theGParent theNode =
    (
    if theParent != undefined then
    theParent[theIndex].name == "Visibility"
    else
    false
    )
    fn testCallbackAdditionFunction arg1 arg2 = (true)
    theInterface = maxOps.trackbar
    theIndex = theInterface.registerFilter filterVisibilityKeys callbackAdditionFunction "Visibility" 8 active:true stopTraversal:false

The filter function will return true only when the Parent is not undefined and the subAnim indexed track of the parent is called "Visibility".

A faster and better way to define a visibility track key filter function would be
    fn filterVisibilityKeys theAnim theParent theIndex theGParent theNode = ( theIndex == 2 and theParent == theNode )

This function will return true only when the parent is the node itself and the index is 2 which corresponds to the Visibility track!

## Name and Class Filter Fun ction Examples

Obviously, you can define filter functions that will filter keys by the class or even the name of the node being traversed,

FOR EXAMPLE
     --this function will show keys only of Sphere class nodes:
    fn filterSphereKeys theAnim theParent theIndex theGParent theNode = ( classof theNode == Sphere )
     --this function will show keys only of objects whose name starts with "Sphere":
    fn filterSphereByNameKeys theAnim theParent theIndex theGParent theNode = ( substring theNode.name 1 6 == "Sphere")

## Key Count Filter Function Examples

In some cases, for example when animating using Reactor or baking animation to keys per frame using MAXScript, the trackBar could become very slow as it tries to display hundreds and even thousands of keys.

The following function will show keys only of those controllers that have less than 10 keys:

    fn filterNonMassiveKeys theAnim theParent theIndex theGParent theNode = (superClassof theAnim == FloatController and theAnim.keys.count < 10 )

Create some object in the scene, for example a Box, set the Animation mode to Set Key and start animating the position by pressing the Key button. The trackBar will display the keys of the Box until you create the 10 th key, after that all keys will be filtered out and disappear! You could define a global variable to control the number of keys to be displayed at a time,

EXAMPLE
    global maxNumberOfKeysInTrackbar = 50
    fn filterNonMassiveKeys theAnim theParent theIndex theGParent theNode = ( superClassof theAnim == FloatController and theAnim.keys.count < maxNumberOfKeysInTrackbar )

Simply changing the value stored in the global variable maxNumberOfKeysInTrackbar will control how many keys a controller may have in order to appear in the trackBar. You could even define a small dialog with a spinner and dock it in the UI to have interactive control over the keys display:

SCRIPT
    (
    try(cui.UnRegisterDialogBar MassiveKeysFilterCount)catch()
    try(destroyDialog MassiveKeysFilterCount)catch()
    global maxNumberOfKeysInTrackbar = 20
    --Define a rollout with a spinner
    rollout MassiveKeysFilterCount "Keys Limit"
    (
    spinner massive_count "Max.Keys:" range:[10,1000,20] type:#integer fieldwidth:40
    on massive_count changed val do
    maxNumberOfKeysInTrackbar = val
    select selection
    )
    --Create a dialog, register as DialogBar and dock at bottom
    createDialog MassiveKeysFilterCount 120 25
    cui.RegisterDialogBar MassiveKeysFilterCount style:#(#cui_dock_all)
    cui.DockDialogBar MassiveKeysFilterCount #cui_dock_bottom
    --Define, register and enable the key filter functions:
    fn callbackAdditionFunction arg1 arg2 = (true)
    fn filterNonMassiveKeys theAnim theParent theIndex theGParent theNode =
    (
    superClassof theAnim == FloatController and theAnim.keys.count < maxNumberOfKeysInTrackbar
    )
    theIndex = (maxOps.trackBar).registerFilter filterNonMassiveKeys callbackAdditionFunction "Massive Keys Filter" 13 active:true stopTraversal:false
    )--end script

#### See Also

- Exploring the Trackbar Filter Callback Functions

- Trackbar Interface