执行脚本

概述

您可以从 EcoStruxure Machine Expert 用户界面来执行包含一系列脚本命令的脚本文件 (filename.py)。

有关从 EcoStruxure Machine Expert 用户界面运行脚本命令的详细信息,请参见脚本相关命令一章。

批处理文件

常用命令

命令

描述

-    REM ::

此行是注释,将被忽略。

cd

切换到另一个目录。

echo off

不显示命令。

为防止显示单个命令,请在该命令的前面插入一个 @ 字符。

echo

在编程控制台上显示字符串串或变量。

set

声明变量并向此变量赋值。

>

将输出写入文件。如果文件已存在,则该文件将被覆盖。

>>

将输出附加到文件。如果文件不存在,则将创建该文件。

应用示例:

@echo off
REM Go to the directory where EcoStruxure Machine Expert is installed
cd "<Replace this with the path to the LogicBuilder.exe, for example, C:\Program Files (x86)\Schneider Electric\SoMachine Software\>"
REM Run LogicBuilder.exe with no graphical user interface and the full path to the script
LogicBuilder.exe --noui --runscript="<Replace this with the full file path where the script is stored, for example, D:\MyScripts\TestScript.py>"
pause

C# 控制台应用程序

通过在 C# 应用程序中运行脚本,可在引擎执行脚本前动态编辑该脚本。另外,也可以在 C# 应用程序中执行某些之前的步。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
namespace ExecuteScriptExample
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                ProcessStartInfo psi = new ProcessStartInfo();
                
                // Specify the name and the arguments you want to pass
                psi.FileName = @"<Replace this with the path to the LogicBuilderShell.exe, for example, C:\Program Files (x86)\Schneider Electric\SoMachine Software\LogicBuilderShell.exe";
                psi.Arguments = "\ "<Replace this with the full file path where the script is stored, for example, D:\MyScripts\TestScript.py\"";
                // Create new process and set the starting information
                Process p = new Process();
                p.StartInfo = psi;
                // Set this so that you can tell when the process has completed
                p.EnableRaisingEvents = true;
                p.Start();
                // Wait until the process has completed
                while (!p.HasExited)
                {
                    System.Threading.Thread.Sleep(1000);
                }
            }
            catch (Exception ex)
            {
                Console.Write(ex.Message);
            }
            Console.ReadKey();
        }
    }
}