You can execute script files (filename.py), containing a sequence of script commands, from the EcoStruxure Machine Expert user interface.
For further information on running scripts form the EcoStruxure Machine Expert user interface, refer to the chapter Script-Related Commands.
Frequently used commands
Command |
Description |
---|---|
- REM or :: |
The line is a comment and will be ignored. |
cd |
Changes to another directory. |
echo off |
The commands will not be displayed. In order to prevent single commands from being displayed, insert an @ character in front of the command. |
echo |
Displays a string or a variable on the programming console. |
set |
Declares a variable and assigns a value to this variable. |
> |
Writes the output to a file. If the file already exists, it will be overwritten. |
>> |
Appends the output to a file. If the file does not already exist, it will be created. |
Application example:
@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
Running the script in a C# application allows you to edit the script dynamically before the script is executed by the engine. In addition, some previous steps can be performed in the C# application as well
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();
}
}
}