Delete all graphs that are NOT part of layouts

Supriya Balaji
Posts: 44
Joined: 2013-05-21
Location: United States

Is there a way to Delete all graphs that are NOT part of layouts

Posts: 327
Joined: 2009-03-21
Location: United States

Hi Supriya,

One strategy:
Use Winlist to get a master list off all open windows.
Use Winlist to get a list of all Layouts and remove those window names from the master list.
Use Layoutinfo for each layout to get a list of objects used in each layout and remove those windows from the master list.
What is left is a list of windows not included in any open layout which can be killed/closed.


Posts: 1675
Joined: 2007-06-21
Location: United States

Here is a solution that I have tested only very briefly:

Function IsGraphInLayout(graphName)
	String graphName
	String layoutList = WinList("*", ";", "WIN:4")
	Variable numLayouts = ItemsInList(layoutList)
	Variable layoutIndex
	for(layoutIndex=0; layoutIndex<numLayouts; layoutIndex+=1)
		String layoutName = StringFromList(layoutIndex, layoutList)
		Variable objectIndex = 0
			String objectIndexStr
			sprintf objectIndexStr, "%d", objectIndex
			String info = LayoutInfo(layoutName, objectIndexStr)
			if (strlen(info) == 0)
				break						// No more objects in this layout
			String typeStr = StringByKey("TYPE", info)
			if (CmpStr(typeStr,"Graph") == 0)
				String nameStr = StringByKey("NAME", info)
				if (CmpStr(nameStr, graphName) == 0)
					return 1				// The graph is in this layout
			objectIndex += 1
	return 0		// The graph is not in this layout
Function KillGraphsNotInLayout()
	String graphList = WinList("*", ";", "WIN:1")
	Variable numGraphs = ItemsInList(graphList)
	Variable graphIndex
	for(graphIndex=0; graphIndex<numGraphs; graphIndex+=1)
		String graphName = StringFromList(graphIndex, graphList)
		if (IsGraphInLayout(graphName) == 0)
			KillWindow $graphName
			Printf "Killed %s\r", graphName

Back to top