EPLAN-Scripts

LogBuch

A.Robert hat uns im CAD.de Forum ein kleines Script zur Verfügung gestellt um Änderungen zu dokumentieren. Ein Changelog für den Schaltplan.
Vielen Dank dafür!

Von |2018-10-01T13:56:52+02:002018-10-01|EPLAN-Scripts|

ExtendedActionList

Mit diesem Script wird ein 3-Punkte-Button im Schaltflächen einstellen Dialog angezeigt. Er zeigt alle verfügbaren Actions an (interne, offizielle und Script-Actions).
Vielen Dank an Frank Schöneck, der mir das Script bereitgestellt hat.

Das Script ausführen und die Einstellung wird gesetzt. Wird es nochmals ausgeführt, wird die Einstellung wieder deaktiviert. Ich hab das auch mal in unser kostenloses Produkt ExtendedSettings eingefügt. Die Einstellung gibt es erst ab Version 2.5, sie ist nicht dokumentiert und wird somit von EPLAN nicht supported!

// Einstellungen-ExtendedActionList.cs
//
// Schaltet einen More-Button im Fenster "Schaltfläche einstellen"
// (Symbolleiste anpassen) neben dem Eingabefeld "Befehlszeile" frei.
// Dieser öffnet ein Fenster mit allen verfügbaren Actions.
//
// Standardmäßig auf 0 gesetzt
//
// Copyright by Frank Schöneck, 2015
// letzte Änderung: Frank Schöneck, 08.07.2015 V1.0.0, Projektbeginn
//
// für Eplan Electric P8, ab V2.5
//
//

using System.Windows.Forms;
using Eplan.EplApi.Scripting;

namespace EplanScriptingProjectBySuplanus.ExtendedActionList
{
  public class ExtendedActionList
  {
    [Start]
    public void MyFunction()
    {
      Eplan.EplApi.Base.Settings oSettings = new Eplan.EplApi.Base.Settings();
      //Einstellung auslesen
      bool bolSetting = oSettings.GetBoolSetting("USER.ModalDialogs.XSdCustomToolbarComponent.ExtendedActionList", 0);
      //wenn nicht gesetzt, setzen
      if (bolSetting == false)
      {
        oSettings.SetBoolSetting("USER.ModalDialogs.XSdCustomToolbarComponent.ExtendedActionList", true, 0);
        MessageBox.Show("Die Einstellung wurde 'aktiviert'.", "USER.ModalDialogs.XSdCustomToolbarComponent.ExtendedActionList", MessageBoxButtons.OK, MessageBoxIcon.Information);
      }
      //wenn gesetzt, zurücksetzen
      else if (bolSetting == true)
      {
        oSettings.SetBoolSetting("USER.ModalDialogs.XSdCustomToolbarComponent.ExtendedActionList", false, 0);
        MessageBox.Show("Die Einstellung wurde 'deaktiviert'.", "USER.ModalDialogs.XSdCustomToolbarComponent.ExtendedActionList", MessageBoxButtons.OK, MessageBoxIcon.Information);
      }
      return;
    }
  }
}
Von |2018-10-01T10:43:39+02:002018-09-26|EPLAN, EPLAN-Scripts|

Script Debugging: Open Debug File

Hab ja hier geschrieben wie man das attachen zu EPLAN automatisieren kann. Hier ist noch die Beschreibung wie man einen Breakpoint setzen kann. Das kann man aber direkt machen wenn die temporäre Datei geöffnet wird. Mit diesem Script (welches man dann per Toolbar wieder einbinden kann), wird die Datei automatisch geöffnet:

using EnvDTE;
using EnvDTE80;
using System.Management;
using System;

public class C : VisualCommanderExt.ICommand
{
   public void Run(EnvDTE80.DTE2 DTE, Microsoft.VisualStudio.Shell.Package package)
   {
      string _sActiveWindowName = string.Empty;
    
      if(DTE.ActiveWindow.Caption != null)
    {
        _sActiveWindowName = DTE.ActiveWindow.Caption;
              string _DebugScriptFileName = System.IO.Path.GetTempPath() + "\\Debug_" + _sActiveWindowName;
          System.IO.FileInfo oFI = new System.IO.FileInfo(_DebugScriptFileName);                   
          if(oFI.Exists)
               {            
                   DTE.ItemOperations.OpenFile(_DebugScriptFileName, Constants.vsext_vk_Debugging);
               }
          else
               {
            System.Windows.MessageBox.Show("Debug-script\n'" + _DebugScriptFileName + "'\nwas not found.");
          }        
               return;
    }    

 
   }
}
Von |2018-09-24T12:52:13+02:002018-09-25|EPLAN, EPLAN-Scripts|

Anzeigesprache per Script ermitteln

Wie so oft ist es in der API ganz einfach… Im Scripting muss man aber einmal einen Roundtrip machen…
Hier eine Action um die Anzeigesprache des Projektes per Script zu ermitteln.

Aufruf:

public void Function()
{
  var languages = GetDisplayLanguages();
  foreach (var language in languages)
  {
    MessageBox.Show(language);
  }
  return;
}

private static List<string> GetDisplayLanguages()
{
  string value = null;
  ActionCallingContext actionCallingContext = new ActionCallingContext();
  new CommandLineInterpreter().Execute("GetDisplayLanguages", actionCallingContext);
  actionCallingContext.GetParameter("value", ref value);
  var split = value.Split(';');
  var languages = split.Where(language => !string.IsNullOrEmpty(language)).ToList();
  return languages;
}

 

Script:

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

namespace EplanScriptingProjectBySuplanus.GetDisplayLanguages
{
    public class GetDisplayLanguages
  {
        [DeclareAction("GetDisplayLanguages")]
        public void Action(out string value)
        {
            // Get language from settings
            string tempFile = Path.Combine(PathMap.SubstitutePath("$(TMP)"), "GetDisplayLanguages.xml");

            ActionCallingContext actionCallingContext = new ActionCallingContext();
            actionCallingContext.AddParameter("prj", FullProjectPath());
            actionCallingContext.AddParameter("node", "TRANSLATEGUI");
            actionCallingContext.AddParameter("XMLFile", tempFile);
            new CommandLineInterpreter().Execute("XSettingsExport", actionCallingContext);

            // Needed because there is no direct access to setting
            string language = GetValueSettingsXml(tempFile, "/Settings/CAT/MOD/Setting[@name='DISPLAYED_LANGUAGES']/Val");
            value = language;
        }

        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)
            {
                string value = rankListSchemaName[0].InnerText;
                return value;
            }
            return null;
        }

        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;
        }
    }
}

 

Ihr findet das wie gewohnt auf GitHub.

Von |2019-03-14T08:30:01+01:002018-09-07|EPLAN, EPLAN-Scripts|

EPLAN Version ermitteln

Vielen Dank an nairolf für die Bereitstellung der schönen Methode um die EPLAN Version zu ermitteln. Funktioniert in API & Scripting. Man kann das dann z.B. so verwenden:

if (EplanApplicationInfo.GetActiveEplanVersion() >= 270)
{
  FlyToTheRainbowIn27();
}

Die Methode:

using System;
using System.Diagnostics;
using System.IO;
using Eplan.EplApi.Base;

namespace Suplanus.Sepla.Application
{
  public class EplanApplicationInfo
  {
    public static int GetActiveEplanVersion()
    {
      string eplanVersion = "0"; //default value = 0 to ensure, that EPLAN-version is correctly recognized 

      //try new variable $(EPLAN_VERSION) first, if not valid, no possibility to get active get active EPLAN-version
      if (PathMap.SubstitutePath("$(EPLAN_VERSION)") != "$(EPLAN_VERSION)")
      {
        eplanVersion = PathMap.SubstitutePath("$(EPLAN_VERSION)");
      }
      else
      {
        //try different method to get version of executing eplan, in case the actual version doesn't support $(EPLAN_VERSION)
        string dllFilename = Path.Combine(PathMap.SubstitutePath("$(BIN)"), "Eplan.EplApi.Baseu.dll");
        FileInfo fileInfo = new FileInfo(dllFilename);
        if (fileInfo.Exists)
        {
          var versionInfo = FileVersionInfo.GetVersionInfo(dllFilename);
          //return main-version-infos (without build number)
          if (versionInfo.ProductVersion.Length >= 5)
          {
            eplanVersion = versionInfo.ProductVersion.Substring(0, 5);
          }
        }
      }

      if (eplanVersion == "0" || eplanVersion == "$(EPLAN_VERSION)")
      {
        MultiLangString multiLangErrorText = new MultiLangString();
        multiLangErrorText.AddString(ISOCode.Language.L_de_DE, "Die aktuelle EPLAN-Version konnte nicht ermittelt werden.");
        multiLangErrorText.AddString(ISOCode.Language.L_en_US, "Unable to get actual EPLAN-version.");
        ISOCode.Language guiLanguage = new Languages().GuiLanguage.GetNumber();
        string errorText = multiLangErrorText.GetStringToDisplay(guiLanguage);
        if (String.IsNullOrEmpty(errorText))
        {
          //if actual GUI-language is not defined in multi-language-string, use en_US-text-version
          errorText = multiLangErrorText.GetStringToDisplay(ISOCode.Language.L_en_US);
        }
        new BaseException(errorText, MessageLevel.Warning).FixMessage(); 
        eplanVersion = "0";
      }
      return Convert.ToInt32(eplanVersion.Replace(".", string.Empty));
    }
  }
}

Findet Ihr auch hier auf GitHub.

Von |2022-03-28T08:08:11+02:002018-09-04|EPLAN, EPLAN-API, EPLAN-Scripts|
Nach oben