Author Topic: SysML is jumping on EA_OnPostNewElement  (Read 3483 times)

tzafrir

  • EA User
  • **
  • Posts: 127
  • Karma: +0/-0
    • View Profile
SysML is jumping on EA_OnPostNewElement
« on: March 07, 2016, 07:08:47 am »
Hi,
I have written an AddIn that jumps on EA_OnPostNewElement event.
One of the Addin functionality is getting the ID of the element that was inserted to a diagram and then deleting it from it.
Up until here everything was fine.
I then installed SysML Addin from sparxsystems site.
What happens is that the SysML started running my event, the problem is that it looked for an Id that does not exist in the model anymore and that causes a crush.
Does anyone have any idea how this issue can be resolved?

Thanks,
Tzafrir

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 7296
  • Karma: +84/-12
    • View Profile
Re: SysML is jumping on EA_OnPostNewElement
« Reply #1 on: March 07, 2016, 08:38:48 am »
For me, there's two things wrong.

1. Unless you want to trial SysML support or use SysML 1.0, the SysML add-in won't do anything for you. For a licensed user just entering the license key will enable use of SysML 1.1, 1.2, 1.3 and 1.4.

2. Deleting an element in EA_OnPostNewElement doesn't seem safe. (As you've seen) Is there a reason that you're doing that rather than handling EA_OnPreNewElement to prevent the element from being created?
Eve

support@sparxsystems.com

tzafrir

  • EA User
  • **
  • Posts: 127
  • Karma: +0/-0
    • View Profile
Re: SysML is jumping on EA_OnPostNewElement
« Reply #2 on: March 07, 2016, 05:05:36 pm »
1. I do need SysML support. currently I am using the trial version but I will get the licensed one shortly (if that affects anything)
2. I need the created element to be on the diagram since I am taking information from it, like its stereo type and coordinates on screen that I am using later on in my AddIn.
Currently I am using:
public Boolean EA_OnPostNewElement(EA.Repository repository, EA.EventProperties info)
{
    prop = (EA.EventProperty)info.Get(0);
    EA.Element newElement= repository.GetElementByID(int.Parse(prop.Value.ToString()));
}
The 2nd line is causing the SysML addIn to crush on 2nd unwanted run.

When using EA_OnPreNewElement, element is not created yet and I can get that info. Is there any other way I can get that information from the element on PreNewElement stage without it being created?
 

tzafrir

  • EA User
  • **
  • Posts: 127
  • Karma: +0/-0
    • View Profile
Re: SysML is jumping on EA_OnPostNewElement
« Reply #3 on: March 08, 2016, 08:01:58 am »
Let my clarify my last post,

The problem is not with My AddIn,
SysML has its own postEvent API in its AddIn and it is jumping on the new element probably trying to load the new element and fails because it does not exist anymore in the model.

My question is, is there anyway I can disable it, since I dont have SysML source code?


Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 7296
  • Karma: +84/-12
    • View Profile
Re: SysML is jumping on EA_OnPostNewElement
« Reply #4 on: March 08, 2016, 08:40:25 am »
No, you can't disable part of the SysML add-in. It's all or nothing. At least the SysML add-in won't be needed when you finish your trial. Could you trial EA's SysML support separately from whatever you're doing with your add-in?

Your original post said you were deleting something in that event. Clearly that's not happening in your posted code. I can't see a reason why that would crash unless perhaps the object was deleted already. (I can't remember if an exception is thrown or a null pointer is returned in case of error in GetElementByID)
Eve

support@sparxsystems.com

tzafrir

  • EA User
  • **
  • Posts: 127
  • Karma: +0/-0
    • View Profile
Re: SysML is jumping on EA_OnPostNewElement
« Reply #5 on: March 08, 2016, 05:15:17 pm »
The code that deletes the new element comes later on in my code, and it indeed deletes the new element . Then  the SysML AddIn jumps.
Is there a way to disable the SysML in some cases or under some configuration?

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 7296
  • Karma: +84/-12
    • View Profile
Re: SysML is jumping on EA_OnPostNewElement
« Reply #6 on: March 09, 2016, 08:36:44 am »
No, you can't disable part of the SysML add-in. It's all or nothing.

The code that deletes the new element comes later on in my code, and it indeed deletes the new element.

Really, don't do that. I'm only surprised that it didn't crash or corrupt your model without interaction with other add-ins. Depending on how you create an element it probably will.
« Last Edit: March 09, 2016, 08:38:19 am by Simon M »
Eve

support@sparxsystems.com

tzafrir

  • EA User
  • **
  • Posts: 127
  • Karma: +0/-0
    • View Profile
Re: SysML is jumping on EA_OnPostNewElement
« Reply #7 on: March 09, 2016, 04:53:56 pm »
Ok, i understand what I did is not a good resolution, but as suggested by your support,
Can I use  EA_OnPreNewElement, get information from the "going to be created" new element, like its stereo type,
without using:
A.EventProperty prop = (EA.EventProperty)info.Get(0);
EA.Element newElement = repository.GetElementByID(int.Parse(prop.Value.ToString()));
and then return false

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 10437
  • Karma: +343/-30
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: SysML is jumping on EA_OnPostNewElement
« Reply #8 on: March 09, 2016, 05:58:34 pm »
The stereotype is one of the properties in the EventProperty. See http://sparxsystems.com/enterprise_architect_user_guide/12.1/automation_and_scripting/broadcastprenewelement.html

I'm pretty sure Repository.GetElementByID won't give you any results in the Prenew event.

Geert

tzafrir

  • EA User
  • **
  • Posts: 127
  • Karma: +0/-0
    • View Profile
Re: SysML is jumping on EA_OnPostNewElement
« Reply #9 on: March 09, 2016, 08:32:48 pm »
I actually dont need the new Element, I just need to get data from it (stereo type and coordinates)
For the stereo type - EA_OnPreNewElement will give me the results.
For the coordinates - I see that EA_OnPreDropFromTree gives me the X\Y cordinates of the object.

Is there anyway to communicate between the two or is there an event I did not find that gives me both with the same event?
My logic is based on what I will do on the first event (EA_OnPreNewElement),
I will need to put on the diagram (maybe using EA_OnPreDropFromTree)

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 10437
  • Karma: +343/-30
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: SysML is jumping on EA_OnPostNewElement
« Reply #10 on: March 09, 2016, 08:41:19 pm »
You can store information from the first event in your class and read them in the second event no?

Geert

tzafrir

  • EA User
  • **
  • Posts: 127
  • Karma: +0/-0
    • View Profile
Re: SysML is jumping on EA_OnPostNewElement
« Reply #11 on: March 09, 2016, 09:17:39 pm »
The problem is that you dont know the order of the events, since they will jump on the same action of putting a new element on the diagram.
If there is no one event that has both properties,
I will try find a way to overcome it.

Thanks,
Tzafrir

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 10437
  • Karma: +343/-30
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: SysML is jumping on EA_OnPostNewElement
« Reply #12 on: March 09, 2016, 09:29:08 pm »
Are you sure that the order is not always the same?
And even then, there should be a way around it using the time difference.

Geert