EPLAN-API

Alles rund um die API in EPLAN

EPLAN-API: Signierung automatisieren (Update 1)

Ich hatte hier ja mal was ausprobiert… aber so ganz zufrieden war ich da nicht:

  1. Es kann nur ein Keyfile angegeben werden
  2. Irgendwas da in der Projektdatei rumschreiben macht nur Probleme

Nun hab ich mir das nochmal angeschaut und eine Lösung gefunden. Per Kommandozeile kann man die DLLs in IL Code umwandeln und dann neu kompilieren mit Keyfile. Achtet darauf dass die Ausgabepfade auch alle vorhanden sind.

"C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools\ildasm.exe" "C:\Testprojekt\bin\Release\Suplanus.Test.EplAddIn.Template.dll" /all /out="C:\Testprojekt\bin\Release\Signed\Suplanus.Test.EplAddIn.Template.il"
"C:\Windows\Microsoft.NET\Framework\v4.0.30319\ilasm.exe" "C:\Testprojekt\Signed\Suplanus.Test.EplAddIn.Template.il" /dll /key:"C:\Testprojekt\Build\Keyfiles\MyKeyFile.snk"

Im Signed Ordner findet ihr dann die signierte DLL. Diese dann bei EPLAN hochladen und das wars.

Von |2017-11-07T16:37:57+01:002017-11-08|EPLAN, EPLAN-API|

EPLAN Offline Console Application

Bin schon paar mal selbst drüber gestolpert, darum hier eine Notiz an mich selbst:
Will man eine EPLAN Offline Anwendung als Konsolenapplikation erstellen muss die Main()  Methode mit dem Compiler Attribut [STAThread]  ausgestattet werden:

using System;
using System.IO;
using System.Linq;
using Suplanus.Sepla.Application;

namespace Suplanus.Test.Console
{
    class Program
    {
        [STAThread]
        static void Main(string[] args)
        {
            // Start EPLAN
            System.Console.WriteLine("Starting EPLAN...");
            string binPath = Starter.GetEplanInstallations()
                .Last(obj => obj.EplanVariant
                .Equals("Electric P8"))
                .EplanPath;
            binPath = Path.GetDirectoryName(binPath);
            EplanOffline eplanOffline = new EplanOffline(binPath, "API");
            eplanOffline.StartWithoutGui();

            // Close
            eplanOffline.Close();           
            System.Console.ReadKey();
        }
    }
}

 

Hab das auch noch in den Kommentar der Starter gepackt:

Von |2026-07-23T12:50:19+02:002017-11-07|EPLAN, EPLAN-API|

CustomItemType

Aus der Rubrik „Ich bau mir die Artikelverwaltung wie Sie mir gefällt…“, wieder eine nicht offizielle Möglichkeit die Artikelverwaltung zu erweitern (kein Support von EPLAN). Nämlich über eine eigene Objekt Art. Weiß garnicht wie man ItemType in dem Kontext korrekt übersetzt.

Naja schaut euch mal das Video an, den Code findet ihr auf GitHub.

Von |2017-10-24T14:49:39+02:002017-10-24|EPLAN, EPLAN-API|

PartsManagementExtension

Ihr wollte eine eigene Registerkarte in der EPLAN Artikeldatenbank? Kein Problem, zumindest per API.
Die Funktionen hier sind von EPLAN nicht offiziell Freigegeben und werden nicht supported. Dennoch gibt es eine kleine Beschreibung in der API-Hilfe.

Die Implementierung ist nicht ganz so einfach, da hier mit manuellen Events gearbeitet wird und diese muss man dann erst in der Action senden und im UserControl registrieren.

Addin:

using System.IO;
using System.Reflection;
using Eplan.EplApi.ApplicationFramework;
using Eplan.EplApi.MasterData;
using Eplan.EplSDK.WPF;
using Eplan.EplSDK.WPF.DB;

namespace Suplanus.Example.EplAddIn.PartsManagementExtensionExample
{
    class Addin : IEplAddIn
    {
        public string TabsheetName => nameof(PartsManagementExtensionContent);
        public string ItemType => "eplan.part";

        public string AddinName
        {
            get
            {
                string addinName = typeof(Addin).Assembly.CodeBase;
                addinName = Path.GetFileNameWithoutExtension(addinName);
                return addinName;
            }
        }        

        public bool OnRegister(ref bool isLoadingOnStart)
        {
            isLoadingOnStart = true;
            return true;
        }

        public bool OnUnregister()
        {
            var partsManagement = new MDPartsManagement();
            partsManagement.UnregisterAddin(AddinName);
            partsManagement.UnregisterItem(ItemType);
            partsManagement.UnregisterTabsheet(TabsheetName);

            return true;
        }

        public bool OnInit()
        {
            return true;
        }

        public bool OnInitGui()
        {
            var partsManagement = new MDPartsManagement();
            string actionName = nameof(PartsManagementExtensionExampleAction);

            partsManagement.RegisterAddin(AddinName, actionName);            
            partsManagement.RegisterItem(AddinName, ItemType);
            partsManagement.RegisterTabsheet(AddinName, ItemType, TabsheetName);
            DialogFactoryDB dialogBarFactory = new DialogFactoryDB(TabsheetName,
                typeof(PartsManagementExtensionContent));
            PartsManagementExtensionExampleAction.TabsheetName = TabsheetName;

            return true;
        }

        public bool OnExit()
        {
            return true;
        }
    }
}

 

Action:

using Eplan.EplApi.ApplicationFramework;
using Eplan.EplSDK.WPF.EEvent;

namespace Suplanus.Example.EplAddIn.PartsManagementExtensionExample
{
    class PartsManagementExtensionExampleAction : IEplAction
    {
        public static string TabsheetName = null;

        public void GetActionProperties(ref ActionProperties actionProperties) { }

        public bool OnRegister(ref string name, ref int ordinal)
        {
            name = nameof(PartsManagementExtensionExampleAction);
            return true;
        }

        public bool Execute(ActionCallingContext actionCallingContext)
        {
            // Sent events to WPF control from base action
            string itemType = string.Empty;
            string action = string.Empty;
            string key = string.Empty;
            actionCallingContext.GetParameter("itemtype", ref itemType);
            actionCallingContext.GetParameter("action", ref action);
            actionCallingContext.GetParameter("key", ref key);

            WPFDialogEventManager wpfDialogEventManager = new WPFDialogEventManager();

            switch (action)
            {
                case "SelectItem":
                case "SaveItem":
                case "PreShowTab":
                case "OpenDatabase":
                case "CreateDatabase":
                    wpfDialogEventManager.send("XPartsManagementDialog", action, key);
                    break;
            }

            return true;
        }
    }
}

 

XAML: CodeBehind

using Eplan.EplApi.MasterData;
using Eplan.EplSDK.WPF.EEvent;
using Eplan.EplSDK.WPF.Interfaces.DialogServices;

namespace Suplanus.Example.EplAddIn.PartsManagementExtensionExample
{
    public partial class PartsManagementExtensionContent : IDialog
    {
        public string Caption => nameof(PartsManagementExtensionContent);
        public bool IsTabsheet => true;
        public ViewModel ViewModel { get; set; } 

        private readonly MDPartsManagement _partsManagement = new MDPartsManagement();

        public PartsManagementExtensionContent()
        {
            InitializeComponent();

            ViewModel = new ViewModel();
            DataContext = ViewModel;

            ViewModel.IsReadOnly = _partsManagement.SelectedPartsDatabase.IsReadOnly;

            // Events, called from Action of this Tab
            WPFDialogEventManager dialogEventManager = new WPFDialogEventManager();
            dialogEventManager.getOnWPFNotifyEvent("XPartsManagementDialog", "SelectItem").Notify += SelectItem;
            dialogEventManager.getOnWPFNotifyEvent("XPartsManagementDialog", "SaveItem").Notify += SaveItem;
            dialogEventManager.getOnWPFNotifyEvent("XPartsManagementDialog", "PreShowTab").Notify += PreShowTab;
            dialogEventManager.getOnWPFNotifyEvent("XPartsManagementDialog", "OpenDatabase").Notify += OpenDatabase;
            dialogEventManager.getOnWPFNotifyEvent("XPartsManagementDialog", "CreateDatabase").Notify += CreateDatabase;
        }

        private void CreateDatabase(string data)
        {
            
        }

        private void OpenDatabase(string data)
        {
            
        }

        private void PreShowTab(string data)
        {
            
        }

        private void SelectItem(string data)
        {
            
        }

        private void SaveItem(string data)
        {
            
        }

    }
}

 

XAML: UserControl

<UserControl
    x:Class="Suplanus.Example.EplAddIn.PartsManagementExtensionExample.PartsManagementExtensionContent"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    d:DesignHeight="300"
    d:DesignWidth="300"
    DataContext="{Binding RelativeSource={RelativeSource Self}, Path=ViewModel}"
    mc:Ignorable="d">
    <Grid Margin="10">
        <Viewbox>
            <TextBox
                IsEnabled="{Binding IsEnabled}"
                Text="Hello PartsManagementExtension!"
                TextWrapping="Wrap" />
        </Viewbox>
    </Grid>
</UserControl>

 

ViewModel:

using System;
using System.ComponentModel;
using System.Runtime.CompilerServices;

namespace Suplanus.Example.EplAddIn.PartsManagementExtensionExample
{
    public class ViewModel : INotifyPropertyChanged
    {
        private bool _isReadonly;
        public bool IsReadOnly
        {
            get { return _isReadonly; }
            set
            {
                if (value == _isReadonly) return;
                _isReadonly = value;
                OnPropertyChanged();
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;
        protected virtual void OnPropertyChanged([CallerMemberName] String propertyName = "")
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}

 

Natürlich findet Ihr das wie gewohnt auf GitHub!

Von |2019-03-14T08:42:17+01:002017-10-18|EPLAN, EPLAN-API|

Navigator in API

Ewig steht das schon auf meiner Todo-Liste: Einen eigenen Navi per API implementieren.
Die Möglichkeit welche ich hier beschreibe ist nicht teil der offiziellen EPLAN API. Somit bekommt man auch kein Support oder Ähnliches.

Dennoch finde ich die Möglichkeit super und denke viele von Euch haben dafür auch einen Anwendungsfall.

Eigentlich braucht man nur eine DialogBarFactory und ein WPF-UserControl dazu:

using System.Reflection;
using Eplan.EplApi.ApplicationFramework;
using Eplan.EplSDK.WPF;

namespace Suplanus.EplAddIn.NavigatorExample
{
    class NavigatorExample : IEplAddIn
    {
        public bool OnRegister(ref bool isLoadingOnStart)
        {
            isLoadingOnStart = true;
            return true;
        }

        public bool OnUnregister()
        {
            return true;
        }

        public bool OnInit()
        {
            return true;
        }

        public bool OnInitGui()
        {
            // Get name from class
            // ReSharper disable once PossibleNullReferenceException
            var className = MethodBase.GetCurrentMethod().DeclaringType.Name;
            DialogBarFactory dialogBarFactory = new DialogBarFactory(className, typeof(NavigatorContent), DialogDockingOptions.Any, 0);

            return true;
        }

        public bool OnExit()
        {
            return true;
        }
    }
}

Im UserControl müssen aber viele Interfaces implementiert sein :^)

using System.Reflection;
using Eplan.EplSDK.WPF.Interfaces;
using Eplan.EplSDK.WPF.Interfaces.DialogServices;

namespace Suplanus.EplAddIn.NavigatorExample
{
    public partial class NavigatorContent : IDialog, IDialogBar, IDialogComponentAccess, ICallingContext, IDialogState, IDialogAction, IDialogClose, IElementStateAccess
    {
        public string Caption { get; set; }
        public bool IsTabsheet { get; set; }
        public int UniqueBarID { get; set; }
        public IDialogComponent Component { get; set; }
        public object Context { get; set; }
        public IDialogStateManager DialogStateManager { get; set; }
        public IElementStateCollection ElementStateCollection { get; set; }

        public NavigatorContent()
        {
            // Iniit
            ElementStateCollection = new Eplan.EplSDK.WPF.Controls.Persistency.ElementStateCollection();
            ElementStateCollection.Load(nameof(NavigatorContent));

            InitializeComponent();

            Caption = "NavigatorExample";
            IsTabsheet = false;

            // Use Class name for uniqueid
            // ReSharper disable once PossibleNullReferenceException
            var className = MethodBase.GetCurrentMethod().DeclaringType.Name;
            UniqueBarID = (int)(uint)className.GetHashCode();           
            
        }
       
        public void init()
        {
            
        }

        public bool isValid()
        {
            return true;
        }

        public void reload()
        {
            
        }

        public void save()
        {
            
        }

        public void close()
        {
            
        }

    }
}

Anbei ein Beispiel UserControl in WPF:

<UserControl
    x:Class="Suplanus.EplAddIn.NavigatorExample.NavigatorContent"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    d:DesignHeight="300"
    d:DesignWidth="300"
    mc:Ignorable="d">
    <Grid Margin="10">
        <Viewbox>
            <TextBlock Text="Hello Navigator!" TextWrapping="Wrap" />
        </Viewbox>
    </Grid>
</UserControl>

Eine lauffähiges Beispiel findet Ihr auf GitHub

Von |2022-04-13T11:20:49+02:002017-09-28|EPLAN, EPLAN-API|
Nach oben