Book a Demo

Author Topic: Problem with updating DiagramObject position  (Read 4507 times)

Eamonn John Casey

  • EA User
  • **
  • Posts: 110
  • Karma: +0/-1
    • View Profile
Problem with updating DiagramObject position
« on: September 20, 2016, 06:49:02 pm »
Hi,

I got a problem when updating the size and position of DiagramObject using the API.
I have a Boundary object and that code works just fine. But then I try placing (for example an ArchiMate element). The same code will not move the element properly.

Attempt 1:
Code: [Select]
private void UpdateElementOnDiagram(
EAAPI.Diagram diagram, EAAPI.DiagramObject diagramObject,
int left, int right, int top, int bottom)
{
diagramObject.top = top;
diagramObject.left = left;
diagramObject.bottom = bottom;
diagramObject.right = right;
diagramObject.Update();
}

Attempt 2:
Code: [Select]
private void UpdateElementOnDiagram(
EAAPI.Diagram diagram, EAAPI.DiagramObject diagramObject,
int left, int right, int top, int bottom)
{
String styleString = diagramObject.Style.ToString();
String[] styleList = styleString.Split(';');

for (int nIndex = 0; nIndex < styleList.Count(); nIndex++) {
if (true == styleList[nIndex].Contains("l=")) {
styleList[nIndex] = String.Format("l={0}", left);
} else if (true == styleList[nIndex].Contains("r=")) {
styleList[nIndex] = String.Format("r={0}", right);
} else if (true == styleList[nIndex].Contains("t=")) {
styleList[nIndex] = String.Format("t={0}", top);
} else if (true == styleList[nIndex].Contains("b=")) {
styleList[nIndex] = String.Format("b={0}", left);
}
}
styleString = String.Join(";", styleList);
diagramObject.Style = styleString;

diagramObject.Update();
}

I also do the Diagram.Update()

Any ideas?

Thanks,
Eamonn J.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Problem with updating DiagramObject position
« Reply #1 on: September 20, 2016, 07:29:04 pm »
After updating the diagramobject make sure you refresh the diagram.
Saving the diagram might have an adverse effect and undo the changes you just made.

Also remember that the Y axis is negative starting from 0 at the top.

Geert

Eamonn John Casey

  • EA User
  • **
  • Posts: 110
  • Karma: +0/-1
    • View Profile
Re: Problem with updating DiagramObject position
« Reply #2 on: September 20, 2016, 08:45:00 pm »
Thanks,

I used Attempt 1 and negated the top and bottom values and now it Works as expected.

EjC