Sparx Systems Forum

Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: Tehila1 on August 03, 2014, 09:17:59 pm

Title: Get the New Element
Post by: Tehila1 on August 03, 2014, 09:17:59 pm
Hello,

I use the EA_OnPostNewDiagramObject(EA.Repository Repository, EA.EventProperties Info) method to change diagram objects properties.

I would like to get the EA.Element that is just created.
How can I do it?
Thanks!
Title: Re: Get the New Element
Post by: qwerty on August 03, 2014, 10:29:42 pm
Read the help:
Info EA.EventProperties Contains the following EventProperty objects for the new element:

· ID: A long value corresponding to the ElementID of the object that has been added to the diagram

· DiagramID: A long value corresponding to the DiagramID of the diagram to which the object has been added

· DUID: A string value for the DUID; can be used with
Diagram.GetDiagramObjectByID to retrieve the new DiagramObject
  
q.
Title: Re: Get the New Element
Post by: Tehila1 on August 03, 2014, 11:37:09 pm
Quote
Read the help:
Info EA.EventProperties Contains the following EventProperty objects for the new element:

· ID: A long value corresponding to the ElementID of the object that has been added to the diagram

· DiagramID: A long value corresponding to the DiagramID of the diagram to which the object has been added

· DUID: A string value for the DUID; can be used with
Diagram.GetDiagramObjectByID to retrieve the new DiagramObject
  
q.

Thanks,
I have in hand the EA.EventProperty named ID, but where the ID number is saved?

The EventProperty name is 'ID', and its desrcription is 'A long value corresponding to the ElementID of the object that has been added to the diagram', but I cannot manage its value.

Thanks in advance!
Title: Re: Get the New Element
Post by: ZuluTen on August 04, 2014, 01:50:42 am
When I used the EA_OnPostNewElement instruction I had to convert the resulting event property called 'Info' to a string using a line:
Code: [Select]

strReport = EventPropertiesToString(Info)

I then had to strip out the non numeric characters to be left with a numeric string.
Title: Re: Get the New Element
Post by: Tehila1 on August 04, 2014, 09:37:37 pm
Quote
When I used the EA_OnPostNewElement instruction I had to convert the resulting event property called 'Info' to a string using a line:
Code: [Select]

strReport = EventPropertiesToString(Info)

I then had to strip out the non numeric characters to be left with a numeric string.

I convert the info as you suggested, using C#:
string strReport = Info.ToString();
Result: strReport contains "EA.EventPropertyClass"

This is probably not what you got as result.
What is missing?
Title: Re: Get the New Element
Post by: qwerty on August 04, 2014, 11:16:39 pm
RTFM:

An EventProperties object is passed to BroadcastFunctions to facilitate parameter passing.

EventProperties Attributes

Attribute
 Type
 Notes
 
Count
 Long
 Read only

The number of parameters being passed to this broadcast event.

 
 
ObjectType
 ObjectType
 Read only

Distinguishes objects referenced through a Dispatch interface.

 
 

EventProperties Methods

Method
 Type
 Notes
 
Get (
object Index)
 EventProperty
 Read only

Returns an EventProperty in the list, raising an error if Index is out of range.

Parameters:

· Index: Variant - can either be a number representing a zero-based index into the array, or a string representing the name of the EventProperty: for example, Props.Get(3) or Props.Get("ObjectID")
  
(see the help directly, it's better formatted there)

q.
Title: Re: Get the New Element
Post by: Aaron B on August 05, 2014, 10:25:16 am
For C#, you should be able to get references to the Element, the Diagram and the DiagramObject using something like:

Code: [Select]
int ElementID = int.Parse(info.Get("ID").Value.ToString());
int DiagramID = int.Parse(info.Get("DiagramID").Value.ToString());
string DUID = info.Get("DUID").Value.ToString();

EA.Element theElement = repository.GetElementByID(ElementID);
EA.Diagram theDiagram = repository.GetDiagramByID(DiagramID);
EA.DiagramObject theObject = theDiagram.GetDiagramObjectByID(ElementID, DUID);

Note: I think Diagram.GetDiagramObjectByID was added in EA 10.
Title: Re: Get the New Element
Post by: bachus on August 05, 2014, 05:53:11 pm
Hello,

I'm also facing problem getting the elementID.
I have try to get it as proposed :
Code: [Select]
int ElementID = int.Parse(info.Get("ID").Value.ToString());
But I'm always getting an error "index is out of range".
It seems a normal error specified in the manual for the "EventProperties Methods".
Whatever I'm passing as objectIndex (e.g. 1;0;"ID"...) I'm always getting this error.

Could you lighten this objectIndex question ?
Thanks !
Title: Re: Get the New Element
Post by: bachus on August 05, 2014, 07:51:27 pm
Quote
Hello,

I'm also facing problem getting the elementID.
I have try to get it as proposed :
Code: [Select]
int ElementID = int.Parse(info.Get("ID").Value.ToString());
But I'm always getting an error "index is out of range".
It seems a normal error specified in the manual for the "EventProperties Methods".
Whatever I'm passing as objectIndex (e.g. 1;0;"ID"...) I'm always getting this error.

Could you lighten this objectIndex question ?
Thanks !

When I'm using :
Code: [Select]
MessageBox.Show(info.GetType().ToString())
I'm getting "System.__ComObject" as output value.
Is it due to a missing library  or Reference ?
Title: Re: Get the New Element
Post by: qwerty on August 05, 2014, 09:28:37 pm
Have you tried printing info.Get("ID").Value? Its probably a string and does not have a ToString method.

I for myself have tested the method and it worked (after some struggling with my own faults) as designed. Just the DUID seems to return an empty value but I wouldn't know what for that parameter would be useful anyway.

q.
Title: Re: Get the New Element
Post by: bachus on August 05, 2014, 10:55:24 pm
I got  something to work with using  
Code: [Select]
int ElementID = int.Parse(info.Get("ElementID").Value.ToString());
I'm using EA version: 11.0.1103
It is strange...
Title: Re: Get the New Element
Post by: qwerty on August 06, 2014, 12:21:48 am
Looks like you use OnPostNewElement, not OnPostNewDiagramObject.

q.
Title: Re: Get the New Element
Post by: Tehila1 on August 06, 2014, 07:05:01 pm
Quote
For C#, you should be able to get references to the Element, the Diagram and the DiagramObject using something like:

Code: [Select]
int ElementID = int.Parse(info.Get("ID").Value.ToString());
int DiagramID = int.Parse(info.Get("DiagramID").Value.ToString());
string DUID = info.Get("DUID").Value.ToString();

EA.Element theElement = repository.GetElementByID(ElementID);
EA.Diagram theDiagram = repository.GetDiagramByID(DiagramID);
EA.DiagramObject theObject = theDiagram.GetDiagramObjectByID(ElementID, DUID);

Note: I think Diagram.GetDiagramObjectByID was added in EA 10.

Thank you all for the help!
Works perfectly!