Sparx Systems Forum

Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: Krzysztof Swiatkowski on July 05, 2008, 07:38:30 am

Title: Modifying element in EA_OnPostNewElement
Post by: Krzysztof Swiatkowski on July 05, 2008, 07:38:30 am
Hi,

I am writing an add-in and I thought I could set some information for new elements. EA_OnPostNewElement seemed to be a great place but no modifications I make are visible in EA.
Code gets executed, debugger shows that values are set, changed values can be read but they are not reflected in EA.
I even checked the GUID - it is the same as in EAs new Element.

Please help! What am I doing wrong ?!?!.

Below is whole addin code :) I don't think it can get any simpler than that :)

Code: [Select]
using System;
using System.Windows.Forms;

namespace PlainSimple
{
  public class Main
  {
    public String EA_Connect(EA.Repository Repository){ return "a string"; }

    public bool EA_OnPostNewElement(EA.Repository Repository, EA.EventProperties Info)
    {
      try
      {
        EA.EventProperty prop = Info.Get(0);
        int ElementID = Int32.Parse(prop.Value.ToString());
        EA.Element elem = Repository.GetElementByID(ElementID);
        string s = "Test name";
        elem.Name = s;
        Repository.SuppressEADialogs = true;
        MessageBox.Show( String.Format("{0} == {1}",s,elem.Name) );
        return true; // only if updated
      }
      catch
      {
        MessageBox.Show("Failed");
        return false;
      }
    }
  }
}
Title: Re: Modifying element in EA_OnPostNewElement
Post by: Krzysztof Swiatkowski on July 05, 2008, 08:04:09 am
Seems really weird to answer my own post but I had a break and I saw what was missing. One line :)

Code: [Select]
...
elem.Update();
...

I didn't delete the question so maybe someone won't be making the same mistake I did -> not taking a break for too long :D

Regards
Kris
Title: Re: Modifying element in EA_OnPostNewElement
Post by: «Midnight» on July 06, 2008, 05:42:45 am
That's it all right.

The way EA works takes a bit of getting used to, and is easy to forget if you don't use it a lot.

Thanks for leaving the thread up; it will be easier for new users to spot or retrieve with a search.

David