How can I batch export graphs using graph title
Mon, 11/21/2022 - 07:11 pm
I want to export multiple graphs into png and name them based on their title. I found an macro online but it generate error saying "expected right
parenthesis ". Can you correct this error for me? I really appreciate!
//Saves all graphs in experiment as PDF files in the
//same folder as the experiment or in subfolder called "graphs"
variable NGraphs, i
string graphList, alertStr, currWindow
GraphList = WinList("*", ";", "WIN:1")
graphList = RemoveFromList("SnglMove", graphList)
NGraphs = itemsInList(GraphList)
string homePathStr, graphPathStr
homePathStr = S_path
graphPathStr = homePathStr + "graphs"
newPath /O graphs, graphPathStr
print "will save graphs for all runs in " + graphPathStr
for (i = 0; i < NGraphs; i += 1)
currWindow = stringFromList(i, graphList)
doWindow /F $currWindow
//Save top window graph using its window's name
//Top window must be a graph. Graph you want to save must be top window
//Graph is saved as pdf file in folder called "graphs" in the home path (folder
//of the current igor experiment), which you can create in advance or in response to the dialog
//box that appears if "graphs" does not exist.
//Filename is created from igor experiment name and graph window's title
string windowTitleStr, titleFirstWord
//Obtain window's title's first word, to be used as part of the filename
//e.g., if autonamed graph1:y vs x, then extract "graph1"
getWindow kwTopWin, wtitle
//(I am getting title because I don't know how to get the window's name)
windowTitleStr = S_Value
titleFirstWord = stringFromList(0, windowTitleStr, ":")
string exptName, fName
exptName = igorInfo(1)
fName = titleFirstWord + "_" + exptName
print "windowTitleStr", windowTitleStr
print "titleFirstWord", titleFirstWord
print "fName", fName
alertStr = "Will try to save graph with title " + windowTitleStr
alertStr += " as a pdf file in same folder as present Igor"
alertStr += " experiment, \nusing name " + fName
doWindow /H /F
SavePICT/Z/O/P=graphs/E=-5/RES=300 as fName
//Here save to png with resolution 300 ppi
//SavePICT /Z/O/P=graphs/E=-2/W=(0,0,0,0) as fName
if (V_flag == 0)
alertStr = "Graph saved successfully."
alertStr = "***An error occurred. Graph not saved"