Book a Demo

Author Topic: How to "Paste Element into Diagram as Simple Link"  (Read 9418 times)

André Olivera

  • EA User
  • **
  • Posts: 24
  • Karma: +0/-0
    • View Profile
How to "Paste Element into Diagram as Simple Link"
« on: March 02, 2011, 10:00:36 pm »
I tried add an Diagram Object in the Current Diagram but didn't work..

Something like that:
Code: [Select]
Object Obj = Diagram.DiagramObjects.AddNew(ElementInRepository.Name, ElementInRepository.GetType().ToString());
EA.DiagramObject DiagramObject = (EA.DiagramObject)Obj;
DiagramObject.Update();
Diagram.DiagramObjects.Refresh();

Element In Repository is an package that is located in the same package of the diagram..

Diagram.DiagramObjects and Diagram.DiagramLinks are ReadOnly Collections. Is that the problem?

Thanks..


qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: How to "Paste Element into Diagram as Simple L
« Reply #1 on: March 02, 2011, 10:09:21 pm »
Don't know that language, but you need to set the element_id of the diagram object to that of the element you want to show.

q.

André Olivera

  • EA User
  • **
  • Posts: 24
  • Karma: +0/-0
    • View Profile
Re: How to "Paste Element into Diagram as Simple L
« Reply #2 on: March 03, 2011, 12:16:46 am »
The code is in C#..

What method I can use to set the element ID?

Need I create an Diagram Object (with "AddNew()")?

Thanks!


qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: How to "Paste Element into Diagram as Sim
« Reply #3 on: March 03, 2011, 05:20:54 am »
something like DiagramObject.Element_ID = ElementInRepository.Element_ID
right before the update.

q.
« Last Edit: March 03, 2011, 05:21:16 am by qwerty »

André Olivera

  • EA User
  • **
  • Posts: 24
  • Karma: +0/-0
    • View Profile
Re: How to "Paste Element into Diagram as Simple L
« Reply #4 on: March 03, 2011, 06:38:42 am »
I have created an Diagram Object, then I set the Diagram Object ID to Package ID (that I want to put into the diagram)..

I made an Update() in the Diagram Object and a Refresh() in the Diagram.DiagramObject Collection..

The number of diagram objects in the diagram was increased..

But the package didn't appear in the diagram =/

Do you made something like this before? Do you have some code to show me?

Thanks!!


stao

  • EA User
  • **
  • Posts: 137
  • Karma: +0/-0
    • View Profile
Re: How to "Paste Element into Diagram as Simple L
« Reply #5 on: March 03, 2011, 07:01:12 am »
i never did that before with packages.
but afaik packages in EA are a bit different to handle.
i would try it to set the diagramObjects elementId to the Package.Element.ElementId

did you reload the diagram?

André Olivera

  • EA User
  • **
  • Posts: 24
  • Karma: +0/-0
    • View Profile
Re: How to "Paste Element into Diagram as Simple L
« Reply #6 on: March 03, 2011, 07:23:31 am »
I will try..

I think that I am not setting the position of the Diagram Object..


stao

  • EA User
  • **
  • Posts: 137
  • Karma: +0/-0
    • View Profile
Re: How to "Paste Element into Diagram as Sim
« Reply #7 on: March 03, 2011, 08:15:49 am »
ah yeh thats right. the position of the diagramObject must be set in the first parameter of the addNew Method.
for instance:

Code: [Select]
EA.DiagramObject fledgedDObj = (EA.DiagramObject)sdmDiagram.DiagramObjects.AddNew("l=50;r=70;t=50;b=70;", "StateNode");
« Last Edit: March 03, 2011, 08:16:56 am by stao »

André Olivera

  • EA User
  • **
  • Posts: 24
  • Karma: +0/-0
    • View Profile
Re: How to "Paste Element into Diagram as Simple L
« Reply #8 on: March 03, 2011, 08:30:34 am »
And What I put in the second parameter?

Where Can I find this documentation?

André Olivera

  • EA User
  • **
  • Posts: 24
  • Karma: +0/-0
    • View Profile
Re: How to "Paste Element into Diagram as Simple L
« Reply #9 on: March 03, 2011, 09:01:51 am »
Now Works!!

I changed the set from

DiagramObj.ElementID = Package.PackageID;

to

DiagramObj.ElementID = Package.Element.ElementID;

And I initialize with the position too..

Is possible find a free space automatically in the diagram?

Thanks a lot everyone!!! :D

stao

  • EA User
  • **
  • Posts: 137
  • Karma: +0/-0
    • View Profile
Re: How to "Paste Element into Diagram as Sim
« Reply #10 on: March 03, 2011, 09:23:29 am »
second parameter is the type of the diagramObject. should be the same type as the element.
you could use the EA Help.
the position of the diagramObject can also be set with the attributes
right, top, left, bottom of the diagramObject

Code: [Select]
Is possible find a free space automatically in the diagram?
i think you can iterate through all diagramObjects and check their positions.
you can look for the diagramObject with the greatest value of the right attribute and creating your new diagramObject where the left attribute is slightly higher than this greatest right value so you new diagramObject should always be on a free spot.
( I never tried something like this its only a guess how it POSSIBLY can be implemented )

stao

« Last Edit: March 03, 2011, 09:30:34 am by stao »

André Olivera

  • EA User
  • **
  • Posts: 24
  • Karma: +0/-0
    • View Profile
Re: How to "Paste Element into Diagram as Simple L
« Reply #11 on: March 20, 2011, 03:18:40 am »
Hello!!

I can put one element in one diagram.. Now I want to put the embedded elements toghtere with the element..

Somebody knows how to make this?

André Olivera

  • EA User
  • **
  • Posts: 24
  • Karma: +0/-0
    • View Profile
Re: How to "Paste Element into Diagram as Simple L
« Reply #12 on: March 20, 2011, 03:43:23 am »
I just create an new DiagramObject with the embedded element and works fine!

=D