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
Visual Studio Projekt mit 84 Beispielen auf GitHub
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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ü
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ü
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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)");
MessageBox.Show("Anzahl markierter Seiten:\n"
+ "►►► " + intPagesCount.ToString() + " ◄◄◄",
"Markierte Seiten [" + strProjectname + "]",
MessageBoxButtons.OK,
MessageBoxIcon.Information);
return;
}
[DeclareMenu]
public void MenuFunction()
{
Eplan.EplApi.Gui.Menu oMenu = new Eplan.EplApi.Gui.Menu();
oMenu.AddMenuItem(
"Seitenzahl ermitteln...", // Name: Menüpunkt
"GetNumberOfPages", // Name: Action
"Anzahl der markierten Seiten ausgeben", // Statustext
35392, // Menü-ID: Menü > Seite
1, // 1 = hinter Menüpunkt, 0 = vor Menüpunkt
true, // Separator davor anzeigen
false // Separator dahinter anzeigen
);
return;
}
}
14_Beispiele\15_Sounds
using System;
using System.Media;
using System.Windows.Forms;
using Eplan.EplApi.Scripting;
class Class
{
[Start]
public void Function()
{
MessageBox.Show(
"Systemsound wird ausgegeben...",
"Hinweis",
MessageBoxButtons.OK,
MessageBoxIcon.Information
);
SystemSounds.Beep.Play();
MessageBox.Show(
"Hardwaresound wird ausgegeben...",
"Hinweis",
MessageBoxButtons.OK,
MessageBoxIcon.Information
);
Console.Beep();
MessageBox.Show(
"Hardwaresound wird mit Frequenz ausgegeben...\n"
+ "1000 Millisekunden\n"
+ "1000 Hz",
"Hinweis",
MessageBoxButtons.OK,
MessageBoxIcon.Information
);
Console.Beep(1000,1000);
return;
}
}
14_Beispiele\16_Besser_als_Progressbar
using System;
using Eplan.EplApi.Scripting;
class Class
{
[Start]
public void Function()
{
Console.Beep(420, 200);
Console.Beep(400, 200);
Console.Beep(420, 200);
Console.Beep(400, 200);
Console.Beep(420, 200);
Console.Beep(315, 200);
Console.Beep(370, 200);
Console.Beep(335, 200);
Console.Beep(282, 600);
Console.Beep(180, 200);
Console.Beep(215, 200);
Console.Beep(282, 200);
Console.Beep(315, 600);
Console.Beep(213, 200);
Console.Beep(262, 200);
Console.Beep(315, 200);
Console.Beep(335, 600);
Console.Beep(213, 200);
Console.Beep(420, 200);
Console.Beep(400, 200);
Console.Beep(420, 200);
Console.Beep(400, 200);
Console.Beep(420, 200);
Console.Beep(315, 200);
Console.Beep(370, 200);
Console.Beep(335, 200);
Console.Beep(282, 600);
Console.Beep(180, 200);
Console.Beep(215, 200);
Console.Beep(282, 200);
Console.Beep(315, 600);
Console.Beep(213, 200);
Console.Beep(330, 200);
Console.Beep(315, 200);
Console.Beep(282, 600);
return;
}
}
14_Beispiele\17_E-mail
using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using Eplan.EplApi.Scripting;
public class Class
{
[DeclareAction("SendMail")]
public void Function(string ADDRESS,string SUBJECT,
string BODY,string ATTACH)
{
MAPI mapi = new MAPI();
mapi.AddRecipientTo(ADDRESS);
if (File.Exists(ATTACH))
{
mapi.AddAttachment(ATTACH);
}
mapi.SendMailPopup(SUBJECT, BODY); // E-mail anzeigen
//mapi.SendMailDirect(SUBJECT, BODY); //E-mail direkt versenden
return;
}
#region MAPI
// MAPI: E-mail Classes
public class MAPI
{
public bool AddRecipientTo(string email)
{
return AddRecipient(email, HowTo.MAPI_TO);
}
public bool AddRecipientCC(string email)
{
return AddRecipient(email, HowTo.MAPI_TO);
}
public bool AddRecipientBCC(string email)
{
return AddRecipient(email, HowTo.MAPI_TO);
}
public void AddAttachment(string strAttachmentFileName)
{
m_attachments.Add(strAttachmentFileName);
}
public int SendMailPopup(string strSubject, string strBody)
{
return SendMail(strSubject, strBody, MAPI_LOGON_UI
| MAPI_DIALOG);
}
public int SendMailDirect(string strSubject, string strBody)
{
return SendMail(strSubject, strBody, MAPI_LOGON_UI);
}
[DllImport("MAPI32.DLL")]
static extern int MAPISendMail(IntPtr sess, IntPtr hwnd,
MapiMessage message, int flg, int rsv);
int SendMail(string strSubject, string strBody, int how)
{
MapiMessage msg = new MapiMessage();
msg.subject = strSubject;
msg.noteText = strBody;
msg.recips = GetRecipients(out msg.recipCount);
msg.files = GetAttachments(out msg.fileCount);
m_lastError = MAPISendMail(new IntPtr(0), new IntPtr(0),
msg, how, 0);
if (m_lastError > 1)
MessageBox.Show("MAPISendMail failed! " + GetLastError(),
"MAPISendMail");
Cleanup(ref msg);
return m_lastError;
}
bool AddRecipient(string email, HowTo howTo)
{
MapiRecipDesc recipient = new MapiRecipDesc();
recipient.recipClass = (int)howTo;
recipient.name = email;
m_recipients.Add(recipient);
return true;
}
IntPtr GetRecipients(out int recipCount)
{
recipCount = 0;
if (m_recipients.Count == 0)
return IntPtr.Zero;
int size = Marshal.SizeOf(typeof(MapiRecipDesc));
IntPtr intPtr =
Marshal.AllocHGlobal(m_recipients.Count * size);
int ptr = (int)intPtr;
foreach (MapiRecipDesc mapiDesc in m_recipients)
{
Marshal.StructureToPtr(mapiDesc, (IntPtr)ptr, false);
ptr += size;
}
recipCount = m_recipients.Count;
return intPtr;
}
IntPtr GetAttachments(out int fileCount)
{
fileCount = 0;
if (m_attachments == null)
return IntPtr.Zero;
if ((m_attachments.Count
maxAttachments))
return IntPtr.Zero;
int size = Marshal.SizeOf(typeof(MapiFileDesc));
IntPtr intPtr =
Marshal.AllocHGlobal(m_attachments.Count * size);
MapiFileDesc mapiFileDesc = new MapiFileDesc();
mapiFileDesc.position = -1;
int ptr = (int)intPtr;
foreach (string strAttachment in m_attachments)
{
mapiFileDesc.name = Path.GetFileName(strAttachment);
mapiFileDesc.path = strAttachment;
Marshal.StructureToPtr(mapiFileDesc, (IntPtr)ptr, false);
ptr += size;
}
fileCount = m_attachments.Count;
return intPtr;
}
void Cleanup(ref MapiMessage msg)
{
int size = Marshal.SizeOf(typeof(MapiRecipDesc));
int ptr = 0;
if (msg.recips != IntPtr.Zero)
{
ptr = (int)msg.recips;
for (int i = 0; i < msg.recipCount; i++)
{
Marshal.DestroyStructure((IntPtr)ptr,
typeof(MapiRecipDesc));
ptr += size;
}
Marshal.FreeHGlobal(msg.recips);
}
if (msg.files != IntPtr.Zero)
{
size = Marshal.SizeOf(typeof(MapiFileDesc));
ptr = (int)msg.files;
for (int i = 0; i < msg.fileCount; i++)
{
Marshal.DestroyStructure((IntPtr)ptr,
typeof(MapiFileDesc));
ptr += size;
}
Marshal.FreeHGlobal(msg.files);
}
m_recipients.Clear();
m_attachments.Clear();
m_lastError = 0;
}
public string GetLastError()
{
if (m_lastError m_recipients = new
List();
List m_attachments = new List();
int m_lastError = 0;
const int MAPI_LOGON_UI = 0x00000001;
const int MAPI_DIALOG = 0x00000008;
const int maxAttachments = 20;
enum HowTo { MAPI_ORIG = 0, MAPI_TO, MAPI_CC, MAPI_BCC };
}
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public class MapiMessage
{
public int reserved;
public string subject;
public string noteText;
public string messageType;
public string dateReceived;
public string conversationID;
public int flags;
public IntPtr originator;
public int recipCount;
public IntPtr recips;
public int fileCount;
public IntPtr files;
}
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public class MapiFileDesc
{
public int reserved;
public int flags;
public int position;
public string path;
public string name;
public IntPtr type;
}
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public class MapiRecipDesc
{
public int reserved;
public int recipClass;
public string name;
public string address;
public int eIDSize;
public IntPtr entryID;
}
#endregion
}