MAXSCRIPT: Cycling through views in active viewport

by

Since I consider using viewport cube a suboptimal, slow way to get certain view, and most of keyboard keys re-binded to different things, I've wrote a quick cycle script to bind under one key/key combination (on my side, its either ctrl+space or shift-space). Its divided to two functions:

macroScript viewportToggle category:"_Piro_Tools" tooltip:"UI: viewportToggle" buttontext:"UI: viewportToggle"
(
    
    fn showGrid_fn =
        (
            for i = 1 to viewport.numViews do ( viewport.setGridVisibility i true )
        )

    fn hideGrid_fn =
        (
            for i = 1 to viewport.numViews do ( viewport.setGridVisibility i false )
        )

    viewportType = viewport.getType()
    case viewportType of
        (
        #view_front:         (viewport.setType(#view_left); showGrid_fn();)
        #view_back:         (viewport.setType(#view_left); showGrid_fn();)
                
        #view_left:         (viewport.setType(#view_top); showGrid_fn();)
        #view_right:         (viewport.setType(#view_top); showGrid_fn();)
            
        #view_top:            (viewport.setType(#view_front); viewport.setType(#view_persp_user); hideGrid_fn();)
        #view_bottom:        (viewport.setType(#view_front); viewport.setType(#view_persp_user); hideGrid_fn();)
        
        #view_persp_user:    (viewport.setType(#view_front); showGrid_fn();)
        #view_iso_user:        (viewport.setType(#view_front); showGrid_fn();)            
        )    

which is default cycling, and

macroScript viewportToggleAlt category:"_Piro_Tools" tooltip:"UI: viewportToggleAlt" buttontext:"UI: viewportToggleAlt"
(
    
    fn showGrid_fn =
        (
            for i = 1 to viewport.numViews do ( viewport.setGridVisibility i true )
        )

    fn hideGrid_fn =
        (
            for i = 1 to viewport.numViews do ( viewport.setGridVisibility i false )
        )

    viewportType = viewport.getType()
    case viewportType of
        (
        #view_front:         (viewport.setType(#view_back); showGrid_fn();)
        #view_back:         (viewport.setType(#view_front); showGrid_fn();)
            
        #view_left:         (viewport.setType(#view_right); showGrid_fn();)
        #view_right:         (viewport.setType(#view_left); showGrid_fn();)
            
        #view_top:            (viewport.setType(#view_bottom); showGrid_fn();)
        #view_bottom:        (viewport.setType(#view_top); showGrid_fn();)
                    
        #view_persp_user:    (viewport.setType(#view_front); viewport.setType(#view_iso_user); showGrid_fn();)
        #view_iso_user:        (viewport.setType(#view_front); viewport.setType(#view_persp_user); showGrid_fn();)        
        )    
        
)

Which allows you to cycle through front-back, top-bottom, persp-iso or left-right views, depending on which one is currently active.

How to use scripts? Check this post on my blog about other maxscript for instructions on bottom: MAXSCRIPT: Open Max File Location