15 Beispiele


01 Compress
using System.Windows.Forms;
using Eplan.EplApi.ApplicationFramework;
using Eplan.EplApi.Scripting;

public class _15_Beispiele_01_Compress
{
  [Start]
  public void Function()
  {
    CommandLineInterpreter cli = new CommandLineInterpreter();
    ActionCallingContext acc = new ActionCallingContext();

    acc.AddParameter("CONFIGSCHEME", 
      "Überflüssige Projektdaten entfernen");

    cli.Execute("compress", acc);

    MessageBox.Show("Action ausgeführt.");
  }
}


02 ChangeLayer
using System.Windows.Forms;
using Eplan.EplApi.ApplicationFramework;
using Eplan.EplApi.Scripting;

public class _15_Beispiele_02_ChangeLayer
{
  [Start]
  public void Function()
  {
    CommandLineInterpreter cli = new CommandLineInterpreter();
    ActionCallingContext acc = new ActionCallingContext();

    acc.AddParameter("LAYER", "EPLAN400");
    acc.AddParameter("TEXTHEIGHT", "10");

    cli.Execute("changeLayer", acc);

    MessageBox.Show("Action ausgeführt.");
  }
}


03 Edit
using Eplan.EplApi.ApplicationFramework;
using Eplan.EplApi.Scripting;

public class _15_Beispiele_03_Edit
{
  [Start]
  public void Function()
  {
    CommandLineInterpreter cli = new CommandLineInterpreter();
    ActionCallingContext acc = new ActionCallingContext();

    acc.AddParameter("DEVICENAME", "=GAA+A1-FCC1");

    cli.Execute("edit", acc);
  }
}


04 ExecuteScript
using Eplan.EplApi.ApplicationFramework;
using Eplan.EplApi.Scripting;

public class _15_Beispiele_04_ExecuteScript
{
  [Start]
  public void Function()
  {
    CommandLineInterpreter cli = new CommandLineInterpreter();
    ActionCallingContext acc = new ActionCallingContext();

    acc.AddParameter("ScriptFile", @"C:\Test\01_Start.cs");

    cli.Execute("ExecuteScript", acc);
  }
}


05 Print
using System.Windows.Forms;
using Eplan.EplApi.ApplicationFramework;
using Eplan.EplApi.Scripting;

public class _15_Beispiele_05_Print
{
  [Start]
  public void Function()
  {
    CommandLineInterpreter cli = new CommandLineInterpreter();
    ActionCallingContext acc = new ActionCallingContext();

    acc.AddParameter("TYPE", "PROJECT");

    cli.Execute("print", acc);

    MessageBox.Show("Action ausgeführt.");
  }
}


06 ProjectAction
using System.Windows.Forms;
using Eplan.EplApi.ApplicationFramework;
using Eplan.EplApi.Scripting;

public class _15_Beispiele_06_ProjectAction
{
  [Start]
  public void Function()
  {
    CommandLineInterpreter cli = new CommandLineInterpreter();
    ActionCallingContext acc = new ActionCallingContext();

    acc.AddParameter("Project", @"C:\Test\Beispielprojekt.elk");
    acc.AddParameter("Action", "reports");
    acc.AddParameter("NOCLOSE", "1");

    cli.Execute("ProjectAction", acc);

    MessageBox.Show("Action ausgeführt.");
  }
}


07 XEsSetProjectPropertyAction
using System.Windows.Forms;
using Eplan.EplApi.ApplicationFramework;
using Eplan.EplApi.Scripting;

public class _15_Beispiele_07_XEsSetProjectPropertyAction
{
  [Start]
  public void Function()
  {
    CommandLineInterpreter cli = new CommandLineInterpreter();
    ActionCallingContext acc = new ActionCallingContext();

    acc.AddParameter("PropertyId", "10013");
    acc.AddParameter("PropertyIndex", "0");
    acc.AddParameter("PropertyValue", "23542");

    cli.Execute("XEsSetProjectPropertyAction", acc);

    MessageBox.Show("Action ausgeführt.");
  }
}


08 Backup
using System;
using System.IO;
using System.Windows.Forms;
using Eplan.EplApi.ApplicationFramework;
using Eplan.EplApi.Base;
using Eplan.EplApi.Scripting;

public class _15_Beispiele_08_Backup
{
  [Start]
  public void Function()
  {
    string projectsPath = PathMap.SubstitutePath("$(MD_PROJECTS)");
    string projectName = PathMap.SubstitutePath("$(PROJECTNAME)");

    string date = DateTime.Now.ToString("yyyy-MM-dd");
    string time = DateTime.Now.ToString("HH-mm-ss");

    string backupDirectory = Path.Combine(projectsPath, "Backup");
    string backupFileName = projectName + "_" +
      date + "_" + time + ".zw1";
    string backupFullFileName = 
      Path.Combine(backupDirectory, backupFileName);

    if (!Directory.Exists(backupDirectory))
    {
      Directory.CreateDirectory(backupDirectory);
    }

    Progress progress = new Progress("SimpleProgress");
    progress.SetAllowCancel(true);
    progress.SetAskOnCancel(true);
    progress.BeginPart(100, "");
    progress.SetTitle("Backup");
    progress.ShowImmediately();

    if (!progress.Canceled())
    {
      CommandLineInterpreter cli = new CommandLineInterpreter();
      ActionCallingContext acc = new ActionCallingContext();

      acc.AddParameter("BACKUPAMOUNT", "BACKUPAMOUNT_ALL");
      acc.AddParameter("BACKUPMEDIA", "DISK");
      acc.AddParameter("BACKUPMETHOD", "BACKUP");
      acc.AddParameter("COMPRESSPRJ", "1");
      acc.AddParameter("INCLEXTDOCS", "1");
      acc.AddParameter("INCLIMAGES", "1");
      acc.AddParameter("ARCHIVENAME", backupFileName);
      acc.AddParameter("DESTINATIONPATH", backupDirectory);
      acc.AddParameter("TYPE", "PROJECT");

      cli.Execute("backup", acc);
    }

    progress.EndPart(true);

    MessageBox.Show(
        "Backup wurde erfolgreich erstellt:" +
        Environment.NewLine +
        backupFullFileName,
        "Hinweis",
        MessageBoxButtons.OK,
        MessageBoxIcon.Information
        );
  }
}


09 Restore
using System.Windows.Forms;
using Eplan.EplApi.ApplicationFramework;
using Eplan.EplApi.Scripting;

public class _15_Beispiele_09_Restore
{
  [Start]
  public void Function()
  {
    CommandLineInterpreter cli = new CommandLineInterpreter();
    ActionCallingContext acc = new ActionCallingContext();

    acc.AddParameter("TYPE", "PROJECT");
    acc.AddParameter("ARCHIVENAME", @"C:\test\Beispielprojekt.zw1");
    acc.AddParameter("PROJECTNAME", @"C:\test\Beispielprojekt.elk");
    acc.AddParameter("UNPACKPROJECT", "0");
    acc.AddParameter("MODE", "1");
    acc.AddParameter("NOCLOSE", "1");

    cli.Execute("restore", acc);

    MessageBox.Show("Action ausgeführt.");
  }
}


10 ProjectManagement
using System.Windows.Forms;
using Eplan.EplApi.ApplicationFramework;
using Eplan.EplApi.Base;
using Eplan.EplApi.Scripting;

public class _15_Beispiele_10_ProjectManagement
{
  [Start]
  public void Function()
  {
    string projectsPath = PathMap.SubstitutePath("$(MD_PROJECTS)");

    OpenFileDialog ofd = new OpenFileDialog();
    ofd.Filter = "ProjectInfo.xml|ProjectInfo.xml";
    ofd.InitialDirectory = projectsPath;
    ofd.Title = "Projekteigenschaften auswählen:";
    ofd.ValidateNames = false;

    if (ofd.ShowDialog() == DialogResult.OK)
    {
      Progress progress = new Progress("SimpleProgress");
      progress.SetAllowCancel(false);
      progress.BeginPart(100, "");
      progress.SetTitle("Projekteigenschaften importieren");
      progress.ShowImmediately();

      CommandLineInterpreter cli = new CommandLineInterpreter();
      ActionCallingContext acc = new ActionCallingContext();

      acc.AddParameter("TYPE", "READPROJECTINFO");
      acc.AddParameter("FILENAME", ofd.FileName);
      cli.Execute("projectmanagement", acc);

      progress.EndPart(true);

      cli.Execute("XPrjActionPropertiesEdit");
    }
  }
}


11 SelectionSet
using System.Windows.Forms;
using Eplan.EplApi.ApplicationFramework;
using Eplan.EplApi.Scripting;

class _15_Beispiele_11_SelectionSet
{
  [Start]
  public void Function()
  {
    CommandLineInterpreter cli = new CommandLineInterpreter();
    ActionCallingContext acc = new ActionCallingContext();
    acc.AddParameter("TYPE", "PAGES");
    cli.Execute("selectionset", acc);

    string pagesString = string.Empty;
    acc.GetParameter("PAGES", ref pagesString);

    string[] pages = pagesString.Split(';');
    int pagesCount = pages.Length;

    MessageBox.Show("Anzahl markierter Seiten: " + pagesCount);
  }
}