Save All Graphs for IP9
Inspired by a code snippet for IP7 posted here, I've worked up a modified version. The snippet below has been tested under IP9. It will show as a menu option in the Macros menu. It takes various modifier keystrokes during the menu call to determine whether to include hidden graphs (default is only visible), store with title (default is with name), or store as PDF (default is PNG).
I commented out many of the print error messaging lines in the main code simply to keep a cleaner operation. I will use this code snippet as part of my "always loaded" functions.
DISCLAIMER: I used Claude AI for recommendations to clean up some of the coding.
Menu "Macros", dynamic
SaveGraphMenuString(), /Q, Do_SaveAllGraphs()
end
Function/S SaveGraphMenuString()
string rStr
variable nvgraphs, nhgraphs
nvgraphs = ItemsInList(WinList("*",";","WIN:1;VISIBLE=1"))
if (nvgraphs == 0)
rStr = "\\M1(Save All Graphs"
else
nhgraphs = ItemsInList(WinList("*",";","WIN:1")) - nvgraphs
sprintf rStr,"Save All Graphs (%d |%2.0f)", nvgraphs, nhgraphs
endif
return rStr
end
Function Do_SaveAllGraphs()
variable keystate = GetKeyState(0)
variable ngraphs
string rStr
// 16 - control
// 4 - shift
// 2 - option
// 1 - command
switch(keystate)
case 1: // command key - include hidden
ngraphs = SaveAllGraphs(H=1)
break
case 2: // option key - use title
ngraphs = SaveAllGraphs(T=1)
break
case 4: // shift key - PDF
ngraphs = SaveAllGraphs(F=1)
break
default: // no key
ngraphs = SaveAllGraphs()
break
endswitch
PathInfo graphs
sprintf rStr, "%s - %s: saved %d graph(s) to %s", date(), time(), nGraphs, s_path
print rStr
return 0
end
// M is match string (default "*")
// P is Igor path name as string (default "home")
// T = 0 use name (default), T = 1 use title
// H = 0 do not include hidden (default), H = 1 include hidden
// F = 0 store as PNG (default), F = 1 store as PDF
function SaveAllGraphs([string M, string P, variable T, variable H, variable F])
variable ic, nGraphs, sv
string graphList, currWindow, fname
// set defaults
M = SelectString(ParamIsDefault(M), M, "*")
T = ParamIsDefault(T) ? 0 : T
H = ParamIsDefault(H) ? 0 : H
F = ParamIsDefault(F) ? 0 : F
// get graph list based on hidden flag
graphList = WinList(M, ";", "WIN:1" + SelectString(H, ";VISIBLE:1", ""))
nGraphs = ItemsInList(graphList)
if (nGraphs == 0)
print "No graphs found matching criteria."
return 0
endif
// define the path
if (ParamIsDefault(P))
PathInfo home
if (V_flag == 0) // Check if path exists
// print "Warning: 'home' path not found. Using current directory."
GetFileFolderInfo/Q/Z ""
endif
else
PathInfo $P
if (V_flag == 0) // Path doesn't exist
// print "Warning: Path '" + P + "' not found. Using 'home' instead."
PathInfo home
if (V_flag == 0) // Check if path exists
// print "Warning: 'home' path not found. Using current directory."
GetFileFolderInfo/Q/Z ""
endif
endif
endif
NewPath/C/O/Q graphs, S_path + "graphs:"
// set save format and resolution
if (F == 0) // PNG
sv = -5 // 150 DPI
else // PDF
sv = (cmpstr(IgorInfo(2), "Windows") == 0) ? -8 : -2
endif
string fileExt = SelectString(F, ".png", ".pdf")
// save all graphs
for (ic = 0; ic < nGraphs; ic += 1)
currWindow = StringFromList(ic, graphList)
// Get filename from window name or title
if (T == 0)
fname = CleanUpName(currWindow, 1)
else
GetWindow $currWindow, wtitle
fname = CleanUpName(S_value, 1)
endif
// save the graph
SavePICT/O/E=(sv)/P=graphs/WIN=$currWindow as fname + fileExt
endfor
return nGraphs
end
Forum
Support
Gallery
Igor Pro 10
Learn More
Igor XOP Toolkit
Learn More
Igor NIDAQ Tools MX
Learn More