Save All Graphs As Graphics Files

//  SaveAllGraphsAsGraphicsFiles(pathName, extension, visibleOnly, format, bitmapRes)
//  NOTE: This overwrites existing files with the same name.
//  Example:
//      SaveAllGraphsAsGraphicsFiles("home", ".png", 1, -5, 288)
Function SaveAllGraphsAsGraphicsFiles(pathName, extension, visibleOnly, format, bitmapRes)
    String pathName         // Name of Igor symbolic path pointing to folder where graphics should be saved.
    String extension                // Extension for file name, e.g., ".tif", ".pdf", ".png" . . .
    Variable visibleOnly            // 1 to save only visible graphs, 0 to save visible and hidden graphs.
    Variable format             // For SavePICT /E flag. See SavePICT documentation.
    Variable bitmapRes          // For SavePICT /RES flag (e.g., 288 for 288 dpi).
   
    Variable index = 0
    do
        String graphName = WinName(index, 1, visibleOnly)
        if (strlen(graphName) == 0)
            break                   // All done
        endif
       
        String fileName = graphName + extension
        SavePICT /N=$graphName /O /P=$pathName /E=(format) /RES=(bitmapRes) as fileName
       
        index += 1
    while(1)
End


Works great. But is there a way that the save dialog box doesn't show up every time ?

You will get a dialog box if you have no home path but use "home" as the first parameter. The home path is not defined in an untitled experiment.

You need to provide a valid symbolic path name as the first parameter. Execute this for details:

DisplayHelpTopic "Symbolic Paths"

 

This is what I did. Made a NewPath inside the SaveAllGraphsAsGraphicsFiles function and stored the information in pathName. But If I have 8 graphs, the save dialogbox pops up 8 times and asks me to save, instead of saving everything in the folder all at once.

Function SaveAllGraphsAsGraphicsFiles()
    String pathName  // Name of Igor symbolic path pointing to folder where graphics should be saved.
    String extension = ".jpeg"  // Extension for file name, e.g., ".tif", ".pdf", ".png" . . .
    Variable visibleOnly = 1  // 1 to save only visible graphs, 0 to save visible and hidden graphs.
    Variable format = -6            // For SavePICT /E flag. See SavePICT documentation.
    Variable bitmapRes = 288         // For SavePICT /RES flag (e.g., 288 for 288 dpi).
   
    NewPath/O/M="Select the folder to Save all the Graphs" pathName
    PathInfo/S pathName
    Variable index = 0
    do
        String graphName = WinName(index, 1, visibleOnly)
        if (strlen(graphName) == 0)
            break                   // All done
        endif
       
        String fileName = graphName + extension
        SavePICT /N=$graphName /O /P=$pathName /E=(format) /RES=(bitmapRes) as fileName
        index += 1
    while(1)
End

 

I think you need to remove the "$" from the SavePict line.  PathName is not string variable but a path name.

use /P=pathname instead of /P=$pathname.

 

Andy

Forum

Support

Gallery

Igor Pro 9

Learn More

Igor XOP Toolkit

Learn More

Igor NIDAQ Tools MX

Learn More