Book a Demo

Author Topic: Modifying element in EA_OnPostNewElement  (Read 3082 times)

Krzysztof Swiatkowski

  • EA User
  • **
  • Posts: 76
  • Karma: +0/-0
  • Understanding is a three-edged sword
    • View Profile
Modifying element in EA_OnPostNewElement
« 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;
      }
    }
  }
}
« Last Edit: July 05, 2008, 07:44:36 am by ged »
If I put you finger in the eye
then you have finger in the eye
and I have finger in the eye
but it's not the same

Krzysztof Swiatkowski

  • EA User
  • **
  • Posts: 76
  • Karma: +0/-0
  • Understanding is a three-edged sword
    • View Profile
Re: Modifying element in EA_OnPostNewElement
« Reply #1 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
If I put you finger in the eye
then you have finger in the eye
and I have finger in the eye
but it's not the same

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: Modifying element in EA_OnPostNewElement
« Reply #2 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
No, you can't have it!