EPLAN

SetSettingExampleWindowLocation

Noch ein Beispiel um mit Settings zu arbeiten.

Hier wird die Location (Position) des Fensters gespeichert.

Ich habe hier bewusst mit stillen Exceptions gearbeitet um sicherzustellen, dass der Form auch geschlossen werden kann.

Leider konnte ich nicht mit numerischen Settings arbeiten, denke das diese zwar als INT in der Dokumentation beschrieben werden, aber EPLAN sie als UINT verarbeitet. Negative Werte sind nicht möglich sind (z.B. zweiter Bildschirm links: X < 0)

SetSettingExampleWindowLocation (1427 Downloads )

    private void SettingsGet()
    {
        if (!oSettings.ExistSetting(SettingPathWindowLocation)) // Create setting
        {
            oSettings.AddStringSetting(
                SettingPathWindowLocation,
                new string[] {},
                new string[] {},
                "Location of the form",
                new string[] {},
                ISettings.CreationFlag.Insert
                );
        }
        else // Get setting
        {
            try
            {
                this.Location = new Point(
                    Convert.ToInt32(oSettings.GetStringSetting(SettingPathWindowLocation, 0)),
                    Convert.ToInt32(oSettings.GetStringSetting(SettingPathWindowLocation, 1))
                    );
                Refresh();
            }
            catch (System.Exception ex)
            {
                //MessageBox.Show(ex.Message);
            }
        }
    }

    private void SettingsSet()
    {
        try
        {
            oSettings.SetStringSetting(SettingPathWindowLocation, this.Location.X.ToString(), 0);
            oSettings.SetStringSetting(SettingPathWindowLocation, this.Location.Y.ToString(), 1);
        }
        catch (System.Exception ex)
        {
            //MessageBox.Show(ex.Message);
        }
    }

 

Von |2017-11-09T12:23:47+01:002012-05-25|EPLAN, EPLAN-Scripts|

SetSortCode

Endlich darf ich mal auf einen anderen EPLAN-Blog hinweisen. Dieser ist englischsprachig und wird von Luc Morin gepflegt. Die Seite findet ihr unter http://www.stlm.ca/.

An dieser Stelle vielen Dank!

Mit dem Script wird das Sortieren bzw. Nummerieren vereinfacht. Am besten seht ihr euch das Beispielvideo von Luc an.

 

 

Das Script ist auf Github zu finden:

SetSortCode

//Created by Luc Morin, November 2011
//http://www.stlm.ca
public class MultiLevelSortCode
{
	[DeclareAction("SetSortCodeAction")]
	public void SetSortCodeAction()
	{
		//Use a Command Line Interpreter to call the Action
		CommandLineInterpreter CLI = new CommandLineInterpreter();

		Eplan.EplApi.Base.Settings set = new Eplan.EplApi.Base.Settings();
		if(!set.ExistSetting("USER.SCRIPTS.SORTCODE"))
		{
			bool bOk = set.AddNumericSetting("USER.SCRIPTS.SORTCODE",  new int[] { 0 },
				new Range[] { new Range { FromValue = 0, ToValue = 32768}}, "Sort code setting", new int[] { 0 },
				ISettings.CreationFlag.Insert);
		}

		int index = set.GetNumericSetting("USER.SCRIPTS.SORTCODE", 0);

		ActionCallingContext ctx1 = new ActionCallingContext();
		ctx1.AddParameter("propertyID","20809"); //Sort code
		ctx1.AddParameter("propertyIndex","0");
		ctx1.AddParameter("propertyValue", index.ToString());
		CLI.Execute("XEsSetPropertyAction", ctx1);

		set.SetNumericSetting("USER.SCRIPTS.SORTCODE", ++index, 0);

		return;

	}

	[DeclareMenu]
	public void SetSortCodeMenuFunction()
	{
		Eplan.EplApi.Gui.Menu oMenu = new Eplan.EplApi.Gui.Menu();
		oMenu.AddMenuItem("Set sort code", "SetSortCodeAction");
	}

	[DeclareAction("ResetSortCodeAction")]
	public void ResetSortCodeAction()
	{
		//Use a Command Line Interpreter to call the Action
		CommandLineInterpreter CLI = new CommandLineInterpreter();

		Eplan.EplApi.Base.Settings set = new Eplan.EplApi.Base.Settings();
		if(!set.ExistSetting("USER.SCRIPTS.SORTCODE"))
		{
			bool bOk = set.AddNumericSetting("USER.SCRIPTS.SORTCODE",  new int[] { 0 },
				new Range[] { new Range { FromValue = 0, ToValue = 32768}}, "Sort code setting", new int[] { 0 },
				ISettings.CreationFlag.Insert);
		}

		set.SetNumericSetting("USER.SCRIPTS.SORTCODE", 0, 0);

		return;

	}

	[DeclareMenu]
	public void ResetSortCodeMenuFunction()
	{
		Eplan.EplApi.Gui.Menu oMenu = new Eplan.EplApi.Gui.Menu();
		oMenu.AddMenuItem("Reset sort code", "ResetSortCodeAction");
	}

}
Von |2017-11-09T12:23:47+01:002012-05-22|EPLAN, EPLAN-Scripts|

SetStringSettingExamplePath

Anbei ein Beispiel wie man die Settings nutzen kann.

Mit diesem Script kann ein Pfad gesetzt werden. Dieser wird gespeichert und beim erneuten Ausführen des Scriptes geladen.

SetSettingExamplePath (1567 Downloads )

 

private void frmSetSettingExamplePath_Load(object sender, System.EventArgs e)
{
    // Check if setting exists
    if (!oSettings.ExistSetting(SettingPath))
    {
        // Add setting
        oSettings.AddStringSetting(
            SettingPath,
            new string[] {},
            new string[] {},
            "FolderBrowseDialog Path",
            new string[] {@"Default value of test setting"},
            ISettings.CreationFlag.Insert
            );
        // Add setting value
        oSettings.SetStringSetting(SettingPath, Environment.GetFolderPath(Environment.SpecialFolder.Desktop), 0);
        txtPath.Text = oSettings.GetStringSetting(SettingPath, 0);
    }
    else
    {
        // Load values
        txtPath.Text = oSettings.GetStringSetting(SettingPath, 0);
    }
}

private void btnPath_Click(object sender, System.EventArgs e)
{
    // Check if directory exists
    if (Directory.Exists(txtPath.Text))
    {
        fbd.SelectedPath = txtPath.Text;
    }
    else
    {
        fbd.SelectedPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
    }

    // Set path to setting
    if (fbd.ShowDialog() == DialogResult.OK)
    {
        txtPath.Text = fbd.SelectedPath;
        oSettings.SetStringSetting(SettingPath, fbd.SelectedPath, 0);
    }
}
Von |2017-11-09T12:23:47+01:002012-05-16|EPLAN, EPLAN-Scripts|

SetStringSetting

Weiß ja nicht ob ihr es wusstet, ich nicht… Man kann in EPLAN eigene Settings erstellen und dann (wie bekannt) abrufen.

Das ermöglicht einiges im Scripting. So können Pfade, Fensterpositionen, usw. gespeichert werden.

Anbei ein Beispiel um ein String Setting zu erstellen und diesem Werte zuzuweisen.

SetStringSetting (1217 Downloads )

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

public class SetStringSetting
{
    [Start]
    public void SetStringSettingVoid()
    {
        const string SettingPath = "USER.SCRIPTS.SUPLANUS";
        Eplan.EplApi.Base.Settings oSettings = new Eplan.EplApi.Base.Settings();

        // Check if setting exists
        if (oSettings.ExistSetting(SettingPath))
        {
            oSettings.DeleteSetting(SettingPath);
            MessageBox.Show("Setting removed.", SettingPath);
        }

        // Add setting
        oSettings.AddStringSetting(
            SettingPath,
            new string[] {},
            new string[] {},
            "My setting from Suplanus",
            new string[] {@"Default value of test setting"},
            ISettings.CreationFlag.Insert
            );

        // Add setting values
        oSettings.SetStringSetting(SettingPath, "Message 0", 0);
        oSettings.SetStringSetting(SettingPath, "Message 1", 1);
        oSettings.SetStringSetting(SettingPath, "Message 2", 2);
        MessageBox.Show("Setting OK.", SettingPath);

        // Show setting values
        string value = oSettings.GetStringSetting(SettingPath, 1);
        MessageBox.Show("Value of Index " + 1 + ":\n" + value, SettingPath);
    }
}
Von |2017-11-09T12:23:47+01:002012-05-14|EPLAN, EPLAN-Scripts|

InsertPageMacro

Anbei eine Möglichkeit ein Seitenmakro per Script einzufügen. Diese Action ist nicht von EPLAN dokumentiert.

InsertPageMacro (1706 Downloads )

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

public class InsertPageMacro
{
    [Start]
    public void InsertPageMacroVoid()
    {
        string strFilename = @"C:\test.emp";

        ActionCallingContext oAcc = new ActionCallingContext();
        CommandLineInterpreter oCLI = new CommandLineInterpreter();

        oAcc.AddParameter("filename", strFilename);
        oCLI.Execute("XMInsertPageMacro", oAcc);
    }
}
Von |2017-11-09T12:23:49+01:002012-05-09|EPLAN, EPLAN-Scripts|
Nach oben