Buch
EPLAN Electric P8 automatisieren
Grundlagen und Beispiele zum Erstellen von Scripten in Visual C#
- Menüs erzeugen und erweitern
- Einzelne oder mehrere Einstellungen gleichzeitig per Knopfdruck verändern
- Formulare mit individuellen Steuerelementen (Checkboxen, Ladebalken, Buttons) erstellen
- Programmsteuerung über Benutzer-Interaktionen
Alle Scripte des Buches einzeln ladbar:
01_Menüpunkt_in_Dienstprogramme
03_Hauptmenü_mit_Untermenüpunkt
04_Bestehendes_Menü_mit_Popup-Menü_erweitern
02_Unterschiedliche_Prozesse_ausführen
11_Dateien_öffnen_und_speichern
02_Beschriftung_mit_Überprüfung
03_PDF_beim_Schließen_erzeugen
13_Projekteigenschaften_importieren
Alle Scripte des Buches in der Übersicht:
01_Erste_Schritte\01_Start
1 2 3 4 5 6 7 8 9 10 11 12 13 | using System.Windows.Forms; using Eplan.EplApi.Scripting; public class Class { [Start] public void Function() { MessageBox.Show("Ich kann Scripten!"); // Kommentar return; } } |
01_Erste_Schritte\02_DeclareAction
1 2 3 4 5 6 7 8 9 10 11 12 13 | using System.Windows.Forms; using Eplan.EplApi.Scripting; public class Class { [DeclareAction("Actionname")] public void Function() { MessageBox.Show("Ich kann Scripten!"); return; } } |
01_Erste_Schritte\03_DeclareEventHandler
1 2 3 4 5 6 7 8 9 10 11 12 13 | using System.Windows.Forms; using Eplan.EplApi.Scripting; public class Class { [DeclareEventHandler("onActionStart.String.XPrjActionProjectClose")] public void Function() { MessageBox.Show("Ich kann Scripten!"); return; } } |
01_Erste_Schritte\04_DeclareRegisterUnregister
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | using System.Windows.Forms; using Eplan.EplApi.Scripting; public class Class { [DeclareRegister] public void Register() { MessageBox.Show("Script geladen."); return; } [DeclareUnregister] public void UnRegister() { MessageBox.Show("Script entladen."); return; } } |
02_Actions_ausführen\01_Einzelne_Action
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | using Eplan.EplApi.ApplicationFramework; using Eplan.EplApi.Scripting; public class Class { [Start] public void Function() { CommandLineInterpreter oCLI = new CommandLineInterpreter(); oCLI.Execute("reports"); return; } } |
02_Actions_ausführen\02_Mehrere_Actions
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | using System.Windows.Forms; using Eplan.EplApi.ApplicationFramework; using Eplan.EplApi.Scripting; public class Class { [Start] public void Function() { CommandLineInterpreter oCLI = new CommandLineInterpreter(); oCLI.Execute("XMsgActionStartVerification"); oCLI.Execute("reports"); oCLI.Execute("Actionname"); return; } } |
02_Actions_ausführen\03_Action_mit_Parameter
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | using Eplan.EplApi.ApplicationFramework; using Eplan.EplApi.Scripting; public class Class { [Start] public void Function() { CommandLineInterpreter oCLI = new CommandLineInterpreter(); ActionCallingContext acc = new ActionCallingContext(); acc.AddParameter("Name", "XGedIaFormatText"); acc.AddParameter("height", "20"); oCLI.Execute("XGedStartInteractionAction", acc); return; } } |
03_Objekte\01_String
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | using System; using System.Windows.Forms; using Eplan.EplApi.Scripting; public class Class { [Start] public void Function() { MessageBox.Show("Ich bin ein Text (aber eigentlich ein String)!"); string strMessage1 = string.Empty; strMessage1 = "Ich bin ein String mit\nZeilenumbruch!"; MessageBox.Show(strMessage1); string strMessage2 = "Ich bin auch ein String!"; MessageBox.Show(strMessage2); strMessage2 = "Mir kann man auch einen neuen Text übergeben!"; MessageBox.Show(strMessage2); string strMessage3_1 = "Und ich "; string strMessage3_2 = "bin auch "; string strMessage3_3 = "einer!"; MessageBox.Show(strMessage3_1 + strMessage3_2 + strMessage3_3); MessageBox.Show("Wenn man einen Zeilenumbruch im Code eingibt " + "wird dieser nicht angezeigt!"); string strMessage4 = "Der {0} ist im {1}."; string strMessage4_1 = String.Format(strMessage4, "Kamm", "Schrank"); string strMessage4_2 = String.Format(strMessage4, "Schrank", "Badezimmer"); MessageBox.Show(strMessage4_1); MessageBox.Show(strMessage4_2); return; } } |
03_Objekte\02_String_Pfadvariable
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | using System.Windows.Forms; using Eplan.EplApi.Base; using Eplan.EplApi.Scripting; public class Class { [Start] public void Function() { string strProjectname = PathMap.SubstitutePath("$(PROJECTNAME)"); MessageBox.Show(strProjectname); return; } } |
03_Objekte\03_Integer
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | using System.Windows.Forms; using Eplan.EplApi.Scripting; public class Class { [Start] public void Function() { int intResult = 0; int intNumber1 = 6; int intNumber2 = 3; MessageBox.Show(intNumber1.ToString()); intResult = intNumber1 + intNumber2; MessageBox.Show(intResult.ToString()); intResult = intNumber1 - intNumber2; MessageBox.Show(intResult.ToString()); intResult = intNumber1 * intNumber2; MessageBox.Show(intResult.ToString()); intResult = intNumber1 / intNumber2; MessageBox.Show(intResult.ToString()); return; } } |
03_Objekte\04_Fehler_Integer
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | using System.Windows.Forms; using Eplan.EplApi.Scripting; public class Class { [Start] public void Function() { string strNumber1 = "10"; string strNumber2 = "2"; string strResultString = strNumber1 + strNumber2; MessageBox.Show(strResultString); int intResult = 0; int intNumber1 = 10; int intNumber2 = 0; intResult = intNumber1 / intNumber2; MessageBox.Show(intResult.ToString()); return; } } |
03_Objekte\05_Float
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | using System.Windows.Forms; using Eplan.EplApi.Scripting; public class Class { [Start] public void Function() { float fltResultFloat = 0; float fltNumber1 = 10; float fltNumber2 = 3; fltResultFloat = fltNumber1 / fltNumber2; MessageBox.Show(fltResultFloat.ToString()); return; } } |
03_Objekte\06_Fehler_Float
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | using System.Windows.Forms; using Eplan.EplApi.Scripting; public class Class { [Start] public void Function() { float fltResultFloat = 0; fltResultFloat = 10 / 3; MessageBox.Show("10 / 3 = " + fltResultFloat.ToString()); return; } } |
03_Objekte\07_TryCatch
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | using System.Windows.Forms; using Eplan.EplApi.Scripting; using System; public class Class { [Start] public void Function() { int intResult = 0; int intNumber1 = 10; int intNumber2 = 0; try { intResult = intNumber1 / intNumber2; //Ab hier wird kein Code mehr ausgeführt MessageBox.Show(intResult.ToString()); MessageBox.Show("Berechnung erfolgreich beendet"); } catch (Exception ex) { MessageBox.Show(ex.Message); } //Ab hier wird der Code wieder ausgeführt MessageBox.Show("Berechnung beendet"); return; } } |
03_Objekte\08_Systemmeldungen
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | using Eplan.EplApi.ApplicationFramework; using Eplan.EplApi.Base; using Eplan.EplApi.Scripting; public class Class { [Start] public void Function() { BaseException bexAssert = new BaseException("Assert", MessageLevel.Assert); bexAssert.FixMessage(); BaseException bexError = new BaseException("Error", MessageLevel.Error); bexError.FixMessage(); BaseException bexFatalError = new BaseException("FatalError", MessageLevel.FatalError); bexFatalError.FixMessage(); BaseException bexMessage = new BaseException("Message", MessageLevel.Message); bexMessage.FixMessage(); BaseException bexTrace = new BaseException("Trace", MessageLevel.Trace); bexTrace.FixMessage(); BaseException bexWarning = new BaseException("Warning", MessageLevel.Warning); bexWarning.FixMessage(); CommandLineInterpreter oCLI = new CommandLineInterpreter(); oCLI.Execute("SystemErrDialog"); return; } } |
03_Objekte\09_Parameter_String
1 2 3 4 5 6 7 8 9 10 11 12 13 | using System.Windows.Forms; using Eplan.EplApi.Scripting; public class Class { [DeclareAction("StringParameter")] public void Function(string ParaString) { MessageBox.Show(ParaString); return; } } |
03_Objekte\10_Parameter_Integer
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | using System.Windows.Forms; using Eplan.EplApi.Scripting; public class Class { [DeclareAction("IntParameter")] public void Function(int INT1, int INT2) { int ResultInt = INT1 + INT2; MessageBox.Show(INT1.ToString() + " + " + INT2.ToString() + " = " + ResultInt.ToString()); return; } } |
03_Objekte\11_Messagebox
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | using System.Windows.Forms; using Eplan.EplApi.Base; using Eplan.EplApi.Scripting; public class Class { [Start] public void Function() { string strProjectname = PathMap.SubstitutePath("$(PROJECTNAME)"); MessageBox.Show("Text", strProjectname); MessageBox.Show( "Text", strProjectname, MessageBoxButtons.YesNo ); MessageBox.Show( "Text", strProjectname, MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Information ); return; } } |
04_Programmsteuerung\01_IF_String
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | using System.Windows.Forms; using Eplan.EplApi.Scripting; public class Class { [DeclareAction("IfString")] public void Function(string ParaString) { if (ParaString == "JA") { MessageBox.Show("Bedingung erfüllt."); } else { MessageBox.Show("Bedingung nicht erfüllt."); } if (ParaString.ToUpper() == "JA") { MessageBox.Show("Bedingung erfüllt."); } else { MessageBox.Show("Bedingung nicht erfüllt."); } return; } } |
04_Programmsteuerung\02_ElseIf
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | using System.Windows.Forms; using Eplan.EplApi.Scripting; public class Class { [Start] public void Function() { DialogResult Result = MessageBox.Show( "Soll die Aktion ausgeführt werden?", "Titelzeile", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question ); if (Result == DialogResult.Yes) { MessageBox.Show("Es wurde 'Ja' gedrückt."); } else if (Result == DialogResult.No) { MessageBox.Show("Es wurde 'Nein' gedrückt."); } else if (Result == DialogResult.Cancel) { MessageBox.Show("Es wurde 'Abbrechen' gedrückt."); } return; } } |
04_Programmsteuerung\03_Switch
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | using System.Windows.Forms; using Eplan.EplApi.Scripting; public class Class { [Start] public void Function() { DialogResult Result = MessageBox.Show( "Soll die Aktion ausgeführt werden?", "Titelzeile", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); switch (Result) { case DialogResult.Yes: MessageBox.Show("Es wurde 'Ja' gedrückt."); break; case DialogResult.No: goto default; default: MessageBox.Show("Es wurde 'Nein' oder" + "'Abbrechen' gedrückt."); break; } return; } } |
04_Programmsteuerung\04_Methode_Messagebox
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | using System.Windows.Forms; using Eplan.EplApi.Scripting; public class Class { [DeclareAction("MethodeMessagebox")] public void Function(int INT1, int INT2) { int intResult = INT1 + INT2; MessageBox.Show(INT1.ToString() + " + " + INT2.ToString() + " = " + intResult.ToString()); FinishedMessageBox1(); return; } private static void FinishedMessageBox1() { MessageBox.Show("Berechnung abgeschlossen."); return; } } |
04_Programmsteuerung\05_Methode_Integer
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | using System.Windows.Forms; using Eplan.EplApi.Scripting; public class Class { [DeclareAction("MethodeInt")] public void Function(int INT1, int INT2) { CalcMessageBox(INT1, INT2); FinishedMessageBox2(); return; } private static void CalcMessageBox(int INT1, int INT2) { int intResult = INT1 + INT2; MessageBox.Show(INT1.ToString() + " + " + INT2.ToString() + " = " + intResult.ToString()); return; } private static void FinishedMessageBox2() { MessageBox.Show("Berechnung abgeschlossen."); return; } } |
04_Programmsteuerung\06_Methode_Rückgabewert
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | using System.Windows.Forms; using Eplan.EplApi.Scripting; public class Class { [DeclareAction("MethodeIntRückgabewert")] public void Function(int INT1, int INT2) { //int intResult = Calc(INT1, INT2); int intResult = INT1 + INT2; MessageBox.Show( INT1.ToString() + " + " + INT2.ToString() + " = " + intResult.ToString() ); FinishedMessageBox3(); return; } private static int Calc(int INT1, int INT2) { return INT1 + INT2; } private static void FinishedMessageBox3() { MessageBox.Show("Berechnung abgeschlossen."); return; } } |
04_Programmsteuerung\07_Methoden_Überladungen
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | using System.Windows.Forms; using System.Windows.Forms; using Eplan.EplApi.Scripting; public class Class { [Start] public void Function() { string strMessage = string.Empty; strMessage = DoSomething("Bananen"); MessageBox.Show(strMessage, "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); strMessage = DoSomething("Bananen", "3"); MessageBox.Show(strMessage, "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } /// //summary> /// Gibt einen Wert zurück der den Satz enthält: /// "Ich habe gerade [Food] gegessen!" /// ///summary> ///Nahrungsmittel private static string DoSomething(string Food) { string strFullMessage = "Ich habe gerade " + Food + " gegessen!"; return strFullMessage; } /// /summary> /// Gibt einen Wert zurück der den Satz enthält: /// "Ich habe gerade [Amount] [Food] gegessen!" /// ///summary> ///Nahrungsmittel ///Menge private static string DoSomething(string Food, string Amount) { string strFullMessage = "Ich habe gerade " + Amount + " " + Food + " gegessen!"; return strFullMessage; } } |
05_Settings\01_Verändern_String
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | using System.Windows.Forms; using Eplan.EplApi.Scripting; public class Class { [Start] public void Function() { Eplan.EplApi.Base.Settings oSettings = new Eplan.EplApi.Base.Settings(); oSettings.SetStringSetting( "USER.TrDMProject.UserData.Identification", "TEST", 0 ); MessageBox.Show("Einstellung wurde gesetzt."); return; } } |
05_Settings\02_Verändern_Bool
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | using System.Windows.Forms; using Eplan.EplApi.Scripting; public class Class { [Start] public void Function() { Eplan.EplApi.Base.Settings oSettings = new Eplan.EplApi.Base.Settings(); oSettings.SetBoolSetting( "USER.EnfMVC.ContextMenuSetting.ShowExtended", true, 0 ); MessageBox.Show( "Einstellung wurde aktiviert. EPLAN-Neustart erforderlich." ); return; } } |
05_Settings\03_Verändern_Integer
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | using System.Windows.Forms; using Eplan.EplApi.Scripting; public class Class { [Start] public void Function() { Eplan.EplApi.Base.Settings oSettings = new Eplan.EplApi.Base.Settings(); oSettings.SetNumericSetting( "USER.SYSTEM.GUI.LAST_PROJECTS_COUNT", 11, 0 ); MessageBox.Show("Einstellung wurde gesetzt."); return; } } |
05_Settings\04_Lesen_String
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | using System.Windows.Forms; using Eplan.EplApi.Scripting; public class Class { [Start] public void Function() { Eplan.EplApi.Base.Settings oSettings = new Eplan.EplApi.Base.Settings(); string strName = oSettings.GetStringSetting( "USER.TrDMProject.UserData.Longname", 0 ); MessageBox.Show("Hallo " + strName + "!"); return; } } |
05_Settings\05_Lesen_Bool
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | using System.Windows.Forms; using Eplan.EplApi.Scripting; public class Class { [Start] public void Function() { Eplan.EplApi.Base.Settings oSettings = new Eplan.EplApi.Base.Settings(); bool bolSetting = oSettings.GetBoolSetting( "USER.XUserSettingsGui.UseLoginName", 0 ); if (bolSetting) { MessageBox.Show("Einstellung ist aktiviert."); } else { MessageBox.Show("Einstellung ist deaktiviert."); } return; } } |
05_Settings\06_Lesen_Integer
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | using System.Windows.Forms; using Eplan.EplApi.Scripting; public class Class { [Start] public void Function() { Eplan.EplApi.Base.Settings oSettings = new Eplan.EplApi.Base.Settings(); int intSetting = oSettings.GetNumericSetting( "USER.MF.PREVIEW.MINCOLWIDTH", 0 ); MessageBox.Show("Mindestbreite der Kacheln in der Vorschau: " + intSetting.ToString()); return; } } |
05_Settings\07_Import
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | using System.Windows.Forms; using Eplan.EplApi.Scripting; public class Class { [Start] public void Function() { Eplan.EplApi.Base.Settings oSettings = new Eplan.EplApi.Base.Settings(); oSettings.ReadSettings(@"C:\test\test.xml"); MessageBox.Show("Einstellungen wurden importiert."); return; } } |
05_Settings\08_Import_Projekteinstellung
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | using System; using System.Windows.Forms; using Eplan.EplApi.ApplicationFramework; using Eplan.EplApi.Base; using Eplan.EplApi.Scripting; public class Class { [DeclareAction("Verbindungsabzweigungen")] public void Function(int SET) { try { string strScripts = PathMap.SubstitutePath("$(MD_SCRIPTS)" + @"\"); string strProject = PathMap.SubstitutePath("$(P)"); string strMessage = string.Empty; CommandLineInterpreter oCLI = new CommandLineInterpreter(); ActionCallingContext acc = new ActionCallingContext(); acc.AddParameter("Project", strProject); switch (SET) { case 1: strMessage = "[Wie gezeichnet]"; acc.AddParameter("XMLFile", strScripts + @"1.xml"); break; case 2: strMessage = "[Als Punkt]"; acc.AddParameter("XMLFile", strScripts + @"2.xml"); break; case 3: strMessage = "[Mit Zielfestlegung]"; acc.AddParameter("XMLFile", strScripts + @"3.xml"); break; default: MessageBox.Show("Parameter nicht bekannt", "Fehler", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } oCLI.Execute("XSettingsImport", acc); MessageBox.Show("Einstellungen wurden importiert.\n" + strMessage, "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show(ex.Message, "Fehler", MessageBoxButtons.OK, MessageBoxIcon.Error); } return; } } |
06_Menüs\01_Menüpunkt_in_Dienstprogramme
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | using System.Windows.Forms; using Eplan.EplApi.Scripting; public class Class { [DeclareAction("MenuAction")] public void ActionFunction() { MessageBox.Show("Action wurde ausgeführt!"); return; } [DeclareMenu] public void MenuFunction() { Eplan.EplApi.Gui.Menu oMenu = new Eplan.EplApi.Gui.Menu(); oMenu.AddMenuItem( "Menüpunkt am Ende von Dienstprogramme", // Name: Menüpunkt "MenuAction" // Name: Action ); return; } } |
06_Menüs\02_Bestehendes_Menü_erweitern
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | using System.Windows.Forms; using Eplan.EplApi.Scripting; public class Class { [DeclareAction("MenuAction")] public void ActionFunction() { MessageBox.Show("Action wurde ausgeführt!"); return; } [DeclareMenu] public void MenuFunction() { Eplan.EplApi.Gui.Menu oMenu = new Eplan.EplApi.Gui.Menu(); oMenu.AddMenuItem( "Bestehendes Menü erweitern", // Name: Menüpunkt "MenuAction", // Name: Action "Statustext", // Statustext 37024, // Menü-ID: Einfügen/Fenstermakro... 1, // 1 = hinter Menüpunkt, 0 = vor Menüpunkt false, // Separator davor anzeigen false // Separator dahinter anzeigen ); return; } } |
06_Menüs\03_Hauptmenü_mit_Untermenüpunkt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | using System.Windows.Forms; using Eplan.EplApi.Scripting; public class Class { [DeclareAction("MenuAction")] public void ActionFunction() { MessageBox.Show("Action wurde ausgeführt!"); return; } [DeclareMenu] public void MenuFunction() { Eplan.EplApi.Gui.Menu oMenu = new Eplan.EplApi.Gui.Menu(); oMenu.AddMainMenu( "Menü 1", // Name: Menü "Hilfe", // neben Menüpunkt "Hauptmenü mit einem Menüpunkt", // Name: Menüpunkt "MenuAction", // Name: Action "Statustext", // Statustext 1 // 1 = hinter Menüpunkt, 0 = vor Menüpunkt ); return; } } |
06_Menüs\04_Bestehendes_Menü_mit_Popup-Menü_erweitern
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | using System.Windows.Forms; using Eplan.EplApi.Scripting; public class Class { [DeclareAction("MenuAction")] public void ActionFunction() { MessageBox.Show("Action wurde ausgeführt!"); return; } [DeclareMenu] public void MenuFunction() { Eplan.EplApi.Gui.Menu oMenu = new Eplan.EplApi.Gui.Menu(); oMenu.AddPopupMenuItem( "Bestehendes Menü erweitern...", // Name: Menü "mit Popup-Menü", // Name: Menüpunkt "MenuAction", // Name: Action "Statustext", // Statustext 37024, // Menü-ID: Einfügen/Fenstermakro... 0, // 1 = hinter Menüpunkt, 0 = vor Menüpunkt false, // Separator davor anzeigen false // Separator dahinter anzeigen ); return; } } |
06_Menüs\05_Hauptmenü_mit_Popup-Menü
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | using System.Windows.Forms; using Eplan.EplApi.Scripting; public class Class { [DeclareAction("MenuAction")] public void ActionFunction() { MessageBox.Show("Action wurde ausgeführt!"); return; } [DeclareMenu] public void MenuFunction() { Eplan.EplApi.Gui.Menu oMenu = new Eplan.EplApi.Gui.Menu(); uint MenuID = new uint(); // Menü-ID vom neu erzeugten Menü MenuID = oMenu.AddMainMenu( // Festlegen der Menü-ID des Objekts "Menü 2", // Name: Menü "Hilfe", // neben Menüpunkt "Hauptmenü mit einem Menüpunkt", // Name: Menüpunkt "MenuAction", // Name: Action "Statustext", // Statustext 1 // 1 = hinter Menüpunkt, 0 = vor Menüpunkt ); oMenu.AddPopupMenuItem( "Popup-Menü mit...", // Name: Menü "Unterpunkt", // Name: Menüpunkt "MenuAction", // Name: Action "Statustext", // Statustext MenuID, // Menü-ID 1, // 1 = hinter Menüpunkt, 0 = vor Menüpunkt true, // Separator davor anzeigen false // Separator dahinter anzeigen ); return; } } |
06_Menüs\06_Menüpunkt_in_Kontextmenü
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | using System.Windows.Forms; using Eplan.EplApi.Scripting; public class Class { [DeclareAction("MenuAction")] public void ActionFunction() { MessageBox.Show("Action wurde ausgeführt!"); return; } [DeclareMenu] public void MenuFunction() { Eplan.EplApi.Gui.ContextMenu oMenu = new Eplan.EplApi.Gui.ContextMenu(); Eplan.EplApi.Gui.ContextMenuLocation oLocation = new Eplan.EplApi.Gui.ContextMenuLocation( "GedEditGuiText", "1002" ); oMenu.AddMenuItem( oLocation, "Menüpunkt in Kontextmenü", "MenuAction", true, false ); return; } } |
06_Menüs\07_Kontextmenü_ID
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | using System.Windows.Forms; using Eplan.EplApi.Scripting; public class Class { [DeclareRegister] public void Register() { Eplan.EplApi.Base.Settings oSettings = new Eplan.EplApi.Base.Settings(); oSettings.SetBoolSetting( "USER.EnfMVC.ContextMenuSetting.ShowIdentifier", true, 0 ); MessageBox.Show("Kontextmenü-ID: sichtbar"); return; } [DeclareUnregister] public void UnRegister() { Eplan.EplApi.Base.Settings oSettings = new Eplan.EplApi.Base.Settings(); oSettings.SetBoolSetting( "USER.EnfMVC.ContextMenuSetting.ShowIdentifier", false, 0 ); MessageBox.Show("Kontextmenü-ID: unsichtbar"); return; } } |
07_Progressbar\01_SimpleProgress
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | using Eplan.EplApi.Base; using Eplan.EplApi.Scripting; using System.Threading; public class Class { [Start] public void Function() { Progress oProgress = new Progress("SimpleProgress"); oProgress.SetAllowCancel(true); oProgress.SetAskOnCancel(true); oProgress.SetNeededSteps(3); oProgress.SetTitle("Meine Progressbar"); oProgress.ShowImmediately(); if (!oProgress.Canceled()) { oProgress.SetActionText("Step 1"); oProgress.SetTitle("Titelzeile 1"); oProgress.Step(1); Thread.Sleep(1000); } if (!oProgress.Canceled()) { oProgress.SetActionText("Step 2"); oProgress.SetTitle("Titelzeile 2"); oProgress.Step(1); Thread.Sleep(1000); } if (!oProgress.Canceled()) { oProgress.SetActionText("Step 3"); oProgress.SetTitle("Titelzeile 3"); oProgress.Step(1); Thread.Sleep(1000); } oProgress.EndPart(true); return; } } |
07_Progressbar\02_EnhancedProgress
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | using Eplan.EplApi.ApplicationFramework; using Eplan.EplApi.Base; using Eplan.EplApi.Scripting; public class Class { [Start] public void Function() { CommandLineInterpreter oCLI = new CommandLineInterpreter(); Progress oProgress = new Progress("EnhancedProgress"); oProgress.SetAllowCancel(false); oProgress.ShowImmediately(); oProgress.BeginPart(33, "Part 1"); oCLI.Execute("generate /TYPE:CONNECTIONS"); oProgress.EndPart(); oProgress.BeginPart(33, "Part 2"); oCLI.Execute("reports"); oProgress.EndPart(); oProgress.BeginPart(33, "Part 3"); oCLI.Execute("compress /FILTERSCHEME:Standard"); oProgress.EndPart(); oProgress.EndPart(true); return; } } |
08_Formulare\01_Vorlage
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | using System.Windows.Forms; using Eplan.EplApi.Scripting; public partial class frmVorlage : System.Windows.Forms.Form { #region Vom Windows Form-Designer generierter Code /// //summary> /// Erforderliche Designervariable. /////summary> private System.ComponentModel.IContainer components = null; /// //summary> /// Verwendete Ressourcen bereinigen. /// ///True, wenn verwaltete Ressourcen /// gelöscht werden sollen; andernfalls False.protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } /// //summary> /// Erforderliche Methode für die Designerunterstützung. /// Der Inhalt der Methode darf nicht mit dem Code-Editor /// geändert werden. /// private void InitializeComponent() { this.SuspendLayout(); // // frmVorlage // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(292, 273); this.Name = "frmVorlage"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "Vorlage"; this.ResumeLayout(false); } public frmVorlage() { InitializeComponent(); } #endregion [Start] public void Function() { frmVorlage frm = new frmVorlage(); frm.ShowDialog(); return; } } |
08_Formulare\02_Formularbeispiel
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | using System.Windows.Forms; using System.Windows.Forms; using Eplan.EplApi.ApplicationFramework; using Eplan.EplApi.Base; using Eplan.EplApi.Scripting; public partial class frmButton : System.Windows.Forms.Form { private Button btnCancel; private Button btnOk; private CheckBox chkProjectcheck; private CheckBox chkReport; private CheckBox chkCheckall; private Label lblProject; private ProgressBar pbr; #region Vom Windows Form-Designer generierter Code ///True, wenn verwaltete Ressourcen /// gelöscht werden sollen; andernfalls False.protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } /// |
08_Formulare\03_Cursor
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | using Eplan.EplApi.Base; using Eplan.EplApi.Scripting; using System.Threading; using System.Windows.Forms; public class Class { [Start] public void Function() { Cursor.Current = Cursors.AppStarting; Thread.Sleep(3000); Cursor.Current = Cursors.WaitCursor; Thread.Sleep(3000); return; } } |
08_Formulare\04_Projektsuche
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 | using System; using System.IO; using System.Windows.Forms; using Eplan.EplApi.ApplicationFramework; using Eplan.EplApi.Base; using Eplan.EplApi.Scripting; public class FrmProjektsuche : System.Windows.Forms.Form { public string strProjects = string.Empty; #region Formular public FrmProjektsuche() { InitializeComponent(); } private System.Windows.Forms.Button btnOK; private System.Windows.Forms.Button btnOpenProject; private System.Windows.Forms.ListView liviResult; private System.Windows.Forms.ColumnHeader columnHeader1; private System.Windows.Forms.ColumnHeader columnHeader2; private System.Windows.Forms.ColumnHeader columnHeader3; private System.Windows.Forms.Button btnSearch; private System.Windows.Forms.TextBox txtSearch; private System.Windows.Forms.StatusStrip st; private System.Windows.Forms.Button btnCancel; private System.Windows.Forms.ToolStripStatusLabel lbl; /// /// Erforderliche Designervariable. /// private System.ComponentModel.IContainer components = null; /// /// Verwendete Ressourcen bereinigen. /// /// True, wenn verwaltete Ressourcen gelöscht werden sollen; andernfalls False. protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } /// /// Erforderliche Methode für die Designerunterstützung. /// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden. /// private void InitializeComponent() { this.btnOK = new System.Windows.Forms.Button(); this.btnOpenProject = new System.Windows.Forms.Button(); this.liviResult = new System.Windows.Forms.ListView(); this.columnHeader1 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.columnHeader2 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.columnHeader3 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.btnSearch = new System.Windows.Forms.Button(); this.txtSearch = new System.Windows.Forms.TextBox(); this.st = new System.Windows.Forms.StatusStrip(); this.lbl = new System.Windows.Forms.ToolStripStatusLabel(); this.btnCancel = new System.Windows.Forms.Button(); this.st.SuspendLayout(); this.SuspendLayout(); // // btnOK // this.btnOK.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.btnOK.Location = new System.Drawing.Point(474, 274); this.btnOK.Name = "btnOK"; this.btnOK.Size = new System.Drawing.Size(75, 23); this.btnOK.TabIndex = 6; this.btnOK.Text = "OK"; this.btnOK.UseVisualStyleBackColor = true; this.btnOK.Click += new System.EventHandler(this.btnOK_Click); // // btnOpenProject // this.btnOpenProject.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.btnOpenProject.Location = new System.Drawing.Point(606, 9); this.btnOpenProject.Name = "btnOpenProject"; this.btnOpenProject.Size = new System.Drawing.Size(24, 23); this.btnOpenProject.TabIndex = 11; this.btnOpenProject.Text = "..."; this.btnOpenProject.UseVisualStyleBackColor = true; this.btnOpenProject.Click += new System.EventHandler(this.btnOpenProject_Click); // // liviResult // this.liviResult.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.liviResult.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { this.columnHeader1, this.columnHeader2, this.columnHeader3}); this.liviResult.FullRowSelect = true; this.liviResult.GridLines = true; this.liviResult.HideSelection = false; this.liviResult.Location = new System.Drawing.Point(12, 39); this.liviResult.Name = "liviResult"; this.liviResult.Size = new System.Drawing.Size(618, 229); this.liviResult.Sorting = System.Windows.Forms.SortOrder.Ascending; this.liviResult.TabIndex = 10; this.liviResult.UseCompatibleStateImageBehavior = false; this.liviResult.View = System.Windows.Forms.View.Details; this.liviResult.DoubleClick += new System.EventHandler(this.liviResult_DoubleClick); // // columnHeader1 // this.columnHeader1.Text = "Projektname"; this.columnHeader1.Width = 76; // // columnHeader2 // this.columnHeader2.Text = "Pfad"; this.columnHeader2.Width = 89; // // columnHeader3 // this.columnHeader3.Text = "Erweiterung"; this.columnHeader3.Width = 223; // // btnSearch // this.btnSearch.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.btnSearch.Enabled = false; this.btnSearch.Location = new System.Drawing.Point(525, 9); this.btnSearch.Name = "btnSearch"; this.btnSearch.Size = new System.Drawing.Size(75, 23); this.btnSearch.TabIndex = 9; this.btnSearch.Text = "Suchen"; this.btnSearch.UseVisualStyleBackColor = true; this.btnSearch.Click += new System.EventHandler(this.btnSearch_Click); // // txtSearch // this.txtSearch.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.txtSearch.Location = new System.Drawing.Point(12, 11); this.txtSearch.Name = "txtSearch"; this.txtSearch.Size = new System.Drawing.Size(507, 20); this.txtSearch.TabIndex = 8; this.txtSearch.TextChanged += new System.EventHandler(this.txtSearch_TextChanged); // // st // this.st.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.lbl}); this.st.Location = new System.Drawing.Point(0, 301); this.st.Name = "st"; this.st.Size = new System.Drawing.Size(642, 22); this.st.TabIndex = 13; this.st.Text = "statusStrip1"; // // lbl // this.lbl.Name = "lbl"; this.lbl.Size = new System.Drawing.Size(627, 17); this.lbl.Spring = true; this.lbl.Text = "Suchbegriff eingeben..."; this.lbl.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; // // btnCancel // this.btnCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.btnCancel.Location = new System.Drawing.Point(555, 274); this.btnCancel.Name = "btnCancel"; this.btnCancel.Size = new System.Drawing.Size(75, 23); this.btnCancel.TabIndex = 15; this.btnCancel.Text = "Abbrechen"; this.btnCancel.UseVisualStyleBackColor = true; this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click); // // FrmProjektsuche // this.AcceptButton = this.btnSearch; this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.BackColor = System.Drawing.SystemColors.Control; this.ClientSize = new System.Drawing.Size(642, 323); this.Controls.Add(this.btnCancel); this.Controls.Add(this.st); this.Controls.Add(this.btnOpenProject); this.Controls.Add(this.liviResult); this.Controls.Add(this.btnSearch); this.Controls.Add(this.txtSearch); this.Controls.Add(this.btnOK); this.MaximizeBox = false; this.MinimizeBox = false; this.MinimumSize = new System.Drawing.Size(450, 200); this.Name = "FrmProjektsuche"; this.ShowIcon = false; this.ShowInTaskbar = false; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "Projektsuche"; this.Load += new System.EventHandler(this.FrmProjektsuche_Load); this.st.ResumeLayout(false); this.st.PerformLayout(); this.ResumeLayout(false); this.PerformLayout(); } #endregion [DeclareMenu] public void MenuFunction() { Eplan.EplApi.Gui.Menu oMenu = new Eplan.EplApi.Gui.Menu(); oMenu.AddMenuItem ( "Projektsuche...", "SearchProjects", "Projekt(e) suchen und öffnen", 35002, 1, false, false ); return; } [DeclareAction("SearchProjects")] public void SearchMacrosVoid() { FrmProjektsuche frm = new FrmProjektsuche(); frm.StartPosition = FormStartPosition.CenterScreen; frm.ShowDialog(); return; } private void FrmProjektsuche_Load(object sender, System.EventArgs e) { strProjects = PathMap.SubstitutePath("$(MD_PROJECTS)"); txtSearch.Select(); return; } private void btnCancel_Click(object sender, System.EventArgs e) { Close(); return; } private void btnOpenProject_Click(object sender, System.EventArgs e) { OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "Projektdatei (*.el*)|*.el*|Alle Dateien anzeigen|*.*"; ofd.InitialDirectory = strProjects; if (ofd.ShowDialog() == DialogResult.OK) { Eplan_OpenProject(ofd.FileName); this.Close(); } return; } private void Eplan_OpenProject(string FullProjectPath) { Cursor.Current = Cursors.WaitCursor; lbl.Text = "Projekt '" + Path.GetFileNameWithoutExtension(FullProjectPath) + "' wird geöffnet..."; this.Update(); CommandLineInterpreter oCli = new CommandLineInterpreter(); ActionCallingContext acc = new ActionCallingContext(); acc.AddParameter("Project", FullProjectPath); oCli.Execute("ProjectOpen", acc); Cursor.Current = Cursors.Default; return; } private void btnSearch_Click(object sender, System.EventArgs e) { Cursor.Current = Cursors.WaitCursor; lbl.Text = "Projekt(e) werden gesucht..."; liviResult.BeginUpdate(); GetProjects(); liviResult.AutoResizeColumns( ColumnHeaderAutoResizeStyle.ColumnContent); liviResult.EndUpdate(); Cursor.Current = Cursors.Default; return; } private void GetProjects() { liviResult.Items.Clear(); string[] result = Directory.GetFiles( strProjects, "*" + txtSearch.Text + "*.el*", SearchOption.TopDirectoryOnly ); foreach (string project in result) { FillListView(project); } lbl.Text = "Projekte gefunden: " + liviResult.Items.Count.ToString(); return; } private void FillListView(string Fullpath) { FileInfo fi = new FileInfo(Fullpath); string FileNameWithoutExtension = Path.GetFileNameWithoutExtension(fi.FullName); string Directory = fi.Directory.ToString() + @"\"; string Extension = fi.Extension.ToString(); ListViewItem liviItem = new ListViewItem(); liviItem.Text = FileNameWithoutExtension; liviItem.SubItems.Add(Directory); liviItem.SubItems.Add(Extension); liviResult.Items.Add(liviItem); return; } private void btnOK_Click(object sender, System.EventArgs e) { GetFileNameAndOpen(); return; } private void liviResult_DoubleClick(object sender, EventArgs e) { GetFileNameAndOpen(); return; } private void GetFileNameAndOpen() { if (liviResult.SelectedItems.Count > 0) { string project = liviResult.SelectedItems[0].SubItems[1].Text + liviResult.SelectedItems[0].SubItems[0].Text + liviResult.SelectedItems[0].SubItems[2].Text; Eplan_OpenProject(project); } this.Close(); return; } private void txtSearch_TextChanged(object sender, System.EventArgs e) { if (txtSearch.Text == "") { btnSearch.Enabled = false; } else { btnSearch.Enabled = true; } return; } } |
09_Externe_Programme\01_Prozess_ausführen
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | using System; using System.Diagnostics; // Zusätzlich using System.Windows.Forms; using Eplan.EplApi.Scripting; public class Class { [Start] public void Function() { try { Process.Start("calc"); } catch (Exception ex) { MessageBox.Show( ex.Message, "Fehler", MessageBoxButtons.OK, MessageBoxIcon.Error ); } return; } } |
09_Externe_Programme\02_Unterschiedliche_Prozesse_ausführen
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | using System; using System.Diagnostics; // Zusätzlich using System.Windows.Forms; using Eplan.EplApi.Base; using Eplan.EplApi.Scripting; public class Class { [DeclareAction("StartProcess")] public void Function(string PROCESS, string PARAMETER) { try { Process.Start(PROCESS, PARAMETER); } catch (Exception ex) { MessageBox.Show( ex.Message, "Fehler", MessageBoxButtons.OK, MessageBoxIcon.Error ); } return; } [DeclareMenu] public void MenuFunction() { Eplan.EplApi.Gui.Menu oMenu = new Eplan.EplApi.Gui.Menu(); string strProjectpath = PathMap.SubstitutePath("$(PROJECTPATH)"); string strPdfExample = @"C:\test\test.pdf"; string quote = "\""; uint MenuID = new uint(); // Menü-ID vom neu erzeugten Menü MenuID = oMenu.AddMainMenu( "Externe Programme", // Name: Menü "Hilfe", // neben Menüpunkt "Taschenrechner", // Name: Menüpunkt "StartProcess /PROCESS:calc /PARAMETER:''", // Name: Action "Taschenrechner öffnen...", // Statustext 1 // 1 = Hinter Menüpunkt, 0 = Vor Menüpunkt ); MenuID = oMenu.AddMenuItem( "Projektordner öffnen", // Name: Menüpunkt "StartProcess /PROCESS:explorer /PARAMETER:" + quote + strProjectpath + quote, // Name: Action "Projektordner im Explorer öffnen...", // Statustext MenuID, // Menü-ID: Einfügen/Fenstermakro... 1, // 1 = Hinter Menüpunkt, 0 = Vor Menüpunkt false, // Separator davor anzeigen false // Separator dahinter anzeigen ); MenuID = oMenu.AddMenuItem( "Zeichentabelle", // Name: Menüpunkt "StartProcess /PROCESS:charmap /PARAMETER:''", // Name: Action "Zeichentabelle öffnen...", // Statustext MenuID, // Menü-ID: Einfügen/Fenstermakro... 1, // 1 = Hinter Menüpunkt, 0 = Vor Menüpunkt false, // Separator davor anzeigen false // Separator dahinter anzeigen ); MenuID = oMenu.AddMenuItem( "PDF öffnen", // Name: Menüpunkt "StartProcess /PROCESS:" + quote + strPdfExample + quote + " /PARAMETER:''", // Name: Action "Beispiel PDF öffnen...", // Statustext MenuID, // Menü-ID: Einfügen/Fenstermakro... 1, // 1 = Hinter Menüpunkt, 0 = Vor Menüpunkt false, // Separator davor anzeigen false // Separator dahinter anzeigen ); return; } } |
10_Dateien_und_Ordner\01_Ordner_prüfen
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | using System.IO; using System.Windows.Forms; using Eplan.EplApi.Scripting; public class Class { [Start] public void Function() { string strDirName = @"C:\test\"; if (Directory.Exists(strDirName)) { MessageBox.Show("Ordner schon vorhanden."); } else { Directory.CreateDirectory(strDirName); MessageBox.Show("Ordner erstellt."); } return; } } |
10_Dateien_und_Ordner\02_Datei_prüfen
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | using System.IO; using System.Windows.Forms; using Eplan.EplApi.Scripting; public class Class { [Start] public void Function() { string strFilename = @"C:\test\test.txt"; if (File.Exists(strFilename)) { MessageBox.Show("Datei schon vorhanden."); } else { File.Create(strFilename); MessageBox.Show("Datei erstellt."); } return; } } |
10_Dateien_und_Ordner\03_Datei_löschen
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | using System.IO; using System.Windows.Forms; using Eplan.EplApi.Scripting; public class Class { [Start] public void Function() { string strFilename = @"C:\test\test.txt"; if (File.Exists(strFilename)) { File.Delete(strFilename); MessageBox.Show("Datei gelöscht"); } return; } } |
10_Dateien_und_Ordner\04_Datei_mit_Datumstempel
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | using System; using System.IO; using System.Windows.Forms; using Eplan.EplApi.Scripting; public class Class { [Start] public void Function() { string strDate = DateTime.Now.ToString("yyyy-MM-dd"); string strTime = DateTime.Now.ToString("HH-mm-ss"); string strFilename = @"C:\test\test_" + strDate + "_" + strTime + ".txt"; File.Create(strFilename); MessageBox.Show("Datei erstellt."); return; } } |
11_Dateien_öffnen_speichern\01_SaveFileDialog
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | using System.IO; using System.Windows.Forms; using Eplan.EplApi.Base; using Eplan.EplApi.Scripting; public class Class { [Start] public void Function() { string strProjectpath = PathMap.SubstitutePath("$(PROJECTPATH)") + @"\"; string strFilename = "Testdatei"; SaveFileDialog sfd = new SaveFileDialog(); sfd.DefaultExt = "txt"; sfd.FileName = strFilename; sfd.Filter = "Textdatei (*.txt)|*.txt"; sfd.InitialDirectory = strProjectpath; sfd.Title = "Speicherort für Testdatei wählen:"; sfd.ValidateNames = true; if (sfd.ShowDialog() == DialogResult.OK) { File.Create(sfd.FileName); MessageBox.Show( "Datei wurde erfolgreich gespeichert:\n" + sfd.FileName, "Information", MessageBoxButtons.OK, MessageBoxIcon.Information ); } return; } } |
11_Dateien_öffnen_speichern\02_OpenFileDialog
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | using System.IO; using System.Windows.Forms; using Eplan.EplApi.Base; using Eplan.EplApi.Scripting; public class Class { [Start] public void Function() { string strProjectpath = PathMap.SubstitutePath("$(PROJECTPATH)") + @"\"; string strFilename = "Testdatei"; OpenFileDialog ofd = new OpenFileDialog(); ofd.DefaultExt = "txt"; ofd.FileName = strFilename; ofd.Filter = "Testdatei (*Testdatei*.txt)" + "|*Testdatei*.txt|Alle Dateien (*.*)|*.*"; ofd.InitialDirectory = strProjectpath; ofd.Title = "Testdatei auswählen:"; ofd.ValidateNames = true; if (ofd.ShowDialog() == DialogResult.OK) { strFilename = ofd.FileName; MessageBox.Show( "Der Speicherort wurde erfolgreich übergeben:\n" + strFilename, "Information", MessageBoxButtons.OK, MessageBoxIcon.Information ); } return; } } |
11_Dateien_öffnen_speichern\03_Dateinamen_prüfen
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | using System.Windows.Forms; using Eplan.EplApi.Base; using Eplan.EplApi.Scripting; public class Class { [Start] public void Function() { string strChars = @"[\\/:*?""<>|]"; MessageBox.Show("Diese Zeichen werden umgewandelt:\n" + strChars, "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); strChars = AdjustPath(strChars); MessageBox.Show(strChars, "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } private string AdjustPath(string Input) { return System.Text.RegularExpressions.Regex.Replace( Input, @"[\\/:*?""<>|]", "-"); } } |
12_Dateien_schreiben\01_Beschriftung
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | using Eplan.EplApi.ApplicationFramework; using Eplan.EplApi.Base; using Eplan.EplApi.Scripting; public class Class { [Start] public void Function() { string strProjectpath = PathMap.SubstitutePath("$(PROJECTPATH)" + @"\"); Progress progress = new Progress("SimpleProgress"); progress.BeginPart(100, ""); progress.SetAllowCancel(true); if (!progress.Canceled()) { progress.BeginPart(50, "Artikelsummenstückliste wird erstellt..."); ActionCallingContext labellingContext = new ActionCallingContext(); labellingContext.AddParameter("CONFIGSCHEME", "Summarized parts list"); labellingContext.AddParameter("DESTINATIONFILE", strProjectpath + "Artikelsummenstückliste.xls"); labellingContext.AddParameter("FILTERSCHEME", ""); labellingContext.AddParameter("LANGUAGE", "de_DE"); labellingContext.AddParameter("LogMsgActionDone", "true"); labellingContext.AddParameter("SHOWOUTPUT", "1"); labellingContext.AddParameter("RECREPEAT", "1"); labellingContext.AddParameter("SORTSCHEME", ""); labellingContext.AddParameter("TASKREPEAT", "1"); new CommandLineInterpreter().Execute("label", labellingContext); progress.EndPart(); } if (!progress.Canceled()) { progress.BeginPart(50, "Betriebsmittelbeschriftung wird erstellt..."); ActionCallingContext labellingContext1 = new ActionCallingContext(); labellingContext1.AddParameter("CONFIGSCHEME", "Device tag list"); labellingContext1.AddParameter("DESTINATIONFILE", strProjectpath + "Betriebsmittelbeschriftung.xls"); labellingContext1.AddParameter("FILTERSCHEME", ""); labellingContext1.AddParameter("LANGUAGE", "de_DE"); labellingContext1.AddParameter("LogMsgActionDone", "true"); labellingContext1.AddParameter("SHOWOUTPUT", "1"); labellingContext1.AddParameter("RECREPEAT", "1"); labellingContext1.AddParameter("SORTSCHEME", ""); labellingContext1.AddParameter("TASKREPEAT", "1"); new CommandLineInterpreter().Execute("label", labellingContext1); progress.EndPart(); } progress.EndPart(true); return; } } |
12_Dateien_schreiben\02_Beschriftung_mit_Überprüfung
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 | using System.IO; using System.Windows.Forms; using Eplan.EplApi.ApplicationFramework; using Eplan.EplApi.Base; using Eplan.EplApi.Scripting; public class Class { [Start] public void Function() { string strFilename = string.Empty; strFilename = CheckFilename("Artikelsummenstückliste.xls"); if (strFilename != "") { ActionCallingContext labellingContext = new ActionCallingContext(); labellingContext.AddParameter("CONFIGSCHEME", "Summarized parts list"); labellingContext.AddParameter("DESTINATIONFILE", strFilename); labellingContext.AddParameter("FILTERSCHEME", ""); labellingContext.AddParameter("LANGUAGE", "de_DE"); labellingContext.AddParameter("LogMsgActionDone", "true"); labellingContext.AddParameter("SHOWOUTPUT", "1"); labellingContext.AddParameter("RECREPEAT", "1"); labellingContext.AddParameter("SORTSCHEME", ""); labellingContext.AddParameter("TASKREPEAT", "1"); new CommandLineInterpreter().Execute("label", labellingContext); } strFilename = CheckFilename("Betriebsmittelbeschriftung.xls"); if (strFilename != "") { ActionCallingContext labellingContext1 = new ActionCallingContext(); labellingContext1.AddParameter("CONFIGSCHEME", "Device tag list"); labellingContext1.AddParameter("DESTINATIONFILE", strFilename); labellingContext1.AddParameter("FILTERSCHEME", ""); labellingContext1.AddParameter("LANGUAGE", "de_DE"); labellingContext1.AddParameter("LogMsgActionDone", "true"); labellingContext1.AddParameter("SHOWOUTPUT", "1"); labellingContext1.AddParameter("RECREPEAT", "1"); labellingContext1.AddParameter("SORTSCHEME", ""); labellingContext1.AddParameter("TASKREPEAT", "1"); new CommandLineInterpreter().Execute("label", labellingContext1); } return; } private static string CheckFilename(string strType) { string strProjectpath = PathMap.SubstitutePath("$(PROJECTPATH)" + @"\"); string strFilename = strProjectpath + strType; if (File.Exists(strFilename)) { DialogResult Result = MessageBox.Show( "Die Datei\n'" + strFilename + "'\nexistiert bereits.\n" + "Wollen Sie die Datei überschreiben?", "Beschriftung", MessageBoxButtons.YesNo, MessageBoxIcon.Question ); if (Result == DialogResult.No) { SaveFileDialog sfd = new SaveFileDialog(); sfd.DefaultExt = "xls"; sfd.FileName = strType; sfd.Filter = "Excel-Datei (*.xls)|*.xls"; sfd.InitialDirectory = strProjectpath; sfd.Title = "Speicherort für " + strType + " wählen:"; sfd.ValidateNames = true; DialogResult ResultSfd = sfd.ShowDialog(); if (ResultSfd == DialogResult.OK) { strFilename = sfd.FileName; } else if (ResultSfd == DialogResult.Cancel) { strFilename = ""; } } } return strFilename; } } |
12_Dateien_schreiben\03_PDF_beim_Schließen_erzeugen
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | using System.Windows.Forms; using Eplan.EplApi.ApplicationFramework; using Eplan.EplApi.Base; using Eplan.EplApi.Scripting; public class Class { [DeclareEventHandler("Eplan.EplApi.OnUserPreCloseProject")] public void Function() { string strFullProjectname = PathMap.SubstitutePath("$(P)"); string strProjectpath = PathMap.SubstitutePath("$(PROJECTPATH)" + @"\"); string strProjectname = PathMap.SubstitutePath("$(PROJECTNAME)"); DialogResult Result = MessageBox.Show( "Soll ein PDF für das Projekt\n'" + strProjectname + "'\nerzeugt werden?", "PDF-Export", MessageBoxButtons.YesNo, MessageBoxIcon.Question ); if (Result == DialogResult.Yes) { Progress oProgress = new Progress("SimpleProgress"); oProgress.SetAllowCancel(true); oProgress.SetAskOnCancel(true); oProgress.BeginPart(100, ""); oProgress.ShowImmediately(); CommandLineInterpreter oCLI = new CommandLineInterpreter(); ActionCallingContext acc = new ActionCallingContext(); acc.AddParameter("TYPE", "PDFPROJECTSCHEME"); acc.AddParameter("PROJECTNAME", strFullProjectname); acc.AddParameter("EXPORTFILE", strProjectpath + strProjectname); acc.AddParameter("EXPORTSCHEME", "EPLAN_default_value"); oCLI.Execute("export", acc); oProgress.EndPart(true); } return; } } |
12_Dateien_schreiben\04_Textdatei_schreiben
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | using System.Diagnostics; using System.IO; using System.Text; using System.Windows.Forms; using Eplan.EplApi.Base; using Eplan.EplApi.Scripting; public class Class { [Start] public void Function() { string filename = PathMap.SubstitutePath(@"$(PROJECTPATH)\Testdatei.txt"); string strContent = "Beispieltext\n"; StreamWriter swTextfile = new StreamWriter( filename, true, Encoding.Unicode ); swTextfile.Write(strContent); swTextfile.Close(); MessageBox.Show( "Textdatei erfolgreich exportiert.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information ); Process.Start(filename); return; } } |
12_Dateien_schreiben\05_XML-Datei_schreiben
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | using System.Diagnostics; using System.Windows.Forms; using System.Xml; using Eplan.EplApi.Base; using Eplan.EplApi.Scripting; public class Class { [Start] public void Function() { string filename = PathMap.SubstitutePath(@"$(PROJECTPATH)\Testdatei.xml"); XmlWriterSettings xs = new XmlWriterSettings(); xs.Indent = true; xs.IndentChars = "\t"; XmlWriter xw = XmlWriter.Create(filename, xs); xw.WriteStartDocument(); // Personen: Start xw.WriteStartElement("Personen"); // Person 1 xw.WriteStartElement("Person"); xw.WriteElementString("Vorname", "Max"); xw.WriteElementString("Nachname", "Mustermann"); xw.WriteStartElement("Adresse"); xw.WriteAttributeString("Ort", "München"); xw.WriteAttributeString("Straße", "Musterstraße 1"); xw.WriteEndElement(); xw.WriteEndElement(); // Person 2 xw.WriteStartElement("Person"); xw.WriteElementString("Vorname", "Maria"); xw.WriteElementString("Nachname", "Musterfrau"); xw.WriteStartElement("Adresse"); xw.WriteAttributeString("Ort", "München"); xw.WriteAttributeString("Straße", "Musterstraße 2"); xw.WriteEndElement(); xw.WriteEndElement(); // Personen: Ende xw.WriteEndElement(); xw.WriteEndDocument(); xw.Close(); MessageBox.Show( "XML-Datei erfolgreich exportiert.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information ); Process.Start(filename); return; } } |
13_Dateien_lesen\01_Textdatei_lesen
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | using System.IO; using System.Text; using System.Windows.Forms; using Eplan.EplApi.ApplicationFramework; using Eplan.EplApi.Base; using Eplan.EplApi.Scripting; public class Class { [Start] public void Function() { string filename = PathMap.SubstitutePath(@"$(TMP)\Last_Version.txt"); LabellingText(filename); string LastVersion = ReadLine(filename, 1); MessageBox.Show( "Zuletzt verwendete EPLAN-Version:\n" + LastVersion, "Information", MessageBoxButtons.OK, MessageBoxIcon.Information ); File.Delete(filename); return; } public string ReadLine(string strFilename, int intLine) { string strContent = ""; float fRow = 0; StreamReader srTextfile = new StreamReader( strFilename, Encoding.Unicode); while (!srTextfile.EndOfStream && fRow < intLine) { fRow += 1; strContent = srTextfile.ReadLine(); } if (fRow < intLine) { strContent = ""; } srTextfile.Close(); return strContent; } private static void LabellingText(string filename) { ActionCallingContext acc = new ActionCallingContext(); acc.AddParameter("CONFIGSCHEME", "Zuletzt verwendete EPLAN-Version_Textdatei"); acc.AddParameter("DESTINATIONFILE", filename); acc.AddParameter("FILTERSCHEME", ""); acc.AddParameter("LANGUAGE", "de_DE"); acc.AddParameter("LogMsgActionDone", "true"); acc.AddParameter("SHOWOUTPUT", "0"); acc.AddParameter("RECREPEAT", "1"); acc.AddParameter("SORTSCHEME", ""); acc.AddParameter("TASKREPEAT", "1"); new CommandLineInterpreter().Execute("label", acc); return; } } |
13_Dateien_lesen\02_XML-Datei_lesen
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | using System.Windows.Forms; using System.Xml; using Eplan.EplApi.Base; using Eplan.EplApi.Scripting; public class Class { [Start] public void Function() { string filename = PathMap.SubstitutePath("$(PROJECTPATH)" + @"\" + "Projectinfo.xml"); string LastVersion = ReadXml(filename, 10043); MessageBox.Show( "Zuletzt verwendete EPLAN-Version:\n" + LastVersion, "Information", MessageBoxButtons.OK, MessageBoxIcon.Information ); return; } private static string ReadXml(string filename, int ID) { string strLastVersion = ""; XmlTextReader reader = new XmlTextReader(filename); while (reader.Read()) { if (reader.HasAttributes) { while (reader.MoveToNextAttribute()) { if (reader.Name == "id") { if (reader.Value == ID.ToString()) { strLastVersion = reader.ReadString(); reader.Close(); return strLastVersion; } } } } } return strLastVersion; } } |
14_Beispiele\01_Compress
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | using System.Windows.Forms; using Eplan.EplApi.ApplicationFramework; using Eplan.EplApi.Scripting; public class Class { [Start] public void Function() { CommandLineInterpreter oCLI = new CommandLineInterpreter(); ActionCallingContext acc = new ActionCallingContext(); acc.AddParameter("CONFIGSCHEME", "Standard"); acc.AddParameter("FILTERSCHEME", "Allpolig"); oCLI.Execute("compress", acc); MessageBox.Show("Action ausgeführt."); return; } } |
14_Beispiele\02_Devicelist
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | using System.Windows.Forms; using Eplan.EplApi.ApplicationFramework; using Eplan.EplApi.Base; using Eplan.EplApi.Scripting; public class Class { [Start] public void Function() { string strProjectpath = PathMap.SubstitutePath("$(PROJECTPATH)") + @"\"; CommandLineInterpreter oCLI = new CommandLineInterpreter(); ActionCallingContext acc = new ActionCallingContext(); acc.AddParameter("TYPE", "EXPORT"); acc.AddParameter("EXPORTFILE", strProjectpath + "Devicelist.txt"); acc.AddParameter("FORMAT", "XDLTxtImporterExporter"); oCLI.Execute("devicelist", acc); MessageBox.Show("Action ausgeführt."); return; } } |
14_Beispiele\03_Edit
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | using Eplan.EplApi.ApplicationFramework; using Eplan.EplApi.Scripting; public class Class { [Start] public void Function() { CommandLineInterpreter oCLI = new CommandLineInterpreter(); ActionCallingContext acc = new ActionCallingContext(); acc.AddParameter("PAGENAME", "=+/1"); acc.AddParameter("DEVICENAME", "=+-1K1"); acc.AddParameter("FORMAT", "XDLTxtImporterExporter"); oCLI.Execute("edit", acc); return; } } |
14_Beispiele\04_ExecuteScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | using Eplan.EplApi.ApplicationFramework; using Eplan.EplApi.Scripting; public class Class { [Start] public void Function() { CommandLineInterpreter oCLI = new CommandLineInterpreter(); ActionCallingContext acc = new ActionCallingContext(); acc.AddParameter("ScriptFile", @"C:\EPLAN Scripting Project\01_Erste_Schritte\01_Start.cs"); oCLI.Execute("ExecuteScript", acc); return; } } |
14_Beispiele\05_Generate
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | using System.Windows.Forms; using Eplan.EplApi.ApplicationFramework; using Eplan.EplApi.Scripting; public class Class { [Start] public void Function() { CommandLineInterpreter oCLI = new CommandLineInterpreter(); ActionCallingContext acc = new ActionCallingContext(); acc.AddParameter("TYPE", "CABLES"); acc.AddParameter("CREATIONSCHEME", "Standard"); acc.AddParameter("NUMBERINGSCHEME", "Standard"); acc.AddParameter("AUTOSELECTSCHEME", "Standard"); acc.AddParameter("REGENERATECONNS", "1"); acc.AddParameter("KEEPOLDNAMES", "1"); acc.AddParameter("STARTVALUE", "1"); acc.AddParameter("STEPVALUE", "1"); acc.AddParameter("ONLYAUTOCABLES", "1"); acc.AddParameter("REBUILDALLCONNECTIONS", "1"); oCLI.Execute("generate", acc); MessageBox.Show("Action ausgeführt."); return; } } |
14_Beispiele\06_Import
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | using Eplan.EplApi.ApplicationFramework; using Eplan.EplApi.Scripting; public class Class { [Start] public void Function() { CommandLineInterpreter oCLI = new CommandLineInterpreter(); ActionCallingContext acc = new ActionCallingContext(); acc.AddParameter("TYPE", "DXFPAGE"); acc.AddParameter("IMPORTFILE", @"C:\DXF\Smile.dxf"); oCLI.Execute("import", acc); return; } } |
14_Beispiele\07_Partlist
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | using System.Windows.Forms; using Eplan.EplApi.ApplicationFramework; using Eplan.EplApi.Base; using Eplan.EplApi.Scripting; public class Class { [Start] public void Function() { string strProjectpath = PathMap.SubstitutePath("$(PROJECTPATH)") + @"\"; CommandLineInterpreter oCLI = new CommandLineInterpreter(); ActionCallingContext acc = new ActionCallingContext(); acc.AddParameter("TYPE", "EXPORT"); acc.AddParameter("EXPORTFILE", strProjectpath + "Partlist.txt"); acc.AddParameter("FORMAT", "XPalCSVConverter"); oCLI.Execute("partslist", acc); MessageBox.Show("Action ausgeführt."); return; } } |
14_Beispiele\08_Print
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | using System.Windows.Forms; using Eplan.EplApi.ApplicationFramework; using Eplan.EplApi.Scripting; public class Class { [Start] public void Function() { CommandLineInterpreter oCLI = new CommandLineInterpreter(); ActionCallingContext acc = new ActionCallingContext(); acc.AddParameter("TYPE", "PROJECT"); oCLI.Execute("print", acc); MessageBox.Show("Action ausgeführt."); return; } } |
14_Beispiele\09_ProjectAction
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | using System.Windows.Forms; using Eplan.EplApi.ApplicationFramework; using Eplan.EplApi.Base; using Eplan.EplApi.Scripting; public class Class { [Start] public void Function() { CommandLineInterpreter oCLI = new CommandLineInterpreter(); ActionCallingContext acc = new ActionCallingContext(); acc.AddParameter("Project", @"C:\Projekte\Beispielprojekt.elk"); acc.AddParameter("Action", "reports"); acc.AddParameter("NOCLOSE", "1"); oCLI.Execute("ProjectAction", acc); MessageBox.Show("Action ausgeführt."); return; } } |
14_Beispiele\10_Projekteigenschaft_setzen
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | using System.Windows.Forms; using Eplan.EplApi.ApplicationFramework; using Eplan.EplApi.Base; using Eplan.EplApi.Scripting; public class Class { [Start] public void Function() { CommandLineInterpreter oCLI = new CommandLineInterpreter(); ActionCallingContext acc = new ActionCallingContext(); acc.AddParameter("PropertyId", "10013"); acc.AddParameter("PropertyIndex", "0"); acc.AddParameter("PropertyValue", "23542"); oCLI.Execute("XEsSetProjectPropertyAction", acc); MessageBox.Show("Action ausgeführt."); return; } } |
14_Beispiele\11_Projekt_Backup
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | using System; using System.Windows.Forms; using Eplan.EplApi.ApplicationFramework; using Eplan.EplApi.Base; using Eplan.EplApi.Scripting; public class Class { [Start] public void Function() { string strProjectpath = PathMap.SubstitutePath("$(PROJECTPATH)"); string strProjectname = PathMap.SubstitutePath("$(PROJECTNAME)"); string strFullProjectname = PathMap.SubstitutePath("$(P)"); string strDate = DateTime.Now.ToString("yyyy-MM-dd"); string strTime = DateTime.Now.ToString("hh-mm-ss"); string strBackupDirectory = strProjectpath + @"\Backup\"; string strBackupFilename = strProjectname + "_Backup_" + strDate + "_" + strTime; if (!System.IO.Directory.Exists(strBackupDirectory)) { System.IO.Directory.CreateDirectory(strBackupDirectory); } Progress oProgress = new Progress("SimpleProgress"); oProgress.SetAllowCancel(true); oProgress.SetAskOnCancel(true); oProgress.BeginPart(100, ""); oProgress.SetTitle("Backup"); oProgress.ShowImmediately(); if (!oProgress.Canceled()) { CommandLineInterpreter oCLI = new CommandLineInterpreter(); ActionCallingContext acc = new ActionCallingContext(); acc.AddParameter("BACKUPMEDIA", "DISK"); acc.AddParameter("ARCHIVENAME", strBackupFilename); acc.AddParameter("BACKUPMETHOD", "BACKUP"); acc.AddParameter("COMPRESSPRJ", "1"); acc.AddParameter("INCLEXTDOCS", "1"); acc.AddParameter("BACKUPAMOUNT", "BACKUPAMOUNT_ALL"); acc.AddParameter("INCLIMAGES", "1"); acc.AddParameter("LogMsgActionDone", "true"); acc.AddParameter("DESTINATIONPATH", strBackupDirectory); acc.AddParameter("PROJECTNAME", strFullProjectname); acc.AddParameter("TYPE", "PROJECT"); oCLI.Execute("backup", acc); } oProgress.EndPart(true); MessageBox.Show( "Backup wurde erfolgreich erstellt:\n" + strBackupFilename, "Hinweis", MessageBoxButtons.OK, MessageBoxIcon.Information ); return; } } |
14_Beispiele\12_Restore
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | using System.Windows.Forms; using Eplan.EplApi.ApplicationFramework; using Eplan.EplApi.Base; using Eplan.EplApi.Scripting; public class Class { [Start] public void Function() { CommandLineInterpreter oCLI = new CommandLineInterpreter(); ActionCallingContext acc = new ActionCallingContext(); acc.AddParameter("TYPE", "PROJECT"); acc.AddParameter("ARCHIVENAME", @"C:\Projekte\Beispielprojekt.zw1"); acc.AddParameter("PROJECTNAME", @"C:\Projekte\Beispielprojekt.elk"); acc.AddParameter("UNPACKPROJECT", "0"); acc.AddParameter("MODE", "1"); acc.AddParameter("NOCLOSE", "1"); oCLI.Execute("restore", acc); MessageBox.Show("Action ausgeführt."); return; } } |
14_Beispiele\13_Projekteigenschaften_importieren
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | using System.Windows.Forms; using Eplan.EplApi.ApplicationFramework; using Eplan.EplApi.Base; using Eplan.EplApi.Scripting; public class Class { [Start] public void Function() { string strProjects = PathMap.SubstitutePath("$(MD_PROJECTS)"); string strFilename = string.Empty; OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "ProjectInfo.xml|ProjectInfo.xml"; ofd.InitialDirectory = strProjects; ofd.Title = "Projekteigenschaften auswählen:"; ofd.ValidateNames = true; if (ofd.ShowDialog() == DialogResult.OK) { strFilename = ofd.FileName; Progress oProgress = new Progress("SimpleProgress"); oProgress.SetAllowCancel(false); oProgress.BeginPart(100, ""); oProgress.SetTitle("Projekteigenschaften importieren"); oProgress.ShowImmediately(); CommandLineInterpreter oCLI = new CommandLineInterpreter(); ActionCallingContext cc = new ActionCallingContext(); cc.AddParameter("TYPE", "READPROJECTINFO"); cc.AddParameter("FILENAME", strFilename); oCLI.Execute("projectmanagement", cc); oProgress.EndPart(true); oCLI.Execute("XPrjActionPropertiesEdit"); } return; } } |
14_Beispiele\14_Seitenanzahl_ermitteln
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | using System.Windows.Forms; using Eplan.EplApi.ApplicationFramework; using Eplan.EplApi.Base; using Eplan.EplApi.Scripting; class Class { [DeclareAction("GetNumberOfPages")] public void Function() { CommandLineInterpreter oCLI = new CommandLineInterpreter(); ActionCallingContext acc = new ActionCallingContext(); string strPages = string.Empty; acc.AddParameter("TYPE", "PAGES"); oCLI.Execute("selectionset", acc); acc.GetParameter("PAGES", ref strPages); string[] strPagesCount = strPages.Split(';'); int intPagesCount = strPagesCount.Length; string strProjectname = PathMap.SubstitutePath("$(PROJECTNAME)") |

