How can I batch export graphs using graph title
Glory
Hi!
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!
//Gmv1 Save all graphs as png
//Saves all graphs in experiment as PDF files in the
//same folder as the experiment or in subfolder called "graphs"
Function SaveAllGraphs()
variable NGraphs, i
string graphList, alertStr, currWindow
GraphList = WinList("*", ";", "WIN:1")
graphList = RemoveFromList("SnglMove", graphList)
NGraphs = itemsInList(GraphList)
string homePathStr, graphPathStr
pathInfo home
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
saveGraph()
endFor
End //SaveAllGraphs
//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
Function saveGraph()
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
string alertStr
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
print alertStr
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."
else
alertStr = "***An error occurred. Graph not saved"
endIf
print alertStr
End //saveGraph()
//Saves all graphs in experiment as PDF files in the
//same folder as the experiment or in subfolder called "graphs"
Function SaveAllGraphs()
variable NGraphs, i
string graphList, alertStr, currWindow
GraphList = WinList("*", ";", "WIN:1")
graphList = RemoveFromList("SnglMove", graphList)
NGraphs = itemsInList(GraphList)
string homePathStr, graphPathStr
pathInfo home
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
saveGraph()
endFor
End //SaveAllGraphs
//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
Function saveGraph()
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
string alertStr
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
print alertStr
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."
else
alertStr = "***An error occurred. Graph not saved"
endIf
print alertStr
End //saveGraph()
int NGraphs, i
string graphList, currWindow
GraphList = WinList("*", ";", "WIN:1")
NGraphs = ItemsInList(GraphList)
PathInfo home
NewPath/C/O/Q graphs, S_path + "graphs:"
for (i = 0; i < NGraphs; i += 1)
currWindow = StringFromList(i, graphList)
GetWindow $currWindow, wtitle
SavePICT/Z/O/E=-5/P=graphs/WIN=$currWindow as CleanUpName(s_value, 1) + ".png"
endfor
end
note that files will be overwritten using the /O flag
November 22, 2022 at 06:04 am - Permalink