Author Topic: How to add a new element on diagram creation?  (Read 7430 times)

MalkContent

  • EA User
  • **
  • Posts: 24
  • Karma: +0/-0
    • View Profile
How to add a new element on diagram creation?
« on: January 10, 2010, 07:02:05 am »
Hi,
I am currently trying to get a self made diagram (done via diagram profile) to add an element to the repository when an instance of it is created.

Is there a possibility to make it happen via profile editing?
And if not:
-how do I create Elements in the Repository
-how do I add Elements to the Diagram

I honestly searched a lot for the element creation and adding to a diagram thing and I tried a few things, but so far no luck.

EA.Element doesn't seem to posess a visible creator so I guessed it only could be added by methods of the Repository.

And as for the adding it to the diagram part, I am guessing it's done via the elements taggedvalues attribute, but I am not sure and don't know how it would be done.

Help :(

Paolo F Cantoni

  • EA Guru
  • *****
  • Posts: 8599
  • Karma: +256/-129
  • Inconsistently correct systems DON'T EXIST!
    • View Profile
Re: How to add a new element on diagram creation?
« Reply #1 on: January 10, 2010, 10:26:34 am »
Hi,

If I understand you correctly, when you create an instance in a diagram, you want to create the classifier also.

I think you'll need automation to do that.  It will need to hook into the EA event model and use the creation event of the instance to trigger the creation of the classifier.

However, I would expect other issues - like what do you do with two (or more instances) of the same classifier?

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

MalkContent

  • EA User
  • **
  • Posts: 24
  • Karma: +0/-0
    • View Profile
Re: How to add a new element on diagram creation?
« Reply #2 on: January 10, 2010, 09:44:35 pm »
I want to create an instance of a certain element when I create the instance of a specific diagram.
I already have the creation event of the diagram.
Problem is, I have no idea which methods of the repository to use to create a new instance of an element.

Paolo F Cantoni

  • EA Guru
  • *****
  • Posts: 8599
  • Karma: +256/-129
  • Inconsistently correct systems DON'T EXIST!
    • View Profile
Re: How to add a new element on diagram creation?
« Reply #3 on: January 11, 2010, 02:18:58 pm »
Quote
I want to create an instance of a certain element when I create the instance of a specific diagram.
I already have the creation event of the diagram.
Problem is, I have no idea which methods of the repository to use to create a new instance of an element.
Do you already know the classifier element that you are creating an instance of?

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

MalkContent

  • EA User
  • **
  • Posts: 24
  • Karma: +0/-0
    • View Profile
Re: How to add a new element on diagram creation?
« Reply #4 on: January 12, 2010, 03:09:52 am »
I want to add a "ActivityInitial" with the stereotype "mofsdmStart".
It is part of a custom ToolBox I build.

I am not sure if this is what you mean :/

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13288
  • Karma: +557/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: How to add a new element on diagram creation?
« Reply #5 on: January 12, 2010, 06:44:34 pm »
Then you'll have to first create the element itself, and then add it to the diagram.

To create the element get the owner element and do a addNew() to the collection of elements.
Give it the appropriate attribute values and don't forget to update. (you may have to update between setting creating the element and setting some of its attributes as well)

Then add a new go to the diagram and do addnew() to the diagramobjects collection.
again make sure to update the diagramobject after creating it. (maybe you need to update() the diagram as well, I'm not sure)

Geert

MalkContent

  • EA User
  • **
  • Posts: 24
  • Karma: +0/-0
    • View Profile
Re: How to add a new element on diagram creation?
« Reply #6 on: January 15, 2010, 12:04:36 am »
I just realized that the EA_OnPostNewDiagramm event doesn't occur after a Diagram has been created, but an object within a diagram, so I am now without a clue how to add standard elements to a diagram on it's creation.
:(

MalkContent

  • EA User
  • **
  • Posts: 24
  • Karma: +0/-0
    • View Profile
Re: How to add a new element on diagram creation?
« Reply #7 on: January 30, 2010, 09:44:00 pm »
So is there no way to create a new element in the repository upon diagram creation? :(

KP

  • EA Administrator
  • EA Expert
  • *****
  • Posts: 2919
  • Karma: +54/-3
    • View Profile
Re: How to add a new element on diagram creation?
« Reply #8 on: February 01, 2010, 09:25:52 am »
Quote
I just realized that the EA_OnPostNewDiagramm event doesn't occur after a Diagram has been created, but an object within a diagram, so I am now without a clue how to add standard elements to a diagram on it's creation.
:(
That sounds like you are using EA_OnPostNewDiagramObject. EA_OnPostNewDiagram should do exactly what you want it to do. This is what the help claims:
Quote
EA_OnPostNewDiagram notifies Add-Ins that a new diagram has been created. It enables Add-Ins to modify the diagram upon creation.
If that isn't happening then please send in a bug report with a code sample. Thanks.
The Sparx Team
[email protected]

MalkContent

  • EA User
  • **
  • Posts: 24
  • Karma: +0/-0
    • View Profile
Re: How to add a new element on diagram creation?
« Reply #9 on: February 06, 2010, 04:04:36 am »
well seemingly this method doesn't exist OR I didn't find a way to get it called

here's my code example - c# in visual studio 2005 pe

Code: [Select]
       public bool EA_OnPostNewDiagram(EA.Repository Repository, EA.EventProperties Info)
        {
            MessageBox.Show("diagram created!");
            return true;
        }

I created a variation of diagrams AND I tried to get it called like the EA_OnPostNewDiagramObject method would which I also didn't succeed in.

also the help contents only list an entry for EA_OnPostNewDiagram (Object) which - in the details - is then titled EA_OnPostNewDiagram and has a description which makes it pretty much sound like EA_OnPostNewDiagramObject:

Quote
Details

EA_OnPostNewDiagram notifies Add-Ins that a new object has been created on a diagram. It enables Add-Ins to modify the object upon creation.

This event occurs after a user has dragged a new object from the Enterprise Architect Project Browser or Resources window onto a diagram. The notification is provided immediately after the object is added to the diagram. Set Repository.SuppressEADialogs to true to suppress Enterprise Architect from showing its default dialogs.

Also look at EA_OnPreNewDiagram.

I am using EA v7.1 Academic.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13288
  • Karma: +557/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: How to add a new element on diagram creation?
« Reply #10 on: February 08, 2010, 05:34:53 am »
Quote
I am using EA v7.1 Academic.
That might be your problem. Have you tried using the latest version?

Geert

KP

  • EA Administrator
  • EA Expert
  • *****
  • Posts: 2919
  • Karma: +54/-3
    • View Profile
Re: How to add a new element on diagram creation?
« Reply #11 on: February 08, 2010, 08:58:18 am »
EA_OnPostNewDiagramObject was added at version 7.1.833
The Sparx Team
[email protected]

MalkContent

  • EA User
  • **
  • Posts: 24
  • Karma: +0/-0
    • View Profile
Re: How to add a new element on diagram creation?
« Reply #12 on: February 09, 2010, 10:10:03 am »
that is my version exacly

but does this version already include EA_OnPostNewDiagram?
« Last Edit: February 09, 2010, 10:10:24 am by MalkContent »

KP

  • EA Administrator
  • EA Expert
  • *****
  • Posts: 2919
  • Karma: +54/-3
    • View Profile
Re: How to add a new element on diagram creation?
« Reply #13 on: February 09, 2010, 10:16:27 am »
Ah sorry, I looked up the wrong event. No, EA_OnPostNewDiagram is new for EA 8.0...
The Sparx Team
[email protected]

MalkContent

  • EA User
  • **
  • Posts: 24
  • Karma: +0/-0
    • View Profile
Re: How to add a new element on diagram creation?
« Reply #14 on: February 17, 2010, 08:45:51 am »
hooray ^^