Search code examples
automationsavedm-script

How to save images automatically after setting up a path?


I want to save my images automatically, but I don't know how to set it in DM. My script is as follows:

Image img
img.GetFrontImage()
string name
if ( GetString( "Enter Name of Sample", "Hello!", name ))
    result( "\nThe Name Of Sample is "+name)
string path
if ( GetDirectoryDialog("select path","",path) )
    result("\nSelected path is:"+path)

While( img.ImageIsValid() )
{
    For( number i=i; i<1000000;i++ )
    {
        img.SetName(name+i)
        img.SaveImage(name+i)
        img := FindNextImage(img)
    }
}

Solution

  • It seems the main thing you are missing is a line that creates a full pathname from the combination of the destination directory path and the name for each image. So in addition to the changes suggested in the answer by BmyGuest, you should add a call to PathConcatenate, as follows:

    number i = 1
    While( img.ImageIsValid() )
    {
        img.SetName(name+i)
        string filepath = path.PathConcatenate(name+i)
        img.SaveAsGatan(filepath)
        img := FindNextImage(img)
        i++
    }