Author Topic: Left, right, top and bottom properties of DiagramObject  (Read 6509 times)

MatthiasVDE

  • EA User
  • **
  • Posts: 196
  • Karma: +1/-0
    • View Profile
Left, right, top and bottom properties of DiagramObject
« on: February 11, 2020, 08:35:09 pm »
When I create a diagramobject, it automatically adjusts its size (right and bottom parameters) to the actual size of the diagramobject, for example a class.

Code: [Select]
dim messageRootObject as EA.DiagramObject
set messageRootObject = messageDiagram.DiagramObjects.AddNew("l=10;r=;t=20;b=")
messageRootObject.ElementID = element.ElementID
messageRootObject.Update()
messageDiagram.DiagramObjects.Refresh()
Repository.ReloadDiagram(messageDiagram.DiagramID)

But this is not saved to the database, it's not possible to get the actual size of a diagramobject.
This displays always '0'.
Quote
Session.Output messageRootObject.right
Session.Output messageRootObject.bottom

Paolo F Cantoni

  • EA Guru
  • *****
  • Posts: 8568
  • Karma: +254/-129
  • Inconsistently correct systems DON'T EXIST!
    • View Profile
Re: Left, right, top and bottom properties of DiagramObject
« Reply #1 on: February 11, 2020, 09:11:04 pm »
When I create a diagramobject, it automatically adjusts its size (right and bottom parameters) to the actual size of the diagramobject, for example a class.

Code: [Select]
dim messageRootObject as EA.DiagramObject
set messageRootObject = messageDiagram.DiagramObjects.AddNew("l=10;r=;t=20;b=")
messageRootObject.ElementID = element.ElementID
messageRootObject.Update()
messageDiagram.DiagramObjects.Refresh()
Repository.ReloadDiagram(messageDiagram.DiagramID)

But this is not saved to the database, it's not possible to get the actual size of a diagramobject.
This displays always '0'.
Quote
Session.Output messageRootObject.right
Session.Output messageRootObject.bottom
If I understand you correctly, Matthias,
You've stumbled upon one of the first "Gotchas" of diagramobject processing.
The API returns, NOT the size of the object on the (live) diagram, but the size of the object as it was last saved with a diagram save.  So UNTIL you save the diagram with the object, you'll see the behaviour you documented.

As qwerty would say, Sparxian logic...

Paolo
Inconsistently correct systems DON'T EXIST!
... Therefore, aim for consistency; in the expectation of achieving correctness....
-Semantica-
Helsinki Principle Rules!

MatthiasVDE

  • EA User
  • **
  • Posts: 196
  • Karma: +1/-0
    • View Profile
Re: Left, right, top and bottom properties of DiagramObject
« Reply #2 on: February 11, 2020, 09:13:15 pm »
When I create a diagramobject, it automatically adjusts its size (right and bottom parameters) to the actual size of the diagramobject, for example a class.

Code: [Select]
dim messageRootObject as EA.DiagramObject
set messageRootObject = messageDiagram.DiagramObjects.AddNew("l=10;r=;t=20;b=")
messageRootObject.ElementID = element.ElementID
messageRootObject.Update()
messageDiagram.DiagramObjects.Refresh()
Repository.ReloadDiagram(messageDiagram.DiagramID)

But this is not saved to the database, it's not possible to get the actual size of a diagramobject.
This displays always '0'.
Quote
Session.Output messageRootObject.right
Session.Output messageRootObject.bottom
If I understand you correctly, Matthias,
You've stumbled upon one of the first "Gotchas" of diagramobject processing.
The API returns, NOT the size of the object on the (live) diagram, but the size of the object as it was last saved with a diagram save.  So UNTIL you save the diagram with the object, you'll see the behaviour you documented.

As qwerty would say, Sparxian logic...

Paolo
And how do I save that?

qwerty

  • EA Guru
  • *****
  • Posts: 13574
  • Karma: +395/-301
  • I'm no guru at all
    • View Profile
Re: Left, right, top and bottom properties of DiagramObject
« Reply #3 on: February 11, 2020, 09:34:56 pm »
Save it. Re-reload the object. Read the size.

q.

MatthiasVDE

  • EA User
  • **
  • Posts: 196
  • Karma: +1/-0
    • View Profile
Re: Left, right, top and bottom properties of DiagramObject
« Reply #4 on: February 11, 2020, 09:38:03 pm »
Save it. Re-reload the object. Read the size.

q.

I did this:
Code: [Select]
messageRootObject.Update()
messageDiagram.DiagramObjects.Refresh()
Repository.ReloadDiagram(messageDiagram.DiagramID)

peterc

  • Guest
Re: Left, right, top and bottom properties of DiagramObject
« Reply #5 on: February 11, 2020, 09:47:02 pm »
Don't you also need a Repository.SaveDiagram(messageDiagram.DiagramID) before you reload it?

MatthiasVDE

  • EA User
  • **
  • Posts: 196
  • Karma: +1/-0
    • View Profile
Re: Left, right, top and bottom properties of DiagramObject
« Reply #6 on: February 11, 2020, 09:51:42 pm »
Code: [Select]
dim l, r, t, b
l = "10"
r = ""
t = "20"
b = ""
dim messageRootObject as EA.DiagramObject
set messageRootObject = messageDiagram.DiagramObjects.AddNew("l="&l&";r="&r&";t="&t&";b="&b, "")
messageRootObject.ElementID = element.ElementID
messageRootObject.Update()
messageDiagram.DiagramObjects.Refresh()
Repository.SaveDiagram(messageDiagram.DiagramID)
Repository.ReloadDiagram(messageDiagram.DiagramID)

Session.Output messageRootObject.right
Session.Output messageRootObject.bottom

The output stays '0', but if you take a look on the diagram, the left and bottom aren't 0 so I don't get it why it always return '0'

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13136
  • Karma: +548/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Left, right, top and bottom properties of DiagramObject
« Reply #7 on: February 11, 2020, 10:00:46 pm »
Remove messageDiagram.DiagramObjects.Refresh(), you don't need that here.

Also, try filling in all parameters (l, r, t, b)

Geert

MatthiasVDE

  • EA User
  • **
  • Posts: 196
  • Karma: +1/-0
    • View Profile
Re: Left, right, top and bottom properties of DiagramObject
« Reply #8 on: February 11, 2020, 10:08:31 pm »
Remove messageDiagram.DiagramObjects.Refresh(), you don't need that here.

Also, try filling in all parameters (l, r, t, b)

Geert

Assume that I have a class element, with 50 attributes. When I create this diagramobject with parameters, left=10, right=50, top=20, bottom=50 the diagramobject will be displayed with a larger width then 50 - 10 (right - left) and with a larger height then 50 - 20 (bottom - top) because Sparx EA auto-resizes the diagramobject to the minimal size to display everything.

My question is, how can I get the positioning of the diagramobject, after the auto-resize that Sparx EA did?

Uffe

  • EA Practitioner
  • ***
  • Posts: 1859
  • Karma: +133/-14
  • Flutes: 1; Clarinets: 1; Saxes: 5 and counting
    • View Profile
Re: Left, right, top and bottom properties of DiagramObject
« Reply #9 on: February 11, 2020, 10:31:17 pm »
My question is, how can I get the positioning of the diagramobject, after the auto-resize that Sparx EA did?
You need to retrieve the DiagramObject from the database. The one you got from AddNew is not kept up-to-date by the API.

So after your call to messageDiagram.DiagramObjects.Refresh() (reloading the list of DiagramObjects from the database), you need to traverse messageDiagram.DiagramObjects, locate the one whose .ElementID matches element.ElementID and use that. You can reuse your messageRootObject variable for this, but you need to read new data into it.

HTH,


/Uffe
My theories are always correct, just apply them to the right reality.

MatthiasVDE

  • EA User
  • **
  • Posts: 196
  • Karma: +1/-0
    • View Profile
Re: Left, right, top and bottom properties of DiagramObject
« Reply #10 on: February 11, 2020, 10:33:21 pm »
My question is, how can I get the positioning of the diagramobject, after the auto-resize that Sparx EA did?
You need to retrieve the DiagramObject from the database. The one you got from AddNew is not kept up-to-date by the API.

So after your call to messageDiagram.DiagramObjects.Refresh() (reloading the list of DiagramObjects from the database), you need to traverse messageDiagram.DiagramObjects, locate the one whose .ElementID matches element.ElementID and use that. You can reuse your messageRootObject variable for this, but you need to read new data into it.

HTH,


/Uffe

So I can't do this without querying the database?

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13136
  • Karma: +548/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Left, right, top and bottom properties of DiagramObject
« Reply #11 on: February 11, 2020, 11:32:59 pm »
Be careful. Sometimes reloading stuff via Refresh() is not enough.
Sometimes you need to actually get the object from the repository again using Repository.GetxxxByID or something similar.

Geert

MatthiasVDE

  • EA User
  • **
  • Posts: 196
  • Karma: +1/-0
    • View Profile
Re: Left, right, top and bottom properties of DiagramObject
« Reply #12 on: February 12, 2020, 12:10:06 am »
When I look at the database, the right and bottom for the diagramobjects is also '0'. And when I drag it a little in EA, and look then in the database, then I see the correct right and bottom as displayed on the diagram.

EDIT:

By first doing Repository.OpenDiagram(messageDiagram.DiagramID) before saving, I can see the correct right and bottom in the database. But stil no correct right and bottom in the object model.
« Last Edit: February 12, 2020, 12:28:55 am by MatthiasVDE »

qwerty

  • EA Guru
  • *****
  • Posts: 13574
  • Karma: +395/-301
  • I'm no guru at all
    • View Profile
Re: Left, right, top and bottom properties of DiagramObject
« Reply #13 on: February 12, 2020, 01:07:19 am »
I also tried that myself and saw the same effect. Initially storing a DO leaves bottom/right zero. So EA will calculate the size depending on the defaults. These can be stored in EA's guts or in the shape script (which ever takes over). Since there is no operation to retrieve the default size your only solutions: a) send a feature request or b) forget it. Probably you should go for c) think about some other solution.

q.

MatthiasVDE

  • EA User
  • **
  • Posts: 196
  • Karma: +1/-0
    • View Profile
Re: Left, right, top and bottom properties of DiagramObject
« Reply #14 on: February 12, 2020, 01:29:19 am »
This works:

Code: [Select]
dim messageRootObject as EA.DiagramObject
set messageRootObject = messageDiagram.DiagramObjects.AddNew("l="&l&";r="&r&";t="&t&";b="&b, "")
messageRootObject.ElementID = element.ElementID
messageRootObject.Update()
Repository.OpenDiagram(messageDiagram.DiagramID)
Repository.SaveDiagram(messageDiagram.DiagramID)
Repository.ReloadDiagram(messageDiagram.DiagramID)
messageDiagram.DiagramObjects.Refresh()

dim newMessageRootObject as EA.DiagramObject
for each newMessageRootObject in messageDiagram.DiagramObjects
if newMessageRootObject.ElementID = element.ElementID then
set messageRootObject = newMessageRootObject
end if
next
Session.Output messageRootObject.right
Session.Output messageRootObject.bottom