如何使用DigitalMicrograph脚本同步外部应用程序? [英] How can one synchronize an external application with a DigitalMicrograph script?

查看:422
本文介绍了如何使用DigitalMicrograph脚本同步外部应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


这个问题的启发来自于Call script from命令行'



如何在应用程序中编写一个作用于触发事件的脚本?其他比DigitalMicrograph?



ie某些脚本功能应由外部应用程序触发。

How can one write a script which acts on 'trigger events' in an application other than DigitalMicrograph?

i.e. some script functionality should be triggered by an external application.

推荐答案

脚本语言在当前没有提供许多外部接口州。可以使用命令 LaunchExternalProcess 将外部进程调用,然后等待进程完成,但没有直接的方式外部程序调用,即在DigitalMicrograph中启动脚本操作。

The scripting language does not offer many 'external' interfaces in its current state. It is possible to call out to an external process with the command LaunchExternalProcess and wait for the process to complete, but there is no straight-forward way for an external process to call in, i.e. to start a script-action within DigitalMicrograph.

但是,可以解决这个问题通过使用系统的文件系统作为消息队列。要执行此操作,请在后台运行脚本,定期检查某个文件是否存在,并且当需要在DigitalMicrograph中触发脚本操作时,使外部应用程序创建此类文件。文件内容(如果它是一个简单的文本文件)也可以用于在两个应用程序之间传输信息。

However, it is possible to work around that issue by using the system's file-system as a message queue. To do this, have a script running in the background which regularly checks if a certain file exists, and have the external application create such a file when it wants to trigger a scripting-action in DigitalMicrograph. The file content - if it is a simple text file - can also be used to transport information between the two applications.

这是一个示例脚本,将等到文件 Trigger.txt 出现在根文件夹中。支票每隔10秒执行一次。

Here is an example script which will wait until the file Trigger.txt appears in the root folder. The check is performed every 10seconds.

class WaitForExternal
{
    string triggerFilePath
    number taskID
    void WaitOnTrigger( object self )
    {
        if ( DoesFileExist( triggerFilePath ) )
        {
            Result( GetTime(1) + ": Triggered! Now act..." )
            If ( TwoButtonDialog( "Do you want to reset the trigger?", "Reset", "Stop" ) )
            {
                DeleteFile( triggerFilePath )
            }
            else
            {
                RemoveMainThreadTask( taskID )
            }
        }
        else
        {
            Result( GetTime(1) + ": not yet\n" )
        }
    }

    object Init( object self, string triggerPath, number waitSec ) 
    { 
        triggerFilePath = triggerPath
        taskID = self.AddMainThreadPeriodicTask( "WaitOnTrigger", waitSec )
        return self
    }
}

// Main script
{
    string triggerPath = "C:\\Trigger.txt"
    number pollingWait = 10
    Alloc(WaitForExternal).Init( triggerPath, pollingWait )
}

请注意,周期性任务在后台等待空闲而不干扰CPU,但是主线程上执行实际检查。

Note that the periodic task waits idle in the background without interfering with the CPU, but the actual check is then performed on the main thread.

这篇关于如何使用DigitalMicrograph脚本同步外部应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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