Usage of C# Interactive Window with EPLAN API
REPL is for Read Evaluate Print Loop. Just imagine you could execute code while you're writing it line by line. The Roslyn compiler makes this possible. The Visual Studio Build Tools include an executable named csi.exe
(C# Interactive) that starts as a simple console window. Here you can start to enter and execute C# code instantly.
Default path for the executable is:
C:\Program Files (x86)\Microsoft Visual Studio\2019\[VARIANT]\MSBuild\Current\Bin\Roslyn\csi.exe
You can also start C# Interactive within Visual Studio 2015 and newer (View > Other Windows > C# Interactive). This adds Intellisense (code completion) to the terminal, what makes it even easier to learn a framework or analyze method behavior and properties of a class.
With the #r
directive you can simply add .Net library references to your C# Interactive instance. With a little trick this works for the EPLAN API assemblies as well. Of course you still need the developer license (EPLAN API Extension).
To use the EPLAN API assemblies in C# Interactive you need to proceed like you would use EPLAN offline in other applications. The easiest way to do so is by using the Suplanus.Sepla library.
But you don't need to type in or copy paste the code each time. With the #load
directive you can include and execute a C# Script (*.csx) to your execution engine. I prepared a script here StartEplanConsole_2_9_4 that does the job if paths for #r
directive are setup correctly.
So all you need to do is:
- Download the script StartEplanConsole_2_9_4
- Fix the path to your Suplanus.Sepla build
- Fix the path and version to your EPLAN assemblies you like to adress
- Fix the system configuration you like to start with (mine is
API
) #load ./src/Scripts/StartEplanConsole_2_9_4.csx
- Select license with API Extension
- have fun
The Script also brings an example method to open a EPLAN project.
Just var myProject = GetProject("$(MD_PROJECTS)\MyProject.elk")
Also it's nicer to shut down the EPLAN offline application with eplan.Close();