Author Topic: Get the New Element  (Read 7843 times)

Tehila1

  • EA User
  • **
  • Posts: 256
  • Karma: +0/-0
    • View Profile
Get the New Element
« 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!
« Last Edit: August 03, 2014, 09:18:23 pm by avoda234 »

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Get the New Element
« Reply #1 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.

Tehila1

  • EA User
  • **
  • Posts: 256
  • Karma: +0/-0
    • View Profile
Re: Get the New Element
« Reply #2 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!

ZuluTen

  • EA User
  • **
  • Posts: 56
  • Karma: +0/-0
    • View Profile
Re: Get the New Element
« Reply #3 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.

Tehila1

  • EA User
  • **
  • Posts: 256
  • Karma: +0/-0
    • View Profile
Re: Get the New Element
« Reply #4 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?

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Get the New Element
« Reply #5 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.
« Last Edit: August 04, 2014, 11:19:55 pm by qwerty »

Aaron B

  • EA Administrator
  • EA User
  • *****
  • Posts: 941
  • Karma: +18/-0
    • View Profile
Re: Get the New Element
« Reply #6 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.

bachus

  • EA Novice
  • *
  • Posts: 18
  • Karma: +0/-0
    • View Profile
Re: Get the New Element
« Reply #7 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 !

bachus

  • EA Novice
  • *
  • Posts: 18
  • Karma: +0/-0
    • View Profile
Re: Get the New Element
« Reply #8 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 ?

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Get the New Element
« Reply #9 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.

bachus

  • EA Novice
  • *
  • Posts: 18
  • Karma: +0/-0
    • View Profile
Re: Get the New Element
« Reply #10 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...

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Get the New Element
« Reply #11 on: August 06, 2014, 12:21:48 am »
Looks like you use OnPostNewElement, not OnPostNewDiagramObject.

q.

Tehila1

  • EA User
  • **
  • Posts: 256
  • Karma: +0/-0
    • View Profile
Re: Get the New Element
« Reply #12 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!