Blog

CustomPropertyEditor

Heute gibts mal wieder ein Schmankerl. Gleich am Anfang vielen Dank an Birdo für die Bereitstellung.

Die versteckte Action RegisterCustomPropertyEditorAction welche nicht dokumentiert ist, kann uns das Leben leichter machen. Mit Hilfe dieser Action könnt ihr eigene Auswahldialoge für Projekteigenschaften erstellen.

CustomPropertyEditor

Birdo hat das ganze auch offen gehalten, um dynamisch über eine INI-Datei, diese für einzelne Property-Ids zu setzen.

Einfach die INI-Dateien mit dem Schema PropertyId.Index.Schreibgeschütz.txt erstellen. Der Inhalt ist Tab-getrennt Value[TAB]Description.

CustomPropertyEditor (9056 Downloads )

 

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

public class CustomPropertyEditor : System.Windows.Forms.Form
{
    public string PathIni = @"C:\Test\CustomPropertyEditor\";

    public static CustomPropertyEditor frm = new CustomPropertyEditor();
    public static string ValueNew = string.Empty;

    // Setup on startup EPLAN
    [DeclareEventHandler("onMainStart")]
    public void Startup()
    {
        RegisterCustomPropertyEditor();
    }

    [DeclareRegister]
    public void RegisterCustomPropertyEditor()
    {
        LoadScript("true");
    }

    [DeclareUnregister]
    public void UnregisterCustomPropertyEditor()
    {
        LoadScript("false");
    }

    private void LoadScript(string register)
    {
        foreach (string FullFilename in Directory.GetFiles(PathIni))
        {
            try
            {
                string Filename = Path.GetFileNameWithoutExtension(FullFilename);
                if (Filename != null)
                {
                    string[] parameters = Filename.Split('.');

                    Eplan.EplApi.ApplicationFramework.ActionCallingContext acc =
                        new Eplan.EplApi.ApplicationFramework.ActionCallingContext();
                    acc.AddParameter("Register", register);
                    acc.AddParameter("Action", "CustomPropertyEditor");
                    acc.AddParameter("PropertyId", parameters[0]);
                    acc.AddParameter("PropertyIndex", parameters[1]);
                    acc.AddParameter("Editable", parameters[2]);
                    new CommandLineInterpreter().Execute("RegisterCustomPropertyEditorAction", acc);

                    BaseExceptionMessage("RegisterCustomPropertyEditorAction: " +
                                         "PropertyId:" + parameters[0] +
                                         " PropertyIndex:" + parameters[1] +
                                         " Editable:" + parameters[2]);
                }
            }
            catch (System.Exception ex)
            {
                BaseExceptionError("RegisterCustomPropertyEditorAction: " + ex.Message);
            }
        }
    }

    [DeclareAction("CustomPropertyEditor")]
    public void Function(int PropertyId, int PropertyIndex, int DbObjectId, ref string Value, out int DialogModalResult, out string DialogModified)
    {
        // form     
        frm.lblPropertyId.Text = PropertyId.ToString();
        frm.lblPropertyIndex.Text = PropertyIndex.ToString();
        frm.lblDbObjectId.Text = DbObjectId.ToString();
        frm.lblCurrentValue.Text = Value;
        frm.ShowDialog();

        // values
        DialogModified = "1";

        if (frm.DialogResult == DialogResult.OK)
        {
            DialogModalResult = 1;
            Value = ValueNew;
        }
        else
        {
            DialogModalResult = 0;
        }
    }

    private static void BaseExceptionMessage(string message)
    {
        Eplan.EplApi.Base.BaseException bexMessage = new BaseException(message, MessageLevel.Message);
        bexMessage.FixMessage();
    }

    private static void BaseExceptionError(string error)
    {
        Eplan.EplApi.Base.BaseException bexMessage = new BaseException(error, MessageLevel.Error);
        bexMessage.FixMessage();
    }

    private void CustomPropertyEditor_Load(object sender, System.EventArgs e)
    {
        // Search for INI-File
        string FileIni = string.Empty;
        foreach (string file in Directory.GetFiles(PathIni).Where(file => file.StartsWith(PathIni + lblPropertyId.Text + "." + lblPropertyIndex.Text)))
        {
            FileIni = file;
            break;
        }

        // Listview
        if (File.Exists(FileIni))
        {
            livi.Items.Clear();
            string[] lines = File.ReadAllLines(FileIni, Encoding.UTF8);
            foreach (string line in lines)
            {
                string[] items = line.Split('\t');
                ListViewItem item = new ListViewItem(items[0]);
                item.SubItems.Add(items[1]);
                livi.Items.Add(item);
            }
            livi.Sorting = SortOrder.Ascending;
            livi.Sort();
            livi.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
        }
        else
        {
            MessageBox.Show("INI-File not found:\n" + FileIni, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
    }

    private void btnCancel_Click(object sender, System.EventArgs e)
    {
        this.Close();
    }

    private void btnOk_Click(object sender, System.EventArgs e)
    {
        Ok();
    }

    private void Ok()
    {        
        try
        {
            ValueNew = livi.SelectedItems[0].SubItems[0].Text;
            this.DialogResult = DialogResult.OK;
            this.Close();
        }
        catch (System.Exception)
        {
            MessageBox.Show("No value selected", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
        }

    }

    private void livi_DoubleClick(object sender, System.EventArgs e)
    {
        Ok();
    }

}
Von |2017-11-09T12:23:44+01:002013-08-06|EPLAN, EPLAN-Scripts|

FEZ Game-O

Hab hier schon lange nichts mehr über den Gadgeteer gepostet… Mir fehlte einfach die Zeit, bzw. ist immer noch so. Ich habe einige Projekte im Kopf und hoffe Sie bald umsetzen zu können.

Wollte euch nur kurz das Kickstarter-Projekt FEZ Game-O vorstellen. Finde es einfach nur klasse. Denke gerade für Kinder/Jugendliche ist es eine tolle Sache hier in die Programmierung bzw. Hardware einzusteigen.

1

Werde mir vorerst zwar noch keinen kaufen, da ich ja noch einiges hier habe, was noch programmiert werden will.

Das Projekt hat ihr Ziel schon erreicht, aber ihr könnt es noch unterstützen. Später wird die Hardware von GHI vertrieben.

42b1b15879d49924fa8557ee616c0c9b_large

Von |2018-05-14T15:22:53+02:002013-08-01|Gadgeteer, NETMF|

Webspace Umzug #3

Die Domain ist nun auch umgezogen und es sollte nun auch wieder suplanus.de in der Adresszeile angezeigt werden, bzw. die Links richtig sein.

Ich bin, wie ihr bestimmt gemerkt habt, zu Uberspace gewechselt. Gründe? Weil die einfach toll sind. Man hat zwar keine klickibunti Weboberfläche in den meisten Fällen, aber dafür eine Bash… und das ist auch gut so.

uberspace-hosting-on-asteroids

Preis kann man selbst bestimmen, aber ich orientiere mich an meinem alten Vertrag. Der Service ist grandios. Sehr kompetente Leute die schnell Antworten. Hatte Probleme mit Email und URLs der Domain, aber war dann auch kein Problem.

Freu mich schon auf paar Spielereien im Terminal!

Von |2013-06-29T17:33:24+02:002013-06-29|Allgemein|
Nach oben