JohannWeiher

Über Johann Weiher

Der Autor hat bisher keine Details angegeben.
Bisher hat Johann Weiher, 533 Blog Beiträge geschrieben.

Ankündigung: Home Automation Kategorie

Komm der Zeit nicht viel zum Schreiben, aber an Ideen fehlt es mir nicht :^)
Als Ankündigung vorweg: Ich möchte gerne mehr über Heimautomatisierung schreiben, wenn jemand Ideen hat, was man sich auf alle Fälle anschauen sollte, bin ich über Vorschläge dankbar.

Ich hab im letzten Jahr einiges an Hardware angesammelt, was definitiv hier Erwähnung finden sollte.
Vielleicht Hoffentlich finde ich um die Feiertage Zeit, hier bisl mehr zu Schreiben!

Von |2014-12-12T13:51:43+01:002014-12-14|Home Automation|

EPLAN Pong

Der Preis für die beste EPLAN Erweiterung geht an Daniel Papp!

Das ganze funktioniert als API-Addin und ist auf Github zu finden. Einfach klasse :^)

Von |2017-11-09T12:23:54+01:002014-11-26|EPLAN, EPLAN-API|

GetProjectProperty

Info: Es gibt eine neue Version von diesem Script.

Mit diesem Script könnt ihr einzelne Projekteigenschaften lesen.

Als Parameter habe ich mich für string entschieden, da zum Setzen der Projekteigenschaft die ID auch als String übergeben werden muss.

Verwendung:

string value = GetProjectProperty(Id, Index);

Die Methode muss im verwendeten Script vorhanden sein:

private static string GetProjectProperty(string id, string index)
{
	string value = null;
	ActionCallingContext actionCallingContext = new ActionCallingContext();
	actionCallingContext.AddParameter("id", id);
	actionCallingContext.AddParameter("index", index);
	new CommandLineInterpreter().Execute("GetProjectProperty", actionCallingContext);
	actionCallingContext.GetParameter("value", ref value);
	return value;
}

Das Script GetProjectProptery.cs laden und das Schema (GetProjectProperty_Template.xml) im Ordner Scripte/GetProjectProperty abspeichern.
Anbei das ganze Script + Download.

/* Usage
	private static string GetProjectProperty(string id, string index)
	{
		string value = null;
		ActionCallingContext actionCallingContext = new ActionCallingContext();
		actionCallingContext.AddParameter("id", id);
		actionCallingContext.AddParameter("index", index);
		new CommandLineInterpreter().Execute("GetProjectProperty", actionCallingContext);
		actionCallingContext.GetParameter("value", ref value);
		return value;
	}
*/

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

class GetProjectProperty
{
    [DeclareAction("GetProjectProperty")]
    public void Action(string id, string index, out string value)
    {
        string pathTemplate = Path.Combine(PathMap.SubstitutePath("$(MD_SCRIPTS)"),
            "GetProjectProperty", "GetProjectProperty_Template.xml");
        string pathScheme = Path.Combine(PathMap.SubstitutePath("$(MD_SCRIPTS)"),
            "GetProjectProperty", "GetProjectProperty_Scheme.xml");

        try
        {
            // Set scheme
            string content = File.ReadAllText(pathTemplate);
            content = content.Replace("GetProjectProperty_ID", id);
            content = content.Replace("GetProjectProperty_INDEX", index);
            File.WriteAllText(pathScheme, content);

            new Settings().ReadSettings(pathScheme);

            string pathOutput = Path.Combine(
                PathMap.SubstitutePath("$(MD_SCRIPTS)"), "GetProjectProperty",
                "GetProjectProperty_Output.txt");

            // Export
            ActionCallingContext actionCallingContext = new ActionCallingContext();
            actionCallingContext.AddParameter("configscheme", "GetProjectProperty");
            actionCallingContext.AddParameter("destinationfile", pathOutput);
            actionCallingContext.AddParameter("language", "de_DE");
            new CommandLineInterpreter().Execute("label", actionCallingContext);

            // Read
            value = File.ReadAllLines(pathOutput)[0];
        }
        catch (Exception exception)
        {
            MessageBox.Show(exception.Message, "GetProjectProperty", MessageBoxButtons.OK,
                MessageBoxIcon.Error);
            value = "[Error]";
        }
    }
}

GetProjectProperty auf GitHub

Von |2018-08-17T12:30:10+02:002014-11-12|EPLAN, 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|
Nach oben