1. There is usually some sort of directory tree structure, with the main project folder having several sub-folders for conditions, and those have several sub-folders for samples, with the image files below those.
2. There are frequently enough subfolders and images that even the Batch processing is annoyingly time consuming, and all too often the manipulations the user wants to do are not available as one of the Batch functions.
3. The images frequently have the exact same file names, with the parent folder distinguishing one condition from another.
So while I have done a bit of scripting in Groovy and a few other languages, I am coming at this fairly cold, though the large selection of macros available from both the rep and on this forum have been very useful in getting started.
The first macro (that I modified) was altering the display settings of all files in a project based on a display settings file that could be located anywhere (due to collaborations and network folders) based on a sample macro called "ZEN2 - Apply display setting for multiple images.czmac":
Code: Select all
#######################################################
##Alter the display settings of all CZI files in various subfolders of one top level project folder
##First dialog is looking for the directory with your display setting files
##Second dialog allows you to choose your display setting, and the top of
##folder of the file tree.
from System.IO import File, Directory, FileInfo, Path, SearchOption
Zen.Application.Documents.RemoveAll()
##Collect folder location for display setting files
defaultFolder = "C:\\"
window = ZenWindow()
window.AddFolderBrowser('dispfolder','Select the folder containing your display settings files',defaultFolder)
result=window.Show()
## check, if Cancel button was clicked
if result.HasCanceled == True:
sys.exit('Macro aborted with Cancel!')
## get string name of source folder/destination folder
dspPath = str(result.GetValue('dispfolder'))
fileNames = []
itype = '*.czdsp'
files = Directory.GetFiles(dspPath,itype)
for i in range(0,files.Length):
file = files[i]
fileInfo = FileInfo(file)
OrgFileNameWE = fileInfo.Name.Substring(0,fileInfo.Name.Length-6)
fileNames.append(OrgFileNameWE)
##Collect exact display setting file and location of project folder with images
window2 = ZenWindow()
window2.AddFolderBrowser('parentFolder','Parent folder','C:\OAD\Input')
window2.AddDropDown('dval','Display setting ', fileNames, 0)
result=window2.Show()
## check, if Cancel button was clicked
if result.HasCanceled == True:
sys.exit('Macro aborted with Cancel!')
path = str(result.GetValue('parentFolder'))
dsp = str(result.GetValue('dval'))
dispset = ZenDisplaySetting()
dispset.Load(dsp,ZenSettingDirectory.Workgroup)
itype = "*.czi"
## get files
dirs = Directory.EnumerateDirectories(path)
files = Directory.GetFiles(path,itype, SearchOption.AllDirectories)
##Main script
for file in files:
PathAndFile = Path.GetFullPath(file)
## load image without display the image in center screen area
image = Zen.Application.LoadImage(PathAndFile,False)
image.SetDisplaySetting(dispset,True)
image.Save(PathAndFile)
image.Close
##
#######################################################
My second macro attempt was less successful, as aside from streamlining the process of making all of the images have comparable display settings, the other process of interest is exporting TIFFs for viewing outside of Zen. While I was able to create a macro similar to the above, I have yet to find a way to create the exported TIFF files in the same folder as the original CZI file while traversing the directory tree. Mostly this seems due to the fact that the expset contains the target folder as a text field, and I do not know of a way to ignore the target folder and simply place the TIFF file into the same folder as the original image.
Exporting all images to the same folder will not work due to the duplicate names.
Am I overlooking some easy way to export many TIFFs to their original folders? Can I macro Batch? Should I try to move the file within the for loop back to the location of the original image? Or might it be easier to try and edit the XML file as described in the 3rd post here: http://forums.zeiss.com/microscopy/comm ... SingleFile
I am basing the macro on the macro provided in that thread, except going through multiple folders worth of files.
Any advice on how to proceed would be appreciated.
Cheers