script

Script ActionCallingContext

Mit der Version 2.9 gab es eine sehr schöne Neuerung: ActionCallingContext kann nun im Scripting verwendet werden.
API Programmierer unter Euch kennen diesen schon. Nun haben wir die Vorteile auch im Scripting:

  • Parameter können optional sein
  • Action kann mit Parametern angereichert werden

Das Beispiel in der Hilfe finde ich bisl verwirrend, da es auch das Hinzufügen von Parametern gleich beinhaltet, hier mal ein kleines Beispiel. Es können zwei Parameter optional angegeben werden. Sind diese vorhanden, werden Sie in einer MessageBox angezeigt.

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

public class TestScript
{
  private ActionCallingContext _acc;

  [DeclareAction("ActionCallingContextDemo")]
  public void Action(ActionCallingContext acc)
  {
    _acc = acc;

    DisplayParameter("firstParameter");
    DisplayParameter("secondParameter");
  }

  private void DisplayParameter(string parameterName)
  {
    string parameter = null;
    _acc.GetParameter(parameterName, ref parameter);
    if (!string.IsNullOrEmpty(parameter))
    {
      MessageBox.Show(parameter);
    }
  }
}
Von |2019-09-17T09:00:00+02:002019-09-17|EPLAN, EPLAN-Scripts|

SVGExportAction

Es handelt sich um eine interne Action von EPLAN, welche offiziell nicht supported wird!

SVG ist ein tolles Format… Hab den Anwendungsfall dass ich SVG aus EPLAN brauche. Darum habe ich mir mal einen Helfer-Klasse geschrieben, damit der Zugriff einfacher ist:

public class SvgExportUtility
{
  public static void ExportProject(Project project, string exportPath, bool isFrameVisible = true)
  {
    if (Directory.Exists(exportPath))
    {
      Directory.Delete(exportPath);
    }

    ActionCallingContext acc = new ActionCallingContext();
    acc.AddParameter("DatabaseId", project.DatabaseIdentifier.ToString());
    acc.AddParameter("ExportPath", exportPath);
    acc.AddParameter("DrawFrame", isFrameVisible.ToString());
    acc.AddParameter("WriteGroupIds", false.ToString());
    new CommandLineInterpreter().Execute("SVGExportAction", acc);
  }

  public static void ExportPage(Page page, string fullFilename, bool isFrameVisible = true)
  {
    if (File.Exists(fullFilename))
    {
      File.Delete(fullFilename);
    }

    ActionCallingContext acc = new ActionCallingContext();
    acc.AddParameter("ExportPath", Path.GetDirectoryName(fullFilename));
    acc.AddParameter("PageObjId", page.ToStringIdentifier());
    acc.AddParameter("Filename", Path.GetFileNameWithoutExtension(fullFilename)); // only name needed
    acc.AddParameter("DrawFrame", isFrameVisible.ToString());
    acc.AddParameter("WriteGroupIds", false.ToString());
    new CommandLineInterpreter().Execute("SVGExportAction", acc);
  }

  public static void ExportPageMacro(Project project, string pageMacroFile, string fullFilename, bool isFrameVisible = true)
  {
    using (PageMacro pageMacro = new PageMacro())
    {
      // Have to insert pages into project because its not working with pageMacro.Pages.First()
      pageMacro.Open(pageMacroFile, project);

      // Set temp structure
      for (var index = 0; index < pageMacro.Pages.Length; index++)
      {
        var pageMacroPage = pageMacro.Pages[index];
        pageMacroPage.NameParts[Properties.Page.PAGE_COUNTER] = "SvgExportUtility" + index;
      }

      var storableObjects = new Insert().PageMacro(pageMacro, project, null, PageMacro.Enums.NumerationMode.None);
      var newPages = storableObjects.OfType().ToList();

      for (var index = 0; index < newPages.Count; index++)
      {
        var newPage = newPages[index];
        var path = Path.GetDirectoryName(fullFilename);
        var filename = Path.GetFileNameWithoutExtension(fullFilename) + "_" + (index + 1) + ".svg";

        // ReSharper disable once AssignNullToNotNullAttribute
        filename = Path.Combine(path, filename);

        if (File.Exists(fullFilename))
        {
          File.Delete(fullFilename);
        }

        ExportPage(newPage, filename, isFrameVisible);

        // Remove pages after export
        newPage.Remove();
      }
    }
  }

  public static void ExportMacro(string macroFile, string fullFilename, int variant, WindowMacro.Enums.RepresentationType representationType)
  {
    if (File.Exists(fullFilename))
    {
      File.Delete(fullFilename);
    }

    ActionCallingContext acc = new ActionCallingContext();
    acc.AddParameter("MacroFile", macroFile);
    acc.AddParameter("Filename1", fullFilename); // Full path needed
    acc.AddParameter("Variant1", variant.ToString());
    acc.AddParameter("RepType1", ((int)representationType).ToString());
    acc.AddParameter("WriteGroupIds", false.ToString());
    new CommandLineInterpreter().Execute("SVGExportAction", acc);
  }
}

Das exportieren von Symbol- & Fenstermakros funktioniert auch im Scripting!

Ich habe auch mal ein kleines Beispiel-Addin geschrieben um die Funktionalitäten zu testen.

Von |2019-08-23T08:20:21+02:002019-08-23|EPLAN, EPLAN-API, EPLAN-Scripts|
Nach oben