EPLAN

EPLAN-API: Offline Applikation starten

Mit der Offline Applikation hat man man vielen Problemen zu kämpfen, angefangen beim Start…

Ich hab auf GitHub mal Methoden bereitgestellt um das zu vereinfach.

 

Verwendung WPF

var eplanOffline = new EplanOffline();
eplanOffline.StartWpf(this);
if (!eplanOffline.IsRunning)
{
	throw new NotImplementedException();
}
eplanOffline.Close();

Verwendung Windows Forms

var eplanOffline = new EplanOffline();
eplanOffline.StartWindowsForms(this);
if (!eplanOffline.IsRunning)
{
	throw new NotImplementedException();
}
eplanOffline.Close();

 

Ich habe bewusst darauf verzichtet dass alles im Konstruktor zu machen, da sonst WindowsForms in WPF und anders herum hinzugefügt werden muss.

Hier mal der Code dazu (Starter ist zum registrieren der Lizenz/DLLs):

using System.Collections.Generic;
using System.IO;
using System.Linq;
using Eplan.EplApi.Starter;

namespace Suplanus.Sepla.Application
{
    /// <summary>
    /// EPLAN Starter Helper: No other EPLAN-Namespaces are allowd
    /// </summary>
    public class Starter
    {
        public static string GetBinPathLastVersion()
        {
            List<EplanData> eplanVersions = new List<EplanData>();

            List<EplanData> eplanVersions32Bit = new List<EplanData>();
            new EplanFinder().GetInstalledEplanVersions(ref eplanVersions32Bit);
            eplanVersions.AddRange(eplanVersions32Bit);

            List<EplanData> eplanVersions64Bit = new List<EplanData>();
            new EplanFinder().GetInstalledEplanVersions(ref eplanVersions64Bit, true);
            eplanVersions.AddRange(eplanVersions64Bit);

            eplanVersions = new List<EplanData>(eplanVersions
                .Where(obj => obj.EplanVariant.Equals("Electric P8"))
                .OrderBy(obj => obj.EplanVersion));

            EplanData eplanData = eplanVersions.LastOrDefault();

            var binPath = Path.GetDirectoryName(eplanData.EplanPath);

            AssemblyResolver resolver = new AssemblyResolver();
            resolver.SetEplanBinPath(binPath);
            resolver.PinToEplan();

            return binPath;
        }
    }
}

 

using System;
using System.Windows;
using System.Windows.Forms;
using System.Windows.Interop;
using Eplan.EplApi.System;
using Suplanus.Sepla.Gui;

namespace Suplanus.Sepla.Application
{
    public class EplanOffline
    {
        public EplApplication Application;

	    public Preview Preview;

		/// <summary>
		/// Starts EPLAN with the last version of Electric P8 and attach to (WPF) window
		/// </summary>
		/// <param name="window"></param>
		public void StartWpf(Window window)
	    {
			IntPtr handle = new WindowInteropHelper(window).Handle;
			string binPath = Starter.GetBinPathLastVersion();
			Start(handle,binPath);
		}

		/// <summary>
		/// Starts EPLAN with the last version of Electric P8 and attach to (WF) form
		/// </summary>
		/// <param name="form"></param>
		public void StartWindowsForms(Form form)
		{
			IntPtr handle = form.Handle;
			string binPath = Starter.GetBinPathLastVersion();
			Start(handle, binPath);
		}

		/// <summary>
		/// Starts EPLAN with the given version of program variant and attach to (WPF) window
		/// </summary>
		/// <param name="window"></param>
		/// <param name="binPath"></param>
		public void StartWpf(Window window, string binPath)
		{
			IntPtr handle = new WindowInteropHelper(window).Handle;
			Start(handle, binPath);
		}

		/// <summary>
		/// Returns if the EPLAN-Application is running
		/// </summary>
		public bool IsRunning
        {
            get { return Application != null; }
        }

	    

	    /// <summary>
		/// Starts the application
		/// </summary>
		/// <param name="handle"></param>
		/// <param name="binPath"></param>
        private void Start(IntPtr handle, string binPath)
        {
            if (Application == null)
            {
                try
                {
                    EplApplication eplApplication = new EplApplication();
                    eplApplication.EplanBinFolder = binPath;
                    eplApplication.ResetQuietMode();
                    eplApplication.SetMainFrame(handle);
                    eplApplication.Init("", true, true);
                    Application = eplApplication;
                }
                catch
                {
                    Application = null;
                } 
            }
        }

		/// <summary>
		/// Release all objects
		/// </summary>
        public void Close()
        {
            if (Application != null)
            {
                Application.Exit();
                Application = null;
            }
        }
    }
}

In diesem Code wird immer die aktuellste Version von EPLAN Electric P8 verwendet. Ich bau irgendwann noch Methoden zur Auswahl von der Lizenz / Version.

Von |2017-11-09T11:23:59+01:002016-01-28|EPLAN, EPLAN-API|

GetProjectVariableLanguage

Ich hatte mal schon geschrieben wie man die Projekt-Sprachen rausfindet

Hier noch ein Script wie man die variable Sprache herausfindet.
Einfach das Script laden und in einem anderen Script das Usage ausführen.

 

using System.IO;
using System.Xml;
using Eplan.EplApi.ApplicationFramework;
using Eplan.EplApi.Base;
using Eplan.EplApi.Scripting;

class GetProjectVariableLanguage
{
	/* Usage
	private static string GetProjectVariableLanguage()
	{
		string value = null;
		ActionCallingContext actionCallingContext = new ActionCallingContext();
		new CommandLineInterpreter().Execute("GetProjectVariableLanguage", actionCallingContext);
		actionCallingContext.GetParameter("value", ref value);
		return value;
	}
	*/

	private readonly string TempPath = Path.Combine(
		PathMap.SubstitutePath("$(TMP)"), "GetProjectLanguages.xml");

	[DeclareAction("GetProjectVariableLanguage")]
	public void Action(out string value)
	{
		ActionCallingContext actionCallingContext = new ActionCallingContext();
		actionCallingContext.AddParameter("prj", FullProjectPath());
		actionCallingContext.AddParameter("node", "TRANSLATEGUI");
		actionCallingContext.AddParameter("XMLFile", TempPath);
		new CommandLineInterpreter().Execute("XSettingsExport", actionCallingContext);

		if (File.Exists(TempPath))
		{
			string languagesString = GetValueSettingsXml(TempPath,
				"/Settings/CAT/MOD/Setting[@name='VAR_LANGUAGE']/Val");

			if (languagesString != null)
			{
				value = languagesString;
				return;
			}
		}

		value = null;
		return;
	}

	// Returns the EPLAN Project Path
	private static string FullProjectPath()
	{
		ActionCallingContext acc = new ActionCallingContext();
		acc.AddParameter("TYPE", "PROJECT");

		string projectPath = string.Empty;
		new CommandLineInterpreter().Execute("selectionset", acc);
		acc.GetParameter("PROJECT", ref projectPath);

		return projectPath;
	}

	// Read EPLAN XML-ProjectInfo and returns the value
	private static string GetValueSettingsXml(string filename, string url)
	{
		XmlDocument xmlDocument = new XmlDocument();
		xmlDocument.Load(filename);

		XmlNodeList rankListSchemaName = xmlDocument.SelectNodes(url);
		if (rankListSchemaName != null && rankListSchemaName.Count > 0)
		{
			// Get Text from MultiLanguage or not :)
			string value = rankListSchemaName[0].InnerText;
			return value;
		}
		else
		{
			return null;
		}
	}
}
Von |2017-11-09T11:22:16+01:002016-01-11|EPLAN, EPLAN-Scripts|

XPrjActionProjectCreateBaseProject

Mit dieser inoffiziellen Action ist es möglich per Script aus einem Projekt ein Basisprojekt zu erstellen:

XPrjActionProjectCreateBaseProject

Parameter:

  • PROJECTfull name of the project
  • TARGETfull name of the target file
Von |2017-11-09T11:22:18+01:002015-12-15|EPLAN, EPLAN-Scripts|

EPLAN5 Konvertierung

Ach… auf meine alten P8 Tage darf ich noch EPLAN5 Projekte konvertieren… das freut mich.
Weniger freut es mich dass man im Scripting dann garnicht weiß, wo EPLAN die *.elk Datei erzeugt.

Komischerweise wird hier eine Großbuchstabenkonvertierung gemacht…

Darum hier mal die Routine wie man von einem EPLAN5 Projekt die Projektdatei von P8 ermittelt:

private string GetNewP8ProjectFromEplan5Import(string path)
{
	var diffWithFilename = path.Replace(ProjectsPath, ""); // FolderA\ProjectA.P

	FileInfo fi = new FileInfo(diffWithFilename);

	var diffWithoutFilename = diffWithFilename.Replace(fi.Name, "").ToUpper(); // FOLDERA\ProjectA.P
	var filename = fi.Name.Replace(".P", ".elk"); // ProjectA.elk			

	var project = Path.Combine(DestinationPath, diffWithoutFilename, filename);

	return project;
}

Danach kann z.B. das Projekt geöffnet, oder auch Actions ausgeführt werden.

Von |2017-11-09T11:22:18+01:002015-12-04|EPLAN, EPLAN-Scripts|
Nach oben