如何在Digital Micrograph脚本中用一个对话框打开多个图像? [英] How could I open more than one image with a single dialog in Digital Micrograph script?

查看:213
本文介绍了如何在Digital Micrograph脚本中用一个对话框打开多个图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用DigialMicrograph脚本编写.我希望脚本在一个对话框(一个多选图像对话框)中打开多个图像,类似于当您转到任何Windows打开对话框时,选择多个图像并按确定".

I am writing in DigialMicrograph scripting. I want a script to open more than one image in a single dialog, a multi-select image dialog, similar to when you go to any Windows open dialog, select several images and press Ok.

我认为这是可能的,但是我还没有找到一种方法.我想在脚本中引入此特定代码,以避免在运行脚本之前打开图像.

I think that this is possible but I haven't found a way to do it. I want to introduce this specific code in my script, to avoid image-opening prior to running the script.

我知道函数OpenDialog,但这仅允许打开单个图像.有人可以给我看一些脚本或可以进一步帮助我的功能吗?

I know the function OpenDialog but this only allows opening of a single image. Could anybody show me some script or a function which can help me further?

谢谢.

推荐答案

您所要求的可能会涉及更多.脚本语言没有 multiple open 函数,因此您只能自己创建它,涉及多个步骤:

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:

  • 基本文件夹的输入(您可以通过GetDirectoryDialog对话框提示用户输入)
  • 使用命令GetFilesInDirectory检索该文件夹中文件的列表( TagList )
  • 处理该列表以过滤出您感兴趣的内容
  • 构建自定义对话框(源自 UIFrame ),该对话框列出了带有复选框,多个下拉菜单或一个列表框的文件.
  • 根据您在自定义对话框中所做的选择,即打开所有这些文件
  • 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()
}

这篇关于如何在Digital Micrograph脚本中用一个对话框打开多个图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆