Book a Demo

Author Topic: OnPreNewElement parentId is always 0  (Read 4553 times)

stao

  • EA User
  • **
  • Posts: 137
  • Karma: +0/-0
    • View Profile
OnPreNewElement parentId is always 0
« on: May 15, 2010, 06:12:39 am »
Hi everyone,

for some weird reason the parentId ( from Info.get(2) )
is always 0.
What i want to do is to check the parent elements stereotype.
here is my code:

public bool EA_OnPreNewElement(EA.Repository Repository, EA.EventProperties Info)
        {
int parentId = (int)((long)((EA.EventPropertyClass)Info.Get(1)).Value);
            System.Windows.Forms.MessageBox.Show(Info.Get(2).Value.ToString());

thx for your time.

Paolo F Cantoni

  • EA Guru
  • *****
  • Posts: 8626
  • Karma: +259/-129
  • Inconsistently correct systems DON'T EXIST!
    • View Profile
Re: OnPreNewElement parentId is always 0
« Reply #1 on: May 15, 2010, 09:36:24 am »
Do a search, there was a topic on it recently...

Paolo
Inconsistently correct systems DON'T EXIST!
... Therefore, aim for consistency; in the expectation of achieving correctness....
-Semantica-
Helsinki Principle Rules!

stao

  • EA User
  • **
  • Posts: 137
  • Karma: +0/-0
    • View Profile
Re: OnPreNewElement parentId is always 0
« Reply #2 on: May 15, 2010, 07:09:23 pm »
I already did but didnt find anything useful..
My only Problem is that EA.EventProperties Info doesnt seem to carry the parentId although it should to as it can be found in the EA Help.
I guess i make a mistake with the typecasting.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: OnPreNewElement parentId is always 0
« Reply #3 on: May 17, 2010, 04:01:15 pm »

Aaron B

  • EA Administrator
  • EA User
  • *****
  • Posts: 941
  • Karma: +18/-0
    • View Profile
Re: OnPreNewElement parentId is always 0
« Reply #4 on: May 17, 2010, 04:29:40 pm »
Just to make sure there is no confusion - the ParentID is not the ID of the Package (in case that's what you were expecting).  The parentId returned in the EventProperties for the EA_OnPreNewElement event will only contain a value if the new element is the child of another element.

Also, in your code example you are assigning the value of Info.Get(1) to your parentId variable instead of Info.Get(2), and your casting seems a little strange.  Should this be as follows?

Code: [Select]
int parentId = (int)((EA.EventProperty)info.Get(2)).Value;

stao

  • EA User
  • **
  • Posts: 137
  • Karma: +0/-0
    • View Profile
Re: OnPreNewElement parentId is always 0
« Reply #5 on: May 17, 2010, 04:50:41 pm »
yeah i see
thx both of you.
i solved the problem by checking the parents Stereotype in the onPostNewElement Method and delete the element if the parent is not correct.
Do you see a "smarter" way i can solve this?
I have 2 Stereotypes ( SDM_Object, SDM_Activity )
for my Addin SDM_Objects should only be created as sub Elements of SDM_Activity.