如何在 DM 脚本的 Gatan Digital Micrograph (GMS) 中从自动保存中排除某些图像

问题描述

我正在尝试模仿 GMS v3 中的自动保存功能,以便我可以在版本 1 和 2 中使用。我想首先承认脚本的主要部分来自 Bernhard Schaffer 博士的“如何编写脚本...数码显微照片脚本手册”。我对其进行了一些修改,以便相机记录的任何新图像都可以自动保存到文件中。但是,我遇到了一些问题,因为如果我决定单击实时取景图像并四处移动图像,或者使用实时fft,实时取景图像或 FFT 图像也将被保存。我的想法之一是使用标签组信息,例如“采集:参数:参数集名称”,因为对于实时视图或实时 FFT,这将处于搜索或聚焦模式。另一个想法是使用文档 ID,例如 iDocID = idoc.ImageDocumentGETID() 来定位实时图像的 ID。但是,我不知道如何使用此信息将它们从自动保存中排除。谁能指出我如何继续这个脚本? 下面是脚本

Class PeriodicAutoSave : Object
    {
    
    Number output
    PeriodicAutoSave(Object self) Result("\n Object ID"+self.ScriptObjectGetID()+" created.")
    ~PeriodicAutoSave(Object self) Result("\n Object ID"+self.ScriptObjectGetID()+" destroyed")
    
    Void Init2(Object self,Number op) 
    output=op

    
    Void AutoSave_SaveAll(Object self)
        {
        String path,name,targettype,targettype1,area,mag,mode,search,result1
        ImageDocument idoc
        Number nr_idoc,count,index_i,index,iDocID,iDocID_search
        path = "c:\\path\\"
        name = "test"
        targettype=="Gatan Format (*.dm4)"
        targettype1 = "dm4"
        If (output) Result("\n AutoSave...")
        nr_idoc = CountimageDocuments()
        For (count = 1; count<nr_idoc; count++)
            {
            idoc = GetimageDocument(count) //imagedocument
            index = 1 // user decide the index to start with
            index_i= nr_idoc - index
            If (idoc.ImageDocumentIsDirty())
                {
                idoc = getfrontimagedocument()  
                iDocID = idoc.ImageDocumentGetID()
                TagGroup tg = ImageGetTagGroup(idoc.ImageDocumentGetimage(0)) // cannot declare an 'img' for this line as it will prompt an error?
                tg.TagGroupGetTagAsstring("Microscope Info:Formatted Indicated Mag",mag)
            
                        
                
            
                
                    Try{
                        
                    
                            {
                            idoc.ImageDocumentSavetoFile( "Gatan Format",path+index_i+"-"+name+"-"+mag+".dm4")
                            idoc.ImageDocumentSetName(index_i + "-"+name+"-"+mag+".dm4")
                            idoc.ImageDocumentClean()
                            
                            }
                        If (Output) Result("\n\t saving: "+idoc.ImageDocumentGetCurrentFile())
                        }
                    Catch{
                        Result("\n image cannot be saved at the moment:" + GetExceptionString())
                        Break
                        }
                    Result("\ Continue autosave...")
                }
            }
        }
    }
    



Void LaunchAutoSave()
    {
    Object obj = Alloc(PeriodicAutoSave)
    obj.Init2(2)
    Number task_id = obj.AddMainThreadPeriodicTask("AutoSave_SaveALL",6)
                                            
    //Sleep(10)
    while(!shiftdown()) 1==2
    RemoveMainThreadTask(task_id)
    }

LaunchAutoSave()

解决方法

您的过滤想法很好,但您的 for 循环有些奇怪。

 nr_idoc = CountImageDocuments()
        For (count = 1; count<nr_idoc; count++)
            {
            idoc = GetImageDocument(count) //imagedocument

您遍历所有当前打开的图像文档(第一个除外!?)并逐个获取它们,然后在

 If (idoc.ImageDocumentIsDirty())
                {
                idoc = getfrontimagedocument()     

您实际上每次都获得最前面的(选定的)文档。你为什么要这样做?

为什么不去:

number nr_idoc = CountImageDocuments()
for (number count = 0; count<nr_idoc; count++)
{
    imagedocument idoc = GetImageDocument(count)
    If (idoc.ImageDocumentIsDirty())
    {
        // now find out what is a filter condition and skip if it is true
        number skip = 0
        
        TagGroup tg = idoc.ImageDocumentGetImage(0).ImageGetTagGroup()
        skip = tg.TagGroupDoesTagExist("Microscope Info:Formatted Indicated Mag")
        if (skip) continue
        
        // do saving
    }
}
,

非常感谢您的指点!我已经尝试过,它与我的脚本配合得很好。由于“TagGroupDoesTagExist”仅指标签组,我进一步修改以包含我想要过滤的标签,例如“搜索”或“焦点”,它似乎运行良好。我修改为您现有的脚本如下:

If (idoc.ImageDocumentIsDirty())
                    {
                        
                        //now find out what is a filter condition and skip if it is true
                        skip = 0
                        TagGroup tg = idoc.ImageDocumentGetImage(0).ImageGetTagGroup()
                        tg.TagGroupGetTagAsString("Microscope Info:Formatted Indicated Mag",mag)
                        tg.TagGroupGetTagAsString("Acquisition:Parameters:Parameter Set Name",mode)
                        skip = tg.TagGroupDoesTagExist("Acquisition:Parameters:Parameter Set Name")
                
                        if(skip && (mode == "Search" || mode== "Focus")) continue