The easiest way to use EPLAN API objects in your program is to directly use the functionally of the API dlls in your code.It is even easier, if your program is a .Net application: You just reference the managed EPLAN API assemblies in your project. This type of application, we call an "offline application".
Then -- in the appropriate place (e.g. in the main form) -- you create an instance of class Eplan.EplApi.System.EplApplication and initialize it:
The string parameter strAppModifier determines, which configuration file is used and thus which modules will be loaded. If you pass an empty string like in the above example, the eplset.xml of the standard version of the current user will be loaded.
After executing theInit() function, all functions/objects of the EPLAN API are available, except those, which are exposing GUI functionality like dialogs, dialog-bars or MDI windows. The API Classes and methods, ... then are used in the same way as if programming a normal EPLAN add-in. A few selected modal Dialogs of EPLAN are provided by special methods of class in Eplan.EplApi.System.EplApplication.
When you no longer need the EPLAN API in your program, you should call the Exit() function of your EplApplication object to unload the API.
In case of offline application using Windows Forms, it is possible that the application changes its size after EplApplication::Init. It happens if the font size is set to other than 100% in OS, which happens quite often in case of big size monitors. Because of it, please set DPI Awarness in .config file of the application, in order to avoid rescalling :
Copy Code
|
|
---|---|
<System.Windows.Forms.ApplicationConfigurationSection> <add key="DpiAwareness" value="PerMonitorV2" /> </System.Windows.Forms.ApplicationConfigurationSection> |
Also please assure Windows 10 compatibility to your .manifest file :
Copy Code
|
|
---|---|
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1"> <application> <!-- Windows 10 compatibility --> <supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" /> </application> </compatibility> |
As was briefly mentioned in the topic EPLAN .Net API, a path must be set to the <eplan main path>\Platform\<version>\Bin folder. More precisely, you need to make sure to load the EPLAN API assemblies from exactly this folder. The reason for this is, that the API assemblies have statically linked unmanaged dependencies, which need to be loaded directly from the current directory.
This is also the reason, why in general it will not work, to register the EPLAN API dlls in GAC. The directory from which references of your Visual Studio project are added does not influence from where the dlls are actually loaded.
You can make sure, the API assemblies are loaded from the bin directory by different means:
C# |
Copy Code
|
---|---|
// Use the finder to find the correct eplan version if not yet known EplanFinder oEplanFinder = new EplanFinder(); String strBinPath = oEplanFinder.SelectEplanVersion(true); // Check if user has selected any Eplan variant (Electric P8, etc) if (String.IsNullOrEmpty(strBinPath)) return; //Use the AssemblyResolver to let the program know where all an Eplan variant can be found. AssemblyResolver oResolver = new AssemblyResolver(); oResolver.SetEplanBinPath(strBinPath); //Now pin to Eplan. This way all referenced eplan assemblies are loaded from the platform bin path. oResolver.PinToEplan(); //Use separate class to initialize EplApplication. Pass path to Eplan variant bin in order to set EplApplication.EplanBinFolder property Form1 oForm = new Form1(); oForm.EplanBinFolder = oResolver.GetEplanBinPath(); Application.Run(oForm); |
3. Publish the codebases of all needed API assemblies in the application config file. (An XML file, which is named like your executable with an additional extension .config., e.g. MyApplication.exe.config). The following code shows an example for the contents of such a config file.
XML |
Copy Code
|
---|---|
<?xml version="1.0"?> <configuration> <runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> <assemblyIdentity name="Eplan.EplApi.Systemu" publicKeyToken="57aaa27e22f7b107" /> <publisherPolicy apply="yes" /> <codeBase version="1.0.0.0" href="file:///C:\Program Files\EPLAN\Platform\2.2.0\Bin\Eplan.EplApi.Systemu.dll" /> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="Eplan.EplApi.AFu" publicKeyToken="57aaa27e22f7b107" /> <publisherPolicy apply="yes" /> <codeBase version="1.0.0.0" href="file:///C:\Program Files\EPLAN\Platform\2.2.0\Bin\Eplan.EplApi.AFu.dll" /> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="Eplan.EplApi.Baseu" publicKeyToken="57aaa27e22f7b107" /> <publisherPolicy apply="yes" /> <codeBase version="1.0.0.0" href="file:///C:\Program Files\EPLAN\Platform\2.2.0\Bin\Eplan.EplApi.Baseu.dll" /> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="Eplan.EplApi.DataModelu" publicKeyToken="57aaa27e22f7b107" /> <publisherPolicy apply="yes" /> <codeBase version="1.0.0.0" href="file:///C:\Program Files\EPLAN\Platform\2.2.0\Bin\Eplan.EplApi.DataModelu.dll" /> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="Eplan.EplApi.HEServicesu" publicKeyToken="57aaa27e22f7b107" /> <publisherPolicy apply="yes" /> <codeBase version="1.0.0.0" href="file:///C:\Program Files\EPLAN\Platform\2.2.0\Bin\Eplan.EplApi.HEServicesu.dll" /> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="Eplan.EplApi.EServicesu" publicKeyToken="57aaa27e22f7b107" /> <publisherPolicy apply="yes" /> <codeBase version="1.0.0.0" href="file:///C:\Program Files\EPLAN\Platform\2.2.0\Bin\Eplan.EplApi.EServicesu.dll" /> </dependentAssembly> </assemblyBinding> </runtime> </configuration> |
4. Last but not least, you can implement an AssemblyResolve event handler in your offline application, where you load the looked-for assemblies explicitly. For this, also you need to set the current directory of the application to the respective bin directory. The following code shows an example for this:
C# |
Copy Code
|
---|---|
[STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Environment.CurrentDirectory = @"C:\program files\EPLAN\platform\x.x.x\BIN\"; // x.x.x = your desired EPLAN version AppDomain appDomain = AppDomain.CurrentDomain; appDomain.AssemblyResolve += new ResolveEventHandler(MyResolveEventHandler); Application.Run(new Form1()); } static Assembly MyResolveEventHandler(object sender, ResolveEventArgs args) { Console.WriteLine("Resolving..."); string sAssemblyName = args.Name.Split(',')[0]; Assembly ass = Assembly.LoadFile(@"C:\program files\EPLAN\platform\x.x.x\BIN\" + sAssemblyName + ".dll"); return ass ; } } |
In Visual Studio Tools for Office (VSTO) projects, the assembly resolver or the application config file is not working. Office still tries to copy the EPLAN API assemblies to a temporary folder before loading. VSTO applications will only work, if you set the codebases of the API assemblies in the machine.config file, which you usualy find in the directory C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\CONFIG.
If you want to use any object from the name spaces beginning with Eplan.EplApi.DataModel , you need to open a LockingStep, before you e.g. open an EPLAN project.
Make sure to call Exit() only one time in your application. It is currently not possible to use Init("") after Exit(), while the application is still running.
EplApplication instance should be deinitialized explicitly by the main thread. When <c>Exit</c> method is called by thread of garbage collector or after leaving main function of application, it cause application crash.