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


hegedus
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.

Andy


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
		do
			String objectIndexStr
			sprintf objectIndexStr, "%d", objectIndex
			String info = LayoutInfo(layoutName, objectIndexStr)
			if (strlen(info) == 0)
				break						// No more objects in this layout
			endif
			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
				endif
			endif			
			objectIndex += 1
		while(1)
	endfor
 
	return 0		// The graph is not in this layout
End
 
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
		endif
	endfor
End


Back to top