EPLAN-Scripts

ScriptTest

Es macht keinen Spaß Scripte zu testen… Immer wieder entladen, laden… die Fehlersuche wird somit noch schwieriger.
Ich habe lange überlegt, wie hier der Workflow optimiert werden kann.

Natürlich mit einem Script :)

Mit diesem Script, welches in EPLAN geladen werden muss, können verschiedene andere Scripte automatisch aus Visual Studio heraus in EPLAN getestet werden.

Der Ablauf ist wie folgt:

  • ScriptTest.cs in EPLAN laden
  • Visual Studio Projekt Startoptionen einstellen
  • Parameter angeben

In Visual Studio sehen die Startoptionen wie folgt aus:

Eigenschaften

C:\Program Files (x86)\EPLAN\Platform\2.4.4\Bin\EPLAN.exe
/Variant:"Electric P8" ScriptTest /parameter:'' /execute:"true" /scriptPath:"C:\Test\Script\Test.cs"

Leere Parameter müssen auch mit angegeben werden.

Hinweis für Nutzer von Visual Studio Express: Dort gibt es den Einstellungsdialog für Startoptionen nicht. Ein Workaround ist hier beschrieben.

Freu mich sehr über die Arbeitserleichterung… und darüber dass ich ein Einhorn bzw. Drache sein kann!

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

namespace ibKastl.Scripts.Test
{
    class ScriptTest
    {
        /// <summary>
        /// Start Visual Studio with the given Script
        /// </summary>
        /// <param name="scriptPath">Full Path to .cs or .vb File</param>
        /// <param name="parameter">Parameters for the Action</param>
        /// <param name="execute">Excute after EPLAN started</param>
        [DeclareAction("ScriptTest")]               
        public void Action(string scriptPath, string parameter, string execute)
        {
            // Check file
            if (!File.Exists(scriptPath))
            {
                MessageBox.Show("Scriptdatei wurde nicht gefunden:"
                                + Environment.NewLine + scriptPath + Environment.NewLine +
                                "Das Script wurde nicht geladen.",
                                "Warnung", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else
            {
                string actionName = Path.GetFileNameWithoutExtension(scriptPath);
                CommandLineInterpreter commandLineInterpreter = new CommandLineInterpreter();

                // Unload if Action exists
                ActionCallingContext actionCallingContextUnregister = new ActionCallingContext();
                actionCallingContextUnregister.AddParameter("DontShowErrorMessage", "1");
                actionCallingContextUnregister.AddParameter("ScriptFile", scriptPath);
                commandLineInterpreter.Execute("UnregisterScript", actionCallingContextUnregister);

                // Load Script 
                ActionCallingContext actionCallingContextRegister = new ActionCallingContext();
                actionCallingContextRegister.AddParameter("ScriptFile", scriptPath);
                commandLineInterpreter.Execute("RegisterScript", actionCallingContextRegister);

                // Execute
                if (execute.ToLower().Equals("true"))
                {
                    if (!string.IsNullOrEmpty(parameter))
                    {
                        commandLineInterpreter.Execute(actionName + " " + parameter); 
                    }
                    else
                    {
                        commandLineInterpreter.Execute(actionName); 
                    }
                }
            }

        }
    }
}

ScriptTest

Von |2017-11-09T12:23:41+01:002014-10-15|EPLAN, EPLAN-Scripts|

SetGrid

Unsere russischen Freunde von Eplan For All haben ein schönes Script geschrieben um die Raster-Größe anzupassen.

Download auf eplan4all.info

Vielen Dank!

 

//  Ersteller (разработчик):  madwolf_by aka Виталий
//  Datum:      2014-08-18 
//  www.eplan4all.info - Eplan For All


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


public class SetGrid
{
    Settings oSettings = new Settings();
    string sPath = "USER.Control.UserGridSize";
    string sPath1 = "USER.Control.UserGridSizeMode";

    [DeclareRegister]
    public void Register()
    {
        if (!oSettings.ExistSetting(sPath))
        {
            if (!oSettings.ExistSetting(sPath))
                oSettings.AddStringSetting(sPath, new string[] { }, new string[] { }, "Current Gridsize", new string[] { @"4" }, ISettings.CreationFlag.Insert);
//            MessageBox.Show("Setting " + sPath + " registered");
        }

        if (!oSettings.ExistSetting(sPath1))
            oSettings.AddBoolSetting(sPath1, new bool[1], "UserGridSizeMode", new bool[1], ISettings.CreationFlag.Insert);

        return;
    }

    [DeclareUnregister]
    public void UnRegister()
    {
        if (oSettings.ExistSetting(sPath))
        {
            oSettings.DeleteSetting(sPath);
//            MessageBox.Show("Setting " + sPath + " unregistered");
        }
    }

    [DeclareAction("SetUserGridSize")]

    public void SetUserGrid(string GridSize)
    {
       
        if (oSettings.GetBoolSetting(sPath1, 0))
        {
            oSettings.SetStringSetting(sPath, GridSize, 0);
            //MessageBox.Show("Incoming param " + oSettings.GetDoubleSetting(sPath, 0));
            SetGridSizeToPage(GridSize);
        }

        else MessageBox.Show("Function is OFF", "SetGrid mode");
        
    }

    [DeclareAction("SetUserGridMode")]

    public void SetUserGridMode()
    {
        oSettings.SetBoolSetting(sPath1, !oSettings.GetBoolSetting(sPath1, 0), 0);
        if (oSettings.GetBoolSetting(sPath1, 0))
        {
            MessageBox.Show("Function is ON", "SetGrid mode");

        }

        else MessageBox.Show("Function is OFF", "SetGrid mode");

    }

    [DeclareEventHandler("onActionEnd.String.XGedNextPageAction")]
    public bool MyEventHandlerFunction1(IEventParameter iEventParameter)
    {
        SetGridSizeToPage(oSettings.GetStringSetting(sPath, 0));
        return true;
    }

    [DeclareEventHandler("onActionEnd.String.XGedPrevPageAction")]
    public bool MyEventHandlerFunction2(IEventParameter iEventParameter)
    {
        SetGridSizeToPage(oSettings.GetStringSetting(sPath, 0));
        return true;
    }

    [DeclareEventHandler("onActionStart.String.XPmPageOpenOnePage")]
    public bool MyEventHandlerFunction3(IEventParameter iEventParameter)
    {
        SetGridSizeToPage(oSettings.GetStringSetting(sPath, 0));
        return true;
    }
    

    public void SetGridSizeToPage(string paramValue)
    {
        if (oSettings.GetBoolSetting(sPath1, 0))
        {
            CommandLineInterpreter oCLI = new CommandLineInterpreter();
            ActionCallingContext oACC = new ActionCallingContext();
            string nameAction = "XEsSetPagePropertyAction";
            oACC.AddParameter("PropertyId", "11051");
            oACC.AddParameter("PropertyIndex", "0");
            //        MessageBox.Show("param from setting " +  Convert.ToString(oSettings.GetDoubleSetting(sPath, 0)));
            oACC.AddParameter("PropertyValue", paramValue);
            oCLI.Execute(nameAction, oACC);
        }
    }
}
Von |2017-11-09T12:23:41+01:002014-09-30|EPLAN, EPLAN-Scripts|

EplanCOMApplication

Oftmals muss man aus einer Applikation heraus EPLAN befeuern aufrufen und Actions ausführen.

Mit der COM Api von EPLAN ist dies möglich.

In Visual Studio müsst ihr den Verweis herstellen:

Verweise

Aufgerufen wird das ganze wie folgt:

EplanApplication eplanApplication = new EplanApplication();
eplanApplication.Show();
eplanApplication.ExecuteCommand("edit " +
                                "/PROJECTNAME:" + EplanProject +
                                " /DEVICENAME:" + SelectedFunction);

Zu beachten:

  • Ist EPLAN geöffnet wird dieser Prozess verwendet.
  • Ist EPLAN nicht geöffnet wird ein Prozess im Hintergrund gestartet und erst mit Show() sichtbar gemacht.
  • Wird beim Start des COM Objektes keine gültige Lizenz für EPLAN gefunden, bleibt das Programm stehen (muss abgeschossen werden).
Von |2017-11-09T12:23:42+01:002014-09-25|EPLAN, EPLAN-Scripts|

TranslateLanguages

Mit diesem Script können alle Sprachen des eingestellten Wörterbuchs abgerufen werden:

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

public class TranslateLanguages
{
    [Start]
    public void Execute()
    {
        Settings setting = new Settings();
        string stringSetting = setting.GetStringSetting("USER.TRANSLATE.TRANSLATE_LANGUAGES", 0);
        MessageBox.Show(stringSetting.Replace(";", Environment.NewLine));
    }
}

Translate_Languages

Von |2017-11-09T12:23:42+01:002014-09-22|EPLAN, EPLAN-Scripts|

XFREActionFrameOpen

Mit diesem Script wird ein Normblatt zum editieren geöffnet.

Vielen Dank an KRM!

using Eplan.EplApi.ApplicationFramework;
using Eplan.EplApi.Scripting;

class XFREActionFrameOpenAction
{
    [Start]
    public void XFREActionFrameOpenActionFunction()
    {
        ActionCallingContext acc = new ActionCallingContext();
        acc.AddParameter("NewFrame", "1");
        acc.SetStrings(new string[] { @"\\Path\To\Frame\NameOfFile.fn1" });
        new CommandLineInterpreter().Execute("XFREActionFrameOpen", acc);
    }
}
Von |2017-11-09T12:23:42+01:002014-07-17|EPLAN, EPLAN-Scripts|
Nach oben