Scripting Resources for DigitalMicrograph™ |
Save all as .dm3 with a common name and counter |
|
Function |
Saves all open images in Gatan .dm3 format, with a common name and counter. |
Version |
version:20131228, v1.0 |
Author |
D. R. G. Mitchell |
Acknowledgements |
- |
Comments |
This script is only compatible with GMS 2 - where it can be used to save files as .dm3 for use in GMS 1. |
System Requirements |
Only compatible with GMS 2, but can be converted to be compatible with both GMSes by editing one line of code - as indicated in the script. |
Known Issues |
- |
Supported |
Yes |
Included Files |
Main script file. |
Source Code |
// Script to save all the currently open images in .dm3 format into a folder of choice.
// Note this script uses the saveasgatan3() function (near the end of the script). // This function is only compatible with GMS 2. This script may be useful when acquiring data // in GMS 2, but where processing offline is to be done using GMS 1. // To convert this script to work in both GMS 1 and 2, simply change the saveasgatan3() function to
// version:20131228, v1.0, adminnospam@dmscripting.com (remove the nospam to make this work) // D. R. G. Mitchell, www.dmscripting.com, December 2013
// function to close all open images
void CloseAllOpenimages() { number nodocs=countdocumentwindowsoftype(5) if(nodocs==0) return
number i for(i = 0; i <nodocs; i++) { ImageDocument imgDoc = GetImageDocument( 0 ) imagedocumentClose(imgdoc,0) }
return }
// function which takes the passed in number (value) and pads it with zeroes out to the length specified in PadOutTo // returns the padded number as a string. eg value=27, PadOutTo=5 returns the string "00027"
string PadWithZeroes(number value, number PadOutTo) {
string startstring=""+value number stringlen=len(startstring)
while(stringlen<PadOutTo) { startstring="0"+startstring stringlen=len(startstring) }
return startstring }
// function to show all hidden images
void showallhiddenimages() { // variables
number nodocs,shown, hidden, imgdocid, counter number i imagedocument imgdoc
// count the number of image documents - this includes both shown and hidden ones // and delete any temporary tag information which may have been left over from last time.
shown=Countdocumentwindowsoftype(5) // images currently shown nodocs=countimagedocuments() // all image documents, including hidden ones hidden=nodocs-shown // the number of hidden images
deletepersistentnote("Show Hidden Temp")
// Image documents are indexed (0,1,2 . . . ) in the following manner // Front-most shown image (0) then the image shown behind that (1) etc. // Hidden images appear at the end of the stacking sequence. The last image in the sequence is the last // image to be hidden. In the Window menu, hidden images have a 'h' next to them. // Hidden images have indexes which run top to bottom in this menu. If there are only 3 image documents // open and all three are hidden, then the top one in the 'Window' menu will have an index of 0 // next down 1, and the last will have an index of 2. If there are four image documents open, one is shown // and three are hidden, the hidden image documents are indexed 1,2 and 3 ie
// Shown images // Front most - index = 0 // behind front - index = 1 // rear most - index = n = number of shown imagedocuments-1
// Hidden images // First to be hidden - index n+1 // Last to be hidden - index number of imagedocuments-1
// Get the IDs of the hidden image documents
for(i=shown; i<nodocs; i++) { imgdoc=getimagedocument(i) imgdocid=imgdoc.imagedocumentgetid() setpersistentnumbernote("Show Hidden Temp:Image "+counter,imgdocid) counter=counter+1 }
// loop to display all the hidden image documents in a stacked sequence.
number j
for(j=hidden-1; j>-1; j--) // loop through the number of hidden image documents { getpersistentnumbernote("Show Hidden Temp:Image "+j,imgdocid) imgdoc=getimagedocumentbyid(imgdocid) imagedocumentshow(imgdoc) }
// Remove the temporary tags
deletepersistentnote("Show Hidden Temp") }
// Main Program
// Count the number of open document windows
number nodocs=countdocumentwindowsoftype(5) if(nodocs==0) { showalert("Please ensure at least one image is displayed.",2) exit(0) }
// Source the front-most image and set up the save directory
image temp:=getfrontimage() string imgname=getname(temp) if(!getstring("Enter the common name for the images?", imgname, imgname)) exit(0)
number startingnumber=1 if(!getnumber("Enter starting file number:",startingnumber, startingnumber)) exit(0)
string currentpath, currentdirectory if(!SaveAsDialog("Save As",imgname,currentpath))exit(0) currentdirectory=pathextractdirectory(currentpath,2)
// Main processing loop to save the images whilst incrementing the counter part of the filename
number i string newname, startstring
for(i=0; i<nodocs; i++) { image front:=getfrontimage() startstring=PadWithZeroes(startingnumber, 3)
string thisname=imgname+"-"+startstring
string thispath=pathconcatenate(currentdirectory, thisname) saveasgatan3(front, thispath) hideimage(front) startingnumber=startingnumber+1 }
showallhiddenimages() showalert(""+nodocs+" images saved to: "+currentdirectory,2)
if(twobuttondialog("Close all open images?","No","Yes")) exit(0) else closeallopenimages() |