Book a Demo

Author Topic: Diagram Object methods from API problem  (Read 9760 times)

Lukasz

  • EA Novice
  • *
  • Posts: 17
  • Karma: +0/-0
    • View Profile
Diagram Object methods from API problem
« on: September 05, 2014, 09:07:25 pm »
Hello,
I know that there is a lot of helpfull people, so I'm writing again :)

I have problem with DiagramObject class Update() method.
When I use it on an object e.g.
Code: [Select]
diagramObject = (EA.DiagramObject)MyDiagram.DiagramObjects.GetAt(diagramObjectIterator);After reloading the project in EA, this object have coordinates set on:
Left: 10,
Top: 10.
I only run Update() method.
Documentation says, that:
Quote
Update the current DiagramObject after modification or appending a new item

If false is returned, check the GetLastError function for more information.

I checked the value returned by method and it was true. How to use this method correctly?

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Diagram Object methods from API problem
« Reply #1 on: September 05, 2014, 09:33:11 pm »
The documentation is likely a bit sloppy. You also need to reload the diagram to make the change visible. EA diagrams are a bit decoupled and have their own temp storage which is only synched on request.

q.

Lukasz

  • EA Novice
  • *
  • Posts: 17
  • Karma: +0/-0
    • View Profile
Re: Diagram Object methods from API problem
« Reply #2 on: September 08, 2014, 05:55:44 pm »
Thanks for the answer. I still have problem with this question.
I want to change the coordinates of the control, so I'm setting the left, right, top and bottom values.
Code: [Select]
diagramObject.left =0;
diagramObject.top = 0;
diagramObject.right = 100;
diagramObject.bottom = -100
After that, in the code there is:
Code: [Select]
diagramObject.Update();
Which should change the values in the db/eap.
I'm running program in debugging mode, and that is, what I observed:
Before method Update(), the values connected with coordinates for diagramObject are, like I set. When the method Update() is called the values changed, e.g. left and right property gets value "-40", top and bottom gets "-80". Word "and" is a key.
When I run this project in EA (after changes in program) coordinates of all controls are set to: top: 10, left: 10.
What I'm doing wrong?

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Diagram Object methods from API problem
« Reply #3 on: September 08, 2014, 06:47:25 pm »
From your snippet it's hard to tell. I ran this Perl code
Code: [Select]
my $dia = $rep->GetCurrentDiagram();
for my $do (in $dia->DiagramObjects) {
    $do->{Top} = -50;
    $do->Update;
}
$rep->ReloadDiagram ($dia->DiagramID);
and it changed the top position of all elements in the diagram to 50 pixels from the top.

q.

Lukasz

  • EA Novice
  • *
  • Posts: 17
  • Karma: +0/-0
    • View Profile
Re: Diagram Object methods from API problem
« Reply #4 on: September 08, 2014, 10:33:12 pm »
What can I say... It doesn't work :(
Breakpoint is set on the method Update().

Before calling this method:



After calling this method:



diagramObject:

Code: [Select]
diagramObject = (EA.DiagramObject)MyDiagram.DiagramObjects.GetAt(diagramObjectIterator);
It's very strange...
« Last Edit: September 08, 2014, 10:34:49 pm by stuk06 »

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Diagram Object methods from API problem
« Reply #5 on: September 09, 2014, 01:10:13 am »
Would you mind to post the code instead of a screenshot where the code is not to see?

q.

Lukasz

  • EA Novice
  • *
  • Posts: 17
  • Karma: +0/-0
    • View Profile
Re: Diagram Object methods from API problem
« Reply #6 on: September 09, 2014, 02:07:15 am »
Quote
Would you mind to post the code instead of a screenshot where the code is not to see?

q.

Sure! I should make it earlier.

Code: [Select]
for (short diagramObjectIterator = 0; diagramObjectIterator < MyDiagram.DiagramObjects.Count; diagramObjectIterator++)
            {
                EA.DiagramObject diagramObject = (EA.DiagramObject)MyDiagram.DiagramObjects.GetAt(diagramObjectIterator);
                var a = repository.GetElementByID(diagramObject.ElementID);

                if (a.Stereotype != "win32Dialog")
                {
                    diagramObject.left = 100;
                    diagramObject.right = 200;
                    diagramObject.top = -60;
                    diagramObject.bottom = -100;
                    diagramObject.Update();
                }
            }
            repository.ReloadDiagram(MyDiagram.DiagramID);
            MessageBox.Show("Saved!");

The code is a little bit different from this on the screens, but the problem, what I'm talking about, is still unresolved.

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Diagram Object methods from API problem
« Reply #7 on: September 09, 2014, 05:07:25 am »
Could it be that you are using locks?

q.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Diagram Object methods from API problem
« Reply #8 on: September 09, 2014, 03:51:57 pm »
I think that this is due to the fact that the win32dialog use a different set of coordinates then the regular elements.
One of the sparxians replied to another post about the difference in coordinates between EA and XMI saying that win32dialog use dialogUnits iso pixels.
So I guess there's somewhere a weird translation going on in the backend.

If my theory is correct you should not have this problem with regular classes.

Geert

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Diagram Object methods from API problem
« Reply #9 on: September 09, 2014, 04:10:59 pm »
I just tried with that and it worked as expected. So it must be another issue.

q.

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: Diagram Object methods from API problem
« Reply #10 on: September 09, 2014, 04:39:28 pm »
Don't think it's win32. That will still set the coordinates as you request, they just won't line up with other elements.

My suspicion is that there's just a minimum offset that it is allowing from the top left of the diagram.

Lukasz

  • EA Novice
  • *
  • Posts: 17
  • Karma: +0/-0
    • View Profile
Re: Diagram Object methods from API problem
« Reply #11 on: September 09, 2014, 05:47:49 pm »
@qwerty: no, I'm not using locks.
@Geert Bellekens: I know about this, and I use this units.

I want to share my observation on this problem. When controls are in another (e.g. in dialog window) it doesn't work properly. When the controls (buttons, checkboxes, etc.) are placed only in the diagram this method works fine.
Any suggestions?
« Last Edit: September 09, 2014, 05:50:42 pm by stuk06 »

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Diagram Object methods from API problem
« Reply #12 on: September 09, 2014, 06:29:42 pm »
Could it be then that they use relative coordinates (relative to the top left corner of the containing element)?

Geert

Lukasz

  • EA Novice
  • *
  • Posts: 17
  • Karma: +0/-0
    • View Profile
Re: Diagram Object methods from API problem
« Reply #13 on: September 09, 2014, 06:40:27 pm »
Rather not, because the values, which are shown in EA are relative to the diagram (not to dialog). When controls are inside the dialog, method update() works like in the Reply #4 of this topic.

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Diagram Object methods from API problem
« Reply #14 on: September 09, 2014, 07:54:58 pm »
Last try: any add-in that do strange things? Try to turn off MDGs / disable add-ins.

q.