EPLAN

GetProjectLanguages

Hatte das Script schon länger hier, aber irgendwie vergessen zu posten.

Aufgrund dieses Beitrages wurde ich daran erinnert :)

Die Funktion um Projekt-Sprachen zu erhalten war im MultiLanguageTool von EPLAN enthalten (freie API). Diese wurde aber nicht mehr entwickelt und ein Teil kam als offizielle Action… leider nicht die Projektsprachen.

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

using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Xml;
using Eplan.EplApi.ApplicationFramework;
using Eplan.EplApi.Base;
using Eplan.EplApi.Scripting;

namespace EplanScriptingProjectBySuplanus.GetProjectLanguages
{
    public class GetProjectLanguages
    {
        private readonly string TempPath = Path.Combine(
            PathMap.SubstitutePath("$(TMP)"), "GetProjectLanguages.xml");

        [DeclareAction("GetProjectLanguages")]
        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='TRANSLATE_LANGUAGES']/Val");

                if (languagesString != null)
                {
                    List<string> languages = languagesString.Split(';').ToList();
                    languages = languages.Where(obj => !obj.Equals("")).ToList();

                    StringBuilder stringBuilder = new StringBuilder();
                    for (int i = 0; i < languages.Count; i++)
                    {
                        var language = languages[i];
                        stringBuilder.Append(language);

                        // not last one
                        if (i != languages.Count - 1)
                        {
                            stringBuilder.Append("|");
                        }
                    }

                    // returns list: "de_DE|en_EN"
                    value = stringBuilder.ToString();
                    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;
            }
        }
    }
}

Download auf GitHub

Von |2018-08-17T12:29:57+02:002015-08-03|EPLAN, EPLAN-Scripts|

GetSelectedProject

Ach, ich weiß ja auch immer nicht.

Mir wurde mal gesagt man soll mit SelectionSet das aktuelle Projekt abfragen… denn mit den Pfadvariablen gibt es Probleme.

Bei mir war es aber nun in zwei Scripten der Fall dass die Abfrage nicht funktionierte.
Somit habe ich mich dazu entschlossen die Pfadvariable zu verwenden und das Problem ist seitdem nicht mehr aufgetreten.

Anbei beide Varianten…

Wie ist denn eure Meinung zu diesem Thema?

 

SelectionSet (meiner Meinung nach schlechte Wahl)

string projectname = string.Empty;
ActionCallingContext actionCallingContext = new ActionCallingContext();
CommandLineInterpreter commandLineInterpreter = new CommandLineInterpreter();
actionCallingContext.AddParameter("TYPE", "PROJECT");
commandLineInterpreter.Execute("selectionset", actionCallingContext);
actionCallingContext.GetParameter("PROJECT", ref projectname); // selected project
if (string.IsNullOrEmpty(projectname))
{
    // No project selected
}

 

Pfadvariable (meiner Meinung nach bessere Wahl)

var projectname = PathMap.SubstitutePath("$(PROJECTNAME)");
if (string.IsNullOrEmpty(projectname))
{
    // No project selected
}

 

Von |2017-11-09T11:22:20+01:002015-07-30|EPLAN, EPLAN-Scripts|

Q&A wird abgeschaltet

Da die Q&A-Sektion wenig genutzt wird und weiterhin die Fragen gerne auf CAD.de gestellt werden, macht es in meinen Augen keinen Sinn eine weitere Plattform am Laufen zu halten.

Die bestehenden Fragen lasse ich online, sollte nix verloren gehen :^)

Von |2015-12-14T11:32:14+01:002015-06-08|EPLAN|
Nach oben