EPLAN-Scripts

ExportProjectMissingTranslation

Luc S. hat ein Script erstellt um fehlende Übersetzungen eines Projektes zu exportieren bzw. anzuzeigen. Vielen Dank für das Bereitstellen!

Download auf GitHub

//===================================================
// LUC S.  04-07-2018
// Script Exportiert die Fehlworteliste für die eingestellte Projektsprache
//===================================================
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using System.IO;

//==========================================
using Eplan.EplApi.ApplicationFramework;
using Eplan.EplApi.Base;
using Eplan.EplApi.Scripting;

//==========================================
public class Export_Project_Missing_Translation
{
    [DeclareAction("Export_Project_Missing_Translation")]
    //[Start]
    public void Export_Txt_Fehlworte()
    {
    //=======================================================================  
    // Dialogabfrage
        const string message = "Prüfung von fehlenden Übersetzungen durchführen?";
        const string caption = "Export Fehlworteliste";
        var result = MessageBox.Show(message, caption,
                                     MessageBoxButtons.YesNo,
                                     MessageBoxIcon.Question);

        if (result == DialogResult.No)
        {
           return;
        }
     //=======================================================================
     // aktuelles Projektpfad ermitteln	
        string sProject = Get_Project();
		//sProject = sProject.Replace("File-2", "K-ELT-01");

        if (sProject == "")
        {
            MessageBox.Show("Projekt auswählen !");
            return;
        }
        //MessageBox.Show(sProject);
        
        // Projektname ermitteln
        string strProjectname = Get_Name(sProject);

     //=======================================================================
     //eingestellte Projektsprache EPLAN ermitteln 
        string strDisplayLanguage = null;
        ActionCallingContext ACCDisplay = new ActionCallingContext();
        new CommandLineInterpreter().Execute("GetDisplayLanguage", ACCDisplay);
        ACCDisplay.GetParameter("value", ref strDisplayLanguage);
        //MessageBox.Show("Language : " + strDisplayLanguage);
			
    //=======================================================================    
  	//Fehlworteliste erzeugen :
         Eplan.EplApi.ApplicationFramework.ActionCallingContext acctranslate = new Eplan.EplApi.ApplicationFramework.ActionCallingContext();
	     Eplan.EplApi.ApplicationFramework.CommandLineInterpreter CLItranslate = new Eplan.EplApi.ApplicationFramework.CommandLineInterpreter(); 
         Eplan.EplApi.Base.Progress progress = new Eplan.EplApi.Base.Progress("SimpleProgress");
         progress.BeginPart(100, "");
         progress.SetAllowCancel(true);


         string MisTranslateFile = @"c:\TEMP\EPLAN\EPLAN_Fehlworteliste_" + strProjectname + "_" + strDisplayLanguage + ".txt";
	     acctranslate.AddParameter("TYPE", "EXPORTMISSINGTRANSLATIONS");
         acctranslate.AddParameter("LANGUAGE", strDisplayLanguage);
	     acctranslate.AddParameter("EXPORTFILE", MisTranslateFile);
	     acctranslate.AddParameter("CONVERTER", "XTrLanguageDbXml2TabConverterImpl");        

	     bool sRet = CLItranslate.Execute("translate", acctranslate);

        if (!sRet)
        {
            MessageBox.Show("Fehler bei Export fehlende Übersetzungen!");
            return;
        }

       // MessageBox.Show("Fehlende Übersetzungen exportiert in : " + MisTranslateFile);

    //=================================================================
    //Fehlworteliste lesen und Zeilenanzahl ermitteln :

        int counter = 0;
        string line;
        
           if (File.Exists(MisTranslateFile))
            { 
                using (StreamReader countReader = new StreamReader(MisTranslateFile))
                {
                    while (countReader.ReadLine() != null)
                        counter++;
                }
                // MessageBox.Show("Zeilenanzahl in " + MisTranslateFile + " : " + counter);

             if (counter > 1)

                    //=================================================================
                    //Fehlworteliste öffnen falls Zeilenanzahl > 1 :

                    {
                        // MessageBox.Show("Fehlende Übersetzungen gefunden !");       
                        // Open the txt file with missing translation
                        System.Diagnostics.Process.Start("notepad.exe", MisTranslateFile);
                    }

            }  

        progress.EndPart(true);
     return;
    }

 //=======================================================================
   public string Get_Project()
    {
	try
	    {
		    // aktuelles Projekt ermitteln
		    //==========================================
		    Eplan.EplApi.ApplicationFramework.ActionManager oMngr = new Eplan.EplApi.ApplicationFramework.ActionManager();
		    Eplan.EplApi.ApplicationFramework.Action oSelSetAction = oMngr.FindAction("selectionset");
		    string sProjektT = "";
		    if (oMngr != null)
		    {
			    Eplan.EplApi.ApplicationFramework.ActionCallingContext ctx = new Eplan.EplApi.ApplicationFramework.ActionCallingContext();
			    ctx.AddParameter("TYPE", "PROJECT");
			    bool sRet = oSelSetAction.Execute(ctx);

			    if (sRet)
			    {ctx.GetParameter("PROJECT",ref sProjektT);}
			    //MessageBox.Show("Projekt: " + sProjektT);
		    }
		    return sProjektT;
        }
	    catch
 		    {return "";}
    }

   //################################################################################################
   public string Get_Name(string sProj)
   {
       try
       {
           // Projektname ermitteln
           //==========================================
           int i = sProj.Length - 5;
           string sTemp = sProj.Substring(1, i);
           i = sTemp.LastIndexOf(@"\");
           sTemp = sTemp.Substring(i + 1);
           //MessageBox.Show("Ausgabe: " + sTemp);
           return sTemp;
       }
       catch
       { return "ERROR"; }
   }

}
Von |2018-08-17T12:30:47+02:002018-07-09|EPLAN, EPLAN-Scripts|

GetProjectProperty

Dieses Script gibt es nun schon in der dritten Auflage. Ich habe die Unterstützung für benutzerdefinierte Eigenschaften hinzugefügt. Im Test des Scriptes seht ihr die verschiedenen Aufrufe:

[Start]
public void Test()
{
  string projectProperty;

  // No index
  projectProperty = GetProjectPropertyAction("10000", "0");
  MessageBox.Show("No index: " + Environment.NewLine +  projectProperty);

  // Index
  projectProperty = GetProjectPropertyAction("10901", "1");
  MessageBox.Show("Index: " + Environment.NewLine + projectProperty);

  // UserDefinied
  projectProperty = GetProjectPropertyAction("ibKastl.Project.Test", null);
  MessageBox.Show("UserDefinied: " + Environment.NewLine + projectProperty);
}

 

Script:

using System;
using System.IO;
using System.Windows.Forms;
using Eplan.EplApi.ApplicationFramework;
using Eplan.EplApi.Base;
using Eplan.EplApi.Scripting;

namespace EplanScriptingProjectBySuplanus.GetProjectProperty
{
  class GetProjectProperty
  {
    private string GetProjectPropertyAction(string id, string index)
    {
      string value = null;
      ActionCallingContext actionCallingContext = new ActionCallingContext();
      actionCallingContext.AddParameter("id", id);
      actionCallingContext.AddParameter("index", index);
      new CommandLineInterpreter().Execute("GetProjectProperty", actionCallingContext);
      actionCallingContext.GetParameter("value", ref value);
      return value;
    }

    [DeclareAction("GetProjectProperty")]
    public void Action(string id, string index, out string value)
    {
      string pathTemplate = Path.Combine(PathMap.SubstitutePath("$(MD_SCRIPTS)"),
          "GetProjectProperty", "GetProjectProperty_Template.xml");
      string pathScheme = Path.Combine(PathMap.SubstitutePath("$(MD_SCRIPTS)"),
          "GetProjectProperty", "GetProjectProperty_Scheme.xml");

      bool isUserDefinied = string.IsNullOrEmpty(index) || index.ToUpper().Equals("NULL");

      try
      {
        // Set scheme
        const string QUOTE = "\"";
        string content = File.ReadAllText(pathTemplate);

        if (isUserDefinied)
        {
          string isSelectedPropertyUserDef =
            @"<Setting name=" + QUOTE + "SelectedPropertyIdUserDef" + QUOTE + " type=" + QUOTE + "string" + QUOTE + ">" +
            "<Val>" + id + "</Val>" +
            "</Setting>";

          content = content.Replace("GetProjectProperty_ID_SelectedPropertyId", "0");
          content = content.Replace("IsSelectedPropertyIdUserDef", isSelectedPropertyUserDef);
          content = content.Replace("GetProjectProperty_INDEX", "0");
          content = content.Replace("GetProjectProperty_ID", id);
        }
        else
        {
          content = content.Replace("GetProjectProperty_ID_SelectedPropertyId", id);
          content = content.Replace("IsSelectedPropertyIdUserDef", "");
          content = content.Replace("GetProjectProperty_INDEX", index);
          content = content.Replace("GetProjectProperty_ID", id);
        }

        File.WriteAllText(pathScheme, content);

        new Settings().ReadSettings(pathScheme);

        string pathOutput = Path.Combine(
            PathMap.SubstitutePath("$(MD_SCRIPTS)"), "GetProjectProperty",
            "GetProjectProperty_Output.txt");

        // Export
        ActionCallingContext actionCallingContext = new ActionCallingContext();
        actionCallingContext.AddParameter("configscheme", "GetProjectProperty");
        actionCallingContext.AddParameter("destinationfile", pathOutput);
        actionCallingContext.AddParameter("language", "de_DE");
        new CommandLineInterpreter().Execute("label", actionCallingContext);

        // Read
        value = File.ReadAllLines(pathOutput)[0];
      }
      catch (Exception exception)
      {
        MessageBox.Show(exception.Message, "GetProjectProperty", MessageBoxButtons.OK,
            MessageBoxIcon.Error);
        value = "[Error]";
      }

    }
  }
}

 

Das Script findet Ihr wie gewohnt auf GitHub.

Von |2019-03-14T08:34:18+01:002018-03-13|EPLAN, EPLAN-Scripts|

LocationPrint

Dieses Script wurde uns freundlicherweise von Artur Netz bereitgestellt. Vielen Dank dafür! Anbei die Beschreibung & Anleitung.

 

Beschreibung

Nach Orten sortiert drucken (LocationPrint):

Mit dem Skript kann man bequem nach Orten sortiert drucken.

Man wählt die gewünschten Orte aus und diese werden ausgedruckt. Es wird dabei „detailliert“ ausgedruckt, also auch die Seiten wo im Rahmen ein anderer Ort steht.

Wen n im Feld „Ort1“ z.B. KK1 gewählt ist und im Feld „Ort2“ KK3 kommt ein Stapel Seiten bezogen auf KK1 raus und anschließend ein Stapel Seiten bezogen auf KK3.

Wenn im Feld „Ort1“ z.B. S* eingegeben wird kommen alle Seiten raus mit Bauteile bezogen au f S, z.B. S01, S02, S03…

Man erspart sich den Arbeitsschritt die „detaillierte Auswahl“ für jeden Ort einzustellen , die Seiten zu markieren und dann auszudrucken. D as ist bei großen Anlagen mit vielen O rten eine große Erleichterung . A uch die Werkstatt , ohne große Eplan Kenntnisse, kann sich bequem die passenden Seiten ausdrucken.

Das Skript lässt sich bequem per Toolbar Button aufrufen.

 

Installation

  • den Ordner „LocationPrint“ entpacken und in den Standard Skript Pfad von EPLAN kopieren.
  • das Skript laden, es wird ein neues Menü erstellt „AN-Tools“ und eine neue Toolbar „AN-Tools“ mit einem Button
  • Action starten

LocationPrint

Von |2018-03-06T08:18:47+01:002018-03-06|EPLAN, EPLAN-Scripts|

Eventlogger Update

Ich hatte ja hier mal einen Eventlogger geschrieben. Diesen habe ich jetzt erweitert. Es werden folgende Eigenschaften gespeichert:

  • Uhrzeit
  • Eventname
  • Eventparameter (falls vorhanden)

Es ist auch eine Blacklist vorhanden, da diese Events immer gefeuert werden bzw. wenn EPLAN im Idle-Modus ist.

using System;
using System.Collections.Generic;
using System.IO;
using Eplan.EplApi.ApplicationFramework;
using Eplan.EplApi.Scripting;
using EventHandler = Eplan.EplApi.ApplicationFramework.EventHandler;

public class EventLogger
{
  EventHandler eventHandler = new EventHandler();

  [DeclareRegister]
  public void Register()
  {
    eventHandler.SetEvent("*");
    EventHandlerNameFunction eventHandlerNameFunction = Event;
    eventHandler.EplanNameEvent += eventHandlerNameFunction;
  }

  [DeclareUnregister]
  public void UnRegister()
  {
    eventHandler.Dispose();
  }

  private void Event(IEventParameter eventParameter, string eventName)
  {
    // Check Blacklist
    List<string> blackList = new List<string>
    {
      "onIdle.Bool.App",
      "onLastIdle.Bool.App",
      "onTimer.UInt.App"
    };

    if (blackList.Contains(eventName))
    {
      return;
    }

    // Get Parameter
    string parameter;
    try
    {
      EventParameterString eventParameterString = new EventParameterString(eventParameter);
      parameter = eventParameterString.String;
    }
    catch
    {
      parameter = string.Empty;
    }

    // Write log
    FileInfo fileInfo = new FileInfo(@"C:\Test\Events.txt");
    using (StreamWriter streamWriter = fileInfo.AppendText())
    {
      string line = string.Format("{1}{0}{2}{0}{3}",
        "\t",
        DateTime.Now.ToString("HH:mm:ss"),
        eventName,
        parameter);

      streamWriter.WriteLine(line);
    }
  }
}

 

Von |2018-02-16T09:15:24+01:002018-02-16|EPLAN, EPLAN-Scripts|
Nach oben