EPLAN-Scripts

Script Debugging: Debugger.IsAttached

Ich hatte hier mal beschrieben wie man den Debugger automatisch anhält… Leider zeigt EPLAN einen Fehler wenn kein Visual Studio dran hängt.
Es geht wie immer besser… Nutzt das hier, dann hält Visual Studio nur an wenn die Einstellung für das Debugging aktiv ist und Visual Studio an EPLAN.exe hängt:

if (Debugger.IsAttached)
{
  Debugger.Break(); 
}

Das kann man sich auch schön verpacken und wie folgt nutzen:

using System.Diagnostics;
using System.Windows.Forms;
using Eplan.EplApi.Scripting;
using Action = System.Action;

public class Test
{
  [Start]
  public void Function()
  {
    Debug(Debugger.Break);

    Debug(()=> MessageBox.Show("Hallo"));

    Debug(() =>
    {
      MessageBox.Show("Hallo");
    });
  }

  private void Debug(Action action)
  {
    if (Debugger.IsAttached)
    {
      action.Invoke();
    }
  }
}

Der Debugger wird nur angehalten wenn Visual Studio dran hängt. Auch die MessageBoxen werden nur angezeigt wenn das der Fall ist. Man kann mit der dritten Varianten auch mehrere Zeilen Code ausführen. Ist zwar nur syntaktischer Zucker, aber denke wird bei mir Anwendung finden.

Von |2018-01-26T15:08:40+01:002018-01-26|EPLAN, EPLAN-Scripts|

Script Debugging: Attach to Process

Für das Script-Debuggen muss man sich ja an den EPLAN Prozess hängen… Das kann man auch recht schön automatisieren.

Hier der Code für das Makro:

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) 
    {
        foreach(Process proc in DTE.Debugger.LocalProcesses)
        {
            if(proc.Name.ToString().EndsWith("EPLAN.exe"))
            {
                proc.Attach();
                return;
            }
        }

        System.Windows.MessageBox.Show("Process running the EPLAN was not found.");
    }
}

Ich habs das gleich in eine Toolbar gepackt zusammen mit Detach All, dann kann ich Visual Studio wieder davon lösen.

Von |2018-01-26T14:44:22+01:002018-01-12|EPLAN, EPLAN-Scripts|

Workaround: Projekteinstellungen werden nicht aktualisiert

Werden bestimmte Projekteinstellungen (wie z.B. Normblatt) geändert, kommt die Änderung zwar in der Oberfläche an, aber EPLAN “weiß davon noch nichts”.
Als Workaround einfach diesen Code nach dem Setzen der Einstellungen ausführen:

new EventManager().Send("PageManagement.ProjectSettings.Changed", new EventParameterString());
Von |2018-01-11T12:46:57+01:002018-01-11|EPLAN, EPLAN-Scripts|

SelectionSet pages

Ich hab hier schon ein paar Scripte bereitgestellt welche über SelectionSet die markierten Seiten einlesen.

Dieses kleine Script dient als Kopiervorlage und geht über alle markierte Seiten und springt diese auch an. Dadurch kann man z.B. Seiteneigenschaften setzen usw.

using System;
using System.Diagnostics;
using System.Threading;
using System.Windows.Forms;
using Eplan.EplApi.ApplicationFramework;
using Eplan.EplApi.Base;
using Eplan.EplApi.Scripting;

class Program
{
    [Start]
    public void Action()
    {
        // Get selected pages
        var pages = GetPages();

        // Setup progressbar
        Progress progress = new Progress("EnhancedProgress");        
        progress.SetTitle("Do Something with pages");            
        progress.SetAllowCancel(true);               
        progress.ShowImmediately();
        progress.SetNeededSteps(pages.Length + 1);

        try
        {
            // Do something with pages
            foreach (var page in pages)
            {
                progress.SetActionText(page);
                progress.Step(1);

                SelectPage(page);

                MessageBox.Show(page, "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
        catch (Exception exception)
        {
            MessageBox.Show(exception.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
        finally
        {
            progress.EndPart(true);
        }
    }

    private static string[] GetPages()
    {
        ActionCallingContext actionCallingContext = new ActionCallingContext();
        string pagesString = string.Empty;
        actionCallingContext.AddParameter("TYPE", "PAGES");
        new CommandLineInterpreter().Execute("selectionset", actionCallingContext);
        actionCallingContext.GetParameter("PAGES", ref pagesString);
        string[] pages = pagesString.Split(';');
        return pages;
    }

    private void SelectPage(string page)
    {
        ActionCallingContext actionCallingContext = new ActionCallingContext();
        actionCallingContext.AddParameter("PAGENAME", page);
        new CommandLineInterpreter().Execute("edit", actionCallingContext);
    }
}

 

Von |2017-11-09T11:16:25+01:002017-10-27|EPLAN, EPLAN-Scripts|

Action überschreiben

Es ist im Scripting möglich Actions von EPLAN auch zu überschreiben. Das sollte aber mit großer Vorsicht geschehen.
Einen konkreten Anwendungsfall hab ich in einem fertigen Script schon mal hier implementiert.

SGB Markus aus dem CAD.de Forum, vielen Dank dafür, hat vom grandiosen API-Support auch eine Lösung bekommen um Parameter abzufragen. Dazu muss der Parametername bekannt sein. Diesen einfach als Parameter in die Methode und fertig :^)

using Eplan.EplApi.ApplicationFramework;
using Eplan.EplApi.Scripting;

class Program
{
    [DeclareAction("GfDlgMgrActionIGfWind", 50)]
    public void Action(string function)
    {
        // Do something before action is called
        switch (function.ToLower())
        {
            case "copy":
                // Do something at copy
                break;

            case "cut":
                // Do something at cut
                break;

            case "paste":
                // Do something at paste
                break;
        }

        // Call the original action
        ActionManager actionManager = new ActionManager();
        Eplan.EplApi.ApplicationFramework.Action action = actionManager.FindBaseActionFromFunctionAction(true);
        ActionCallingContext actionCallingContext = new ActionCallingContext();
        actionCallingContext.AddParameter("function", function); // add parameter again
        action.Execute(actionCallingContext);
    }
}

 

Von |2017-12-07T13:37:20+01:002017-10-22|EPLAN, EPLAN-Scripts|
Nach oben