Killing Graphs From Command Line

I have searched the Web, the Help files, and everywhere in between. I cannot find a way to kill graphs from the command line. It's easy to kill waves, but what about graphs, or even tables? Is there a way to kill these objects from the command line?
patarroyo wrote:
I have searched the Web, the Help files, and everywhere in between. I cannot find a way to kill graphs from the command line. It's easy to kill waves, but what about graphs, or even tables? Is there a way to kill these objects from the command line?


Look under DoWindow/K or KillWindow.

--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAH
Dr. Weimer, thanks a lot, you are always a huge help. Sorry I couldn't figure this out on my own, but the manual is just so thick...

Here is the preliminary solution I came up with. Basically, this macro relies on the default graph name being "Graph#". It will give an error if "endnum" exceeds the actual number of graphs, or if there is a non-sequential ordering of the graphs (e.g. graphs 1-3 exist, and 5-7, but not graph4. The function will fail on graph4). I am all ears if someone would like to point out some good ways to avoid error codes, but for now, this helps me quite a bit. I often times generate 10-20 graphs just to look at them once, and then kill them, no need to bring them up later.
#pragma rtGlobals=1

Function KillGraphs(startnum, endnum)
    Variable startnum, endnum
    Variable i
    String WindowName
   
    for(i=startnum; i<=(endnum); i+=1)
        WindowName="Graph"+num2str(i)
        KillWindow $WindowName
    endfor
   
End


-Mike
patarroyo wrote:
... point out ways to avoid error codes ...


Try the following:

Function KillGraphs(startnum, endnum)
    Variable startnum, endnum

    Variable i
        String WindowName
   
    for(i=startnum; i<=(endnum); i+=1)
        WindowName="Graph"+num2str(i)
                if (WinType($WindowName) == 1)
               KillWindow $WindowName
                endif
    endfor
   
End


--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAH
Jeff's code has a typo in it. What you really want is this:
Function KillGraphs(startnum, endnum)
    Variable startnum, endnum
 
    Variable i
        String WindowName
 
    for(i=startnum; i<=(endnum); i+=1)
        WindowName="Graph"+num2str(i)
                if (WinType(WindowName) == 1)
               KillWindow $WindowName
                endif
    endfor
 
End


I removed the $ before WindowName in the call to WinType().
Here's yet another possibility. It kills all graphs and windows.

function kill_graphs_and_tables()
    string object_name
    variable string_length
    do
        object_name = WinName(0,3)          // name of top graph or table  (see III-441)
        string_length = strlen(object_name)         // returns "" if no graph/table is present 
        if (string_length == 0)
            break
        endif
        DoWindow /K $object_name            // kill top graph or table; keep going till all done
    while (1)                                                            // loop forever until break       
end



John Bechhoefer
Department of Physics
Simon Fraser University
Burnaby, BC, Canada
patarroyo wrote:
I have searched the Web, the Help files, and everywhere in between. I cannot find a way to kill graphs from the command line. It's easy to kill waves, but what about graphs, or even tables? Is there a way to kill these objects from the command line?


Or this, to kill any of graphs, tables, layouts, notebooks, panels, XOP windows:

//---------------------------------------------------------------------------------------
// KillOrHideAnyWindow
// -------------------
//   'KillOrHideAnyWindow' kills any graph, table, layout, notebook, panel, or XOP window
//  
//   PARAMETERS:
//        - winMask:      bitmask of window types to kill
//                          - 0x0  kill everything possible
//                          - 0x01 graphs
//                          - 0x02 tables
//                          - 0x04 layouts
//                          - 0x10 notebooks
//                          - 0x40 panels
//                          - 0x1000 XOP target windows
//---------------------------------------------------------------------------------------
FUNCTION KillOrHideAnyWindow(winMask)
    variable                      winMask;
   
    variable                      i,n;
    variable                      all=0x1000+0x40+0x10+0x4+0x2+0x1;
    string                        theWins;
   
    winMask = !winMask ? all : winMask;

    theWins = winList("*",";","WIN:"+num2iStr(winMask & all));
    for(i=0,n=itemsInList(theWins,";") ; i<n ; i+=1)
        doWindow/K $stringFromList(i,theWins,";");
    endfor;
END


Regards,
Patrick.
Q: Kill most RECENTLY opened window?

Is there a simple way to kill the most recently opened window without knowing it's name?

Thanks
Quote:
Is there a simple way to kill the most recently opened window without knowing it's name?


No, but you can kill the top graph:

Function KillTopVisibleGraph()
    String topGraph = WinName(0, 1, 1)
    if (strlen(topGraph) == 0)
        return 0
    endif
   
    DoWindow /K $topGraph
    return 1
End


If you really want to kill the most-recently-created graph, you would have to keep track of the time of creation. This could be stored as user data in the graph but it is much more complicated than killing the top graph.