Kill graph windows that aren't included in the named layout

I like to use a layout for making figures. If you're disorganized like me during data analysis, you can end up with many many graph windows that aren't actually included in the layout that contains the important figures/graphs. Most of the time I don't need these extra graphs and can kill them. This function kills all graph windows that aren't included in the named layout.

Function cleanDesk(s,mode)
//Kills all graph windows that are not included in the named layout, s
//Mode: 0, leaves windows that are part of the layout visible
//Mode: 1, hides windows that are part of the layout
//Mode: 2, windows that are a part of the layout become visible if they weren't already

    String s
    variable mode
    String list,info,graphList,currentGraph
    variable numItems,numPages,i,j,graphListItems,k,match
   
    list=""
    info = LayoutInfo(s,"Layout")
    numPages = str2num(StringByKey("NUMPAGES",info,":",";"))
   
    For(j=1;j<=numPages;j+=1)
        LayoutPageAction page=j
        info = LayoutInfo(s,"Layout")
        numItems = str2num(StringByKey("NUMOBJECTS",info,":",";"))
        For(i=0;i<numItems;i+=1)
            info = LayoutInfo(s,num2str(i))
            list += StringByKey("NAME",info,":",";")+";"
        EndFor
    EndFor
    graphList = WinList("*",";","WIN:1")
    graphListItems = ItemsInList(graphList,";")
   
    For(k=0;k<graphListItems;k+=1)
        currentGraph =StringFromList(k,graphList,";")
        match = StringMatch(list,"*"+currentGraph+"*")
        If(match == 0)
            KillWindow /Z $currentGraph
        EndIf
    EndFor
   
    If(mode == 1)
        numItems = ItemsInList(list,";")
        For(i=0;i<numItems;i+=1)
            currentGraph = StringFromList(i,list,";")
            DoWindow/HIDE=1 $currentGraph
        EndFor
    ElseIf(mode ==2)
        numItems = ItemsInList(list,";")
        For(i=0;i<numItems;i+=1)
            currentGraph = StringFromList(i,list,";")
            DoWindow/HIDE=0 $currentGraph
        EndFor
    EndIf
End

Forum

Support

Gallery

Igor Pro 9

Learn More

Igor XOP Toolkit

Learn More

Igor NIDAQ Tools MX

Learn More