Author Topic: Move diagram object  (Read 703 times)

Thorbjørn

  • EA Novice
  • *
  • Posts: 4
  • Karma: +0/-0
    • View Profile
Move diagram object
« on: August 29, 2018, 06:33:08 pm »
Hi
I have created a diagram using a C# plugin and added some objects to the diagram. I am trying to move the objects around so they do not overlap but the changes does not apply.
Tried the following which is part of a loop, but the elements are still placed in the top left corner of the diagram.

Code: [Select]
EA.DiagramObject diagramObject = eaDiagram.DiagramObjects.AddNew("l=200;r=400;t="+ 200 * row + ";b=200;", "");
diagramObject.ElementID = element.ElementID;
diagramObject.Update();
diagramObject.top = 200 * row++;
diagramObject.Update();

Any suggestions on how to move the element?

Best regards
Thorbjørn

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 9467
  • Karma: +264/-27
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Move diagram object
« Reply #1 on: August 29, 2018, 07:03:51 pm »
Ha, a gotcha!  ;D

The vertical coordinates are in fact negative. Starting at 0 at the top, and going down (-20 is 20 pixels from the top)
Except when you create a diagramObject, then you can use positive coordinates (just to mess with you I guess)

It is however document in the manual:

Quote
   
Name - This can either be an empty string, or it can specify the initial Left, Right, Top and Bottom values for the new DiagramObject. For example:

     diagram.DiagramObjects.AddNew("l=200;r=400;t=200;b=600;", "")

Note: Top and Bottom values should be specified here as positive numbers, but will be set in the repository as negative values.

Type - Unused.

Geert

PS. you might need to reload the diagram before changes become apparent

Thorbjørn

  • EA Novice
  • *
  • Posts: 4
  • Karma: +0/-0
    • View Profile
Re: Move diagram object
« Reply #2 on: August 29, 2018, 07:54:09 pm »
Nice :-)
But still have some issues. If I crate a diagram object with no initial position but want to set the position afterwards based on some index it seems like the changes is not saved. Based on other posts I have tried a few things but have stumbled on the right combination yet...

Code: [Select]
EA.DiagramObject diagramObject = eaDiagram.DiagramObjects.AddNew("", "");
diagramObject.ElementID = element.ElementID;
diagramObject.Update();
repository.SaveDiagram(diagramID);

diagramObject.top = -200 * causerow;
causerow++;
diagramObject.Update();
eaDiagram.DiagramObjects.Refresh();

repository.SaveDiagram(diagramID);
repository.ReloadDiagram(diagramID);


When I open the diagram afterwards the elements are still all placed in the top left corner?

Best regards and thanks for you help :-)

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 9467
  • Karma: +264/-27
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Move diagram object
« Reply #3 on: August 29, 2018, 08:46:48 pm »
To make sure what is happening you should go step by step and check each time what has actually been changed in the database

e.g

- create diagramObject
- check database
- update diagramObject
- check database
- do something else
- check database

Few things about your code:
eaDiagram.DiagramObjects.Refresh(); is not needed
repository.SaveDiagram(diagramID); might possibly be undoing your changes to the diagramobjects.

Geert

PS. I seem to remember an issue with saving diagramObjects. There possibly is a bug at play here.
Edit: No bug. I checked some of my code and updating the position of diagramobjects works just fine.
« Last Edit: August 29, 2018, 08:50:54 pm by Geert Bellekens »

Thorbjørn

  • EA Novice
  • *
  • Posts: 4
  • Karma: +0/-0
    • View Profile
Re: Move diagram object
« Reply #4 on: August 29, 2018, 11:04:51 pm »
Thanks for your support :-)
I was using an eap file but have now changed to a database to see what is happening. It seems that the values in the database is updated correctly, but when I open the diagram afterwards the values are not used. If I manually update the entries in the database it does not affect the diagram. If I move an element on the diagram and then save the diagram, the database is updated, and then I am able to move the object by changing the values in the database.
The Sequence and ObjectStyle cells are not filled until I save the diagram. I can set the Sequence cell using code but I am not sure what to put into the ObjectStyle cell and I am not sure it will have any affect since setting the cells to null through a database update and then opening the diagram does not have any affect.
Currently my code look like this, which will update the database correctly, but will not update the diagram when it is opened afterwards.

Code: [Select]
EA.Diagram eaDiagram = package.Diagrams.AddNew(diagram.SwFunctionArea, "Object");
eaDiagram.Update();

EA.Element element = softwarecausepackage.Elements.AddNew(examplecause, "Object");
element.Stereotype = "Cause for Hazard";
element.Update();

EA.DiagramObject diagramObject = eaDiagram.DiagramObjects.AddNew("l=100;r=200;t=100;b=200;", "");
diagramObject.ElementID = element.ElementID;
diagramObject.Update();

diagramObject.top = -200;
diagramObject.bottom = diagramObject.top;
diagramObject.Update();

Thanks :-)

Thorbjørn

  • EA Novice
  • *
  • Posts: 4
  • Karma: +0/-0
    • View Profile
Re: Move diagram object
« Reply #5 on: August 29, 2018, 11:13:04 pm »
Hi again
Not totally sure yet, but I think my current issue is that the there needs to be a positive difference between top and bottom, and right and left, otherwise the object will be drawn in the top left corner.

Best regards
Thorbjørn

qwerty

  • EA Guru
  • *****
  • Posts: 10578
  • Karma: +232/-191
  • I'm no guru at all
    • View Profile
Re: Move diagram object
« Reply #6 on: August 30, 2018, 06:06:15 am »
You need to specify top/left and bottom/right in order to place and size the element in the diagram. If the size is too small EA will (IIRC) take a minimum size. Eventually the result is just scrap it negativ/too small size is specified.

q.