Author Topic: Insert a new Element in a available Element  (Read 19430 times)

marine1981

  • EA User
  • **
  • Posts: 58
  • Karma: +0/-0
    • View Profile
Insert a new Element in a available Element
« on: November 16, 2010, 12:29:02 am »
I search the available diagram. How I get this diagram? I select the Package and then I create a “New Package” with a “New Diagram”. Now, I want insert the New Diagram in the available diagram”. I use the OnPostNewPackage-Event with C#

My tree:
Quote
+ Package
++ Diagram
++ New Element for the “New Diagram”
++ NewPackage
+++ New Diagram
Code: [Select]
EA.Package ParentPackage = Repository.GetPackageByID(NewPackage.ParentID)

for(short i=0; i < ParentPackage.Diagrams.Count-1; i++)
{
      MessageBox.Show(“Do somethinkg” + i);

}  
« Last Edit: November 17, 2010, 12:35:35 am by marine1981 »

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13287
  • Karma: +557/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Insert a new Diagram in a available Diagram
« Reply #1 on: November 16, 2010, 12:40:14 am »
Sven,

First of all, you can use foreach on EA.Collection, that is a bit more elegant then your for loop.
Further you need to add Something to the Diagram.DiagramObjects collection to put something on the diagram.

Geert

marine1981

  • EA User
  • **
  • Posts: 58
  • Karma: +0/-0
    • View Profile
Re: Insert a new Diagram in a available Diagram
« Reply #2 on: November 16, 2010, 01:08:13 am »
I have already inserted a Element into the Diagram. Later, I want connect the both "Elements".
« Last Edit: November 16, 2010, 01:08:47 am by marine1981 »

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13287
  • Karma: +557/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Insert a new Diagram in a available Diagram
« Reply #3 on: November 16, 2010, 01:11:34 am »
To Connect the elements use Element.Connectors on the source and fill in the ID of the target on the new Connector before saving it.

Geert

marine1981

  • EA User
  • **
  • Posts: 58
  • Karma: +0/-0
    • View Profile
Re: Insert a new Diagram in a available Diagram
« Reply #4 on: November 16, 2010, 01:28:49 am »
How I can use the EA.Collection with foreach?

EA.Collection DiagramSearch = ParentPackage.Diagrams. ....;//?
foreach(short i in DiagramSearch)
{
 MessageBox.Show("Test: " + Convert.ToString(i));
}

stao

  • EA User
  • **
  • Posts: 137
  • Karma: +0/-0
    • View Profile
Re: Insert a new Diagram in a available Diagram
« Reply #5 on: November 16, 2010, 11:54:05 am »
foreach (EA.Diagram actDiagram in ParentPackage.Diagrams) {

       actDiagram...();
}

marine1981

  • EA User
  • **
  • Posts: 58
  • Karma: +0/-0
    • View Profile
Re: Insert a new Diagram in a available Diagram
« Reply #6 on: November 16, 2010, 08:29:01 pm »
I have got under a selected Package a Diagram in the Project Browser. How I can get the Diagram? It exists only one Diagram. How I can do this one?
« Last Edit: November 16, 2010, 08:33:06 pm by marine1981 »

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13287
  • Karma: +557/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Insert a new Diagram in a available Diagram
« Reply #7 on: November 16, 2010, 08:44:52 pm »
If you are sure there is only one diagram you can do
Package.Diagrams.GetAt(0)
But you better put a test before that, so something like
Code: [Select]
if (myPackage.Diagrams.Count > 0)
{
   myDiagram = (EA.Diagram)Package.Diagrams.GetAt(0);
}

Geert

marine1981

  • EA User
  • **
  • Posts: 58
  • Karma: +0/-0
    • View Profile
Re: Insert a new Element in a available Element
« Reply #8 on: November 17, 2010, 12:42:51 am »
It does work well. Now, I want conntect both elements.
I have already the ID vom the new element. Now, I need the ElementID from the Element with Stereotype "MyStereotypeName". How I can search the right element in the Diagram?
« Last Edit: November 17, 2010, 12:54:14 am by marine1981 »

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13287
  • Karma: +557/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Insert a new Element in a available Element
« Reply #9 on: November 17, 2010, 12:49:03 am »
Quote
My Idea:
Not much of an idea then  ;D

I think you best loop the DiagramObjects of your diagram, get the ElementID of the diagramObject, get the element using Repository.GetElementByID and check the stereotype.

Geert

marine1981

  • EA User
  • **
  • Posts: 58
  • Karma: +0/-0
    • View Profile
Re: Insert a new Element in a available Element
« Reply #10 on: November 17, 2010, 01:01:40 am »
It's late ;)
My Idea is:

Code: [Select]
foreach(EA.Element ParentElement in ParentDiagramObject)
{

   ParentElement = Repository.GetElementByID(ParentElement.ElementID);
   if(ParentElement.Stereotype == "StereotypeName");
   {
     //Conntect the elements
    }
}
« Last Edit: November 17, 2010, 05:11:57 pm by marine1981 »

marine1981

  • EA User
  • **
  • Posts: 58
  • Karma: +0/-0
    • View Profile
Re: Insert a new Element in a available Element
« Reply #11 on: November 17, 2010, 06:28:13 pm »
My problem is very simple. I don't kow, how i can get the upper element from the diagram(not Project Browser). The upper element has got a clear stereotyp. The other elements in the diagram has got the same stereotyp. How I can get the the element with the clear stereotype?

My idea was:
Code: [Select]
foreach(EA.Element ParentElement in ParentDiagramObject)
{
//a sample code
MessageBox.Show(ParentElement.Stereotype);

}
But it does not work :(
« Last Edit: November 17, 2010, 06:29:09 pm by marine1981 »

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13287
  • Karma: +557/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Insert a new Element in a available Element
« Reply #12 on: November 17, 2010, 06:35:09 pm »
So do you need the element that owns the diagram, or an element that is shown on the diagram?

Geert

marine1981

  • EA User
  • **
  • Posts: 58
  • Karma: +0/-0
    • View Profile
Re: Insert a new Element in a available Element
« Reply #13 on: November 17, 2010, 06:45:40 pm »
I need the first element(main element) from the diagram. Is the first element the owner of the diagram?

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13287
  • Karma: +557/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Insert a new Element in a available Element
« Reply #14 on: November 17, 2010, 06:52:21 pm »
How do you determine the "first" or "main" object in a diagram?
In a diagram all objects are created equal  ;)
The owning element is the element which owns the diagram, which means the diagram is nested under the element in the project browser like
Package -> Onwer of element
- Element -> Owner of diagram
  - Diagram

Geert