I'm working with Digital Micrograph (DM) and have an MRC file that contains 10 distinct pieces. When loaded in DM, I can navigate through these pieces using the left and right arrow keys. I'm looking to automate this process with DM script by:
I've searched for documentation or examples on handling multi-piece MRC files in DM script but haven't found a clear solution yet. Has anyone successfully implemented this? If so, could you provide guidance or sample code to achieve this functionality? Any tips or pointers on potential pitfalls would be greatly appreciated.
Glad you've solved it yourself by now. In order to have some answer here on StackOverflow as well, this is how I would do it. (Tested with your example file)
string path = "C:\\temp\\test.mrc"
if ( !OpenDialog( NULL , "Load MRC stack from" , path , path ) ) exit(0)
image stack := NewImageDocumentFromFile(path).ImageDocumentGetRootImage()
if ( !stack.ImageIsValid() )
Throw("Could not read file:\n"+path)
//stack.ShowImage()
if ( 3 != stack.ImageGetNumDimensions() )
Throw("File is not a 3D stack.")
number sx,sy,sz
stack.ImageGetDimensionSizes(sx,sy,sz)
string folder = PathExtractDirectory(path,0)
string baseName = PathExtractBasename(path,0)
// Split and save
for(number i=0;i<sz;i++){
image img := stack.slice2(0,0,i, 0,sx,1, 1,sy,1).ImageClone()
string filePath = folder+basename+"_"+i
OpenAndSetProgressWindow("Saving file "+(i+1)+" / "+sz,filepath,"")
img.ImageGetOrCreateImageDocument().ImageDocumentSaveToFile( "Gatan Format", filePath)
Result("\n saved: "+filePath)
}
CloseProgressWindow()