Sparx Systems Forum
Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started 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!
-
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.
-
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!
-
When I used the EA_OnPostNewElement instruction I had to convert the resulting event property called 'Info' to a string using a line:
strReport = EventPropertiesToString(Info)
I then had to strip out the non numeric characters to be left with a numeric string.
-
When I used the EA_OnPostNewElement instruction I had to convert the resulting event property called 'Info' to a string using a line:
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?
-
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.
-
For C#, you should be able to get references to the Element, the Diagram and the DiagramObject using something like:
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.
-
Hello,
I'm also facing problem getting the elementID.
I have try to get it as proposed :
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 !
-
Hello,
I'm also facing problem getting the elementID.
I have try to get it as proposed :
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 :
MessageBox.Show(info.GetType().ToString())
I'm getting "System.__ComObject" as output value.
Is it due to a missing library or Reference ?
-
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.
-
I got something to work with using
int ElementID = int.Parse(info.Get("ElementID").Value.ToString());
I'm using EA version: 11.0.1103
It is strange...
-
Looks like you use OnPostNewElement, not OnPostNewDiagramObject.
q.
-
For C#, you should be able to get references to the Element, the Diagram and the DiagramObject using something like:
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!