How could I open more than one image with a single dialog in Digital Micrograph script?

狂风中的少年 提交于 2019-12-02 03:57:36

What you are asking for might be a bit more involved. There is no multiple open function in the scripting language, so you can only create it yourself, involving multiple steps:

  • An input for a base-folder (This you could prompt the user for with a GetDirectoryDialog dialog)
  • Using the command GetFilesInDirectory to retrieve a list (TagList) of files in that folder
  • Process that list to filter out what you are interested in
  • Build a custom-dialog (derived from UIFrame) which lists the files with either checkboxes, multiple drop-down menus, or a list-box to select from.
  • Act on the selection made in your custom dialog, i.e. open all those files

The following script is an example doing that.

class MyMultiSelect : UIframe
{
    string root
    TagGroup FileList
    TagGroup DLGlist

    TagGroup CreateDLG( object self )
    {
        TagGroup dlg,dlgitems
        dlg = DLGCreateDialog( "MultiOpen", dlgItems )

        number nMax = fileList.TagGroupCountTags();
        TagGroup listitems
        DLGlist = DLGCreateList( listitems, 90, nMax+1 )
        DLGlist.DLGMultipleSelect(1)
        for (number i=0; i<nMax; i++)
        {
            string name
            if ( FileList.TagGroupGetIndexedTagAsString(i,name) )
                    listitems.DLGAddListItem( name, 0 )
        }

        dlgitems.DLGAddElement(DLGlist)
        return dlg
    }

    TagGroup CreateFilteredFileList( object self )
    {
        // Get all files
        TagGroup list = GetFilesInDirectory( root, 1 )
        // Filter all DM3 files
        TagGroup filtered = NewTagList() 
        for( number i = 0; i<list.TagGroupCountTags(); i++)
        {
            TagGroup entry
            string file = ""
            list.TagGroupGetIndexedTagAsTagGroup(i,entry)
            entry.TagGroupGetTagAsString( "Name", file )
            if ( -1 != find(file,".dm3") )
                filtered.TagGroupInsertTagAsString(Infinity(),file)
        }
        return filtered
    }

    TagGroup GetSelectedList( object self )
    {
        TagGroup selList = NewTagList()
        TagGroup itemList
        DLGlist.TagGroupGetTagAsTagGroup( "Items", itemList )
        for ( number i=0; i<itemList.TagGroupCountTags(); i++ )
        {
            number isSelected = 0
            TagGroup entry
            itemList.TagGroupGetIndexedTagAsTagGroup(i,entry)
            entry.TagGroupGetTagAsBoolean( "Selected", isSelected )
            if ( isSelected )
            {
                string filename
                entry.TagGroupGetTagAsString( "Label", fileName )
                selList.TagGroupInsertTagAsString( Infinity(),fileName)
            }
        }
        return selList
    }

    void OpenSelectedFiles( object self )
    {
        TagGroup files = self.GetSelectedList()
        number nFiles = files.TagGroupCountTags()
        if ( 0 == nFiles )
            Throw( "No files selected" )

        Result( "\n Opening "+nFiles+" files now..")
        for ( number i=0; i<nFiles; i++ )
        {
            string filename
            files.TagGroupGetIndexedTagAsString(i,fileName)
            string path = root + "\\" + filename
            Result( "\n Opening: "+path)
            OpenImage(path).ShowImage()
        }
    }

    Object Init( object self, string rootInput )
    {
        root = rootInput
        FileList = self.CreateFilteredFileList( )
        return self.super.Init( self.CreateDLG() )
    }
}

// Main
{
    string rootDir
    GetDirectoryDialog( NULL, "Select Folder from which to multi-open", GetApplicationDirectory("current",0), rootDir )
    object dlg = Alloc(MyMultiSelect).Init(rootDir)
    dlg.pose()
    dlg.OpenSelectedFiles()
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!