Xep21022 Trainingsbook de
Xep21022 Trainingsbook de
Ziele
• Calls – Scripts – API
• Was ist ein Script?
• Grundlagen C#
• Namespaces API / scripting
• Wie ist ein Script zu erstellen?
• „Ausführen“ – „Laden“ eines Scripts
• EPLAN-Settings beeinflussen
• Menü- und Symbolleiste
Call - Script - API
Files
… Extension .VB or .CS
… enthält Program-Logic .NET VB or C#
in EPLAN
… Files werden geladen, kompiliert und
ausgeführt
(ohne zusätzliches Development-Tool)
Development
… kann mittels Text-Editor realsiert werden
… oder mittels Development-Tool:
Syntax .NET VB
.NET Visual Basic
• File-Extension .vb
• Ende einer Zeile: <CRLF>
• Kommentare starten mit '
VB Code - example:
Documentation:
http://openbook.galileocomputing.de/vb_net/
C# Code - example:
Documentation:
http://openbook.rheinwerk-verlag.de/visual C# 2012/
C# Code - example:
Fehlerbehandlung
C# : Try - catch
try
{
// .. Do something;
}
catch (System.Exception ex)
{
// .. Handle the error - case
// .. Do something;
}
finally
{
// .. Do something
}
C# Deklarieren und Initialisieren einer Variable
Variable
C# : Deklarieren und Initialisieren einer Variable
int iZaehler;
iZaehler = 1000;
bool bEntscheidung;
bEntscheidung = true;
// Objekte anlegen
CommandLineInterpreter oCLI = new CommandLineInterpreter();
Basic_Datentyp.cs
C# Kontrollstrukturen
Kontrollstrukturen
C# : if else
if (Bedingung)
{
//instruction1
}
else
{
//instruction 2
}
C# : switch
switch (oDialogResult)
{
case DialogResult.Yes:
// instruction Yes;
break;
case DialogResult.No :
// instruction No;
break;
default:
//instruction Cancel;
}
Basic_Kontrollstrukturen_If_Ausführen.cs; Basic_Kontrollstrukturen_Switch_Ausführen.cs
C# Schleifen
Schleifen
C# : for
for(int i=0; i<=10; i++)
{
// for führt eine Anweisung oder einen Anweisungsblock aus, solange ein angegebener boolescher Ausdruck true ergibt. Z.B. "i<=10"
// instruction;
}
C# : while
while (Bedingung)
{
// Eine while-Schleife wird ausgeführt, solange die Bedingung true ist.
// Die Schleife wird beendet, wenn die Bedingung false ist.
// instruction1;
}
Basic_Schleifen_For_Ausführen.cs; Basic_Schleifen_While_Ausführen.cs
Möglichkeiten im Scripting
Ausführen …
Dienstprogramme> Scripte > Ausführen... ; nur temporär verfügbar.
Laden…
Dienstprogramme> Scripte > Laden... ; Script ist permanent verfügbar.
Attribute used to
<DeclareMenu()> [DeclareMenu]
implement menu-points.
Verweise auf EPLAN.EplApi.*dll
Eplan.EplApi.Baseu.dll enthält:
Eplan.EplApi.Base
Eplan.EplApi.Guiu.dll enthält:
Eplan.EplApi.GUI
Eplan.EplApi.CommandLineActions;
call via CommandLineInterpreter
using System;
.NET:
using System.Collections.Generic;
using System.Text;
using System.IO;
System; // ====
using Eplan.EplApi.ApplicationFramework;
using Eplan.EplApi.Base; http://www.eplan.help/help/platformapi/2.7/en-us/help/index.html
System.XML using Eplan.EplApi.Gui;
using Eplan.EplApi.Scripting;
System.Drawing using System.Windows.Forms;
// ====
System.Windows.Forms
Einstellungen im “Script”- Projekt
EPLAN 2.7
uses .Net Framework 4.5.2
C#: example – HalloWelt “Start” - Script
C# : example
SEM_HalloWelt.cs
C#: example – HalloWelt “Start” - Script
C# : example
SEM_HalloWelt.cs
C#: example – HalloWelt “Start” - Script
C# : example
SEM_HalloWelt.cs
C#: example – Wichtige Benutzereinstellungen Setzen
C# : SEM_ScriptEinstellungen_Ausführen.cs
SEM_ScriptEinstellungen_Ausführen.cs
EPLAN – Settings (Benutzer, Station, Firma)
“Einstellungspfad in die
Zwischenablage kopieren”
C# : example
SEM_SetBoolSetting4Toggle_Laden.cs
C#: Example – "Laden" - Action mit Menüeintrag
C# : example
class example
{
[DeclareAction("MyAction")]
public bool MyAction(string sName)
{
// Action with parameter
MessageBox.Show("Hallo Welt, schöne Grüße von ", "Begrüßung");
return true;
}
[DeclareMenu]
public void MenuFunction()
{
Eplan.EplApi.Gui.Menu oMenu = new Eplan.EplApi.Gui.Menu();
oMenu.AddMenuItem("MyAction_Call", "MyAction");
}
}
EPLAN Diagnostics?
Execute action
Name and Menu-ID
DumpInfo-Dialog
=>[Strg]+[^] Germany
=>[CTRL]+[\] UK
=>[CTRL]+[§]
=>[CTRL]+[|] US
=>[CTRL]+<]>
EPLAN - Actions
oder
new CommandLineInterpreter().Execute("label /configscheme:\"Device tag list\" /language:de_DE
/destinationfile:\"$(MD_DOCUMENTS)\\$(PROJECTNAME)_BM-LISTE2.txt\" /recrepeat:1 /taskrepeat:1
/showoutput:1");
SEM_CommandLineInterpreterBeschriftungsAusgabe_Ausführen.cs
EPLAN – Aktionen protokollieren
Aktionen protokollieren
EPLAN_ExampleSystemmeldungen_Ausführen.cs
C#: Progress - Fortschrittsanzeige
C# : example
EPLAN_ProgressBarSimple_Ausführen.cs
C#: Menü und Kontextmenü
EA_MenuVerzeichnisse_Laden.cs; SEM_Kontextmenüerweiterung_Laden.cs
C#: Menü und Kontextmenü
EA_MenuVerzeichnisse_Laden.cs; SEM_Kontextmenüerweiterung_Laden.cs
C#: Example
C# : example: „Project_Closing_Functions.cs“
3. Anzeige Progress
EPLAN – Automatisiert bearbeiten
Im Script-Verzeichnis
befindet sich das erstellte
Script „workshop.cs“
EPLAN – Einstellungen
Benutzereinstellung:
EA_SetBoolSetting3Toggle_Ausführen.cs
EPLAN – Properties - Eigenschaften
EPLAN -Eigenschaften
• Jedes Objekt (project, page, functions) hat Eigenschaften
• Eigenschaften werden über eine eindeutige Nummer identifiziert
// PropertyIdentName
PropertyId
PropertyValue
PropertyIndex
• Eigenschaften sind typisiert (bool, integer, string ...)
oCLI.Execute("XEsSetProjectPropertyAction", oACC); {
EA_Projekteigenschaft1Setzen_Ausführen.cs
EPLAN – Projektname ermitteln
….
string sProjectName1 = PathMap.SubstitutePath("$(PROJECTNAME)");
string sProjectName2 = projectName();
…..}
public string projectName()
{
// Ermittelt das aktuelle Projekt und gibt den vollständigen Projektnamen zurück
ActionCallingContext oContext = new ActionCallingContext();
oContext.AddParameter("type", "PROJECT");
bool ret = new CommandLineInterpreter().Execute("selectionset", oContext);
if (ret != false)
{
string sBack = string.Empty;
oContext.GetParameter("PROJECT", ref sBack);
return sBack;
}
return string.Empty;
}
}
[DeclareEventHandler("Eplan.EplApi.OnUserPreCloseProject")]
public void MyEventHandlerFunction1(IEventParameter iEventParameter)
{
EventParameterString oEventParameterString = new EventParameterString(iEventParameter);
string sProjectName3 = oEventParameterString.String;
… }
EPLAN_ProjektnameErmitteln_Laden.cs
EventHandler
Siehe API-Hilfe:
Eplan.EplApi.ApplicationFramework.Events Namespace
Event Description
Eplan.EplApi.OnMainStart Send when the Main Start is done; when a mainframe is available
EPLAN_DeclareEventHandler_Laden.cs
Script debuggen
Start EPLAN
Entwicklungsumgebung mit Projekt öffnen.
Das Script erneut in EPLAN laden.
(Dienstprogramme; Scripte entladen – laden)
DebugScript laden.
Name: „Debug_<scriptname>
(Name: „Debug_<scriptname>
(Das DebugScript liegt im „tmp“ Ordner. „$(TMP)“ kontrollieren!)
(Das DebugScript darf beim öffnen nicht verändert werden.)
Scripting API
Acting on Events
Creating Actions
Start Functionality
without loading
Design Menu
Toolbar, (Contextmenu)
Read/Set Setting ()
Read/Set Properties ()
Export EPLAN-Data
(Labeling, …)
Übersicht - API
API
Create / Modify EPLAN-Objects directly
(project, pages, function, articles, …….)
Change layer-information in the project
Change parts directly;
additional influence on the functionality in the
parts-management-dialogs
Create own check functionality
(“Prüfläufe” – “Verifications“)
Access project message database
handle events connected with interactive work in GED ()
(not internal dialogs)
Perspektiven im Engineering