Author Topic: Element positioning missing (Top,Left,Bottom,Right) version 15.2.1554  (Read 2724 times)

Ruff

  • EA Novice
  • *
  • Posts: 8
  • Karma: +0/-0
    • View Profile
I'm trying to import a new set of elements that supercede the existing ones.
I have migrate the relationships but when I try to replace the items in existing diagrams I'm having issues.

In the existing diagram DiagramObjects should have Top, Left, Bottom, Right.  This would help me to add the new relationship in the same spot.  But when I read this value, they're undefined.  I tried viewing their style and sure enough they're is no values for l,r,b,t.

I also just for giggles tried setting the value (DiagramObjects.Left = 50) updating the object and reloading the diagram, but this does nothing as well.

I can add an object with l,r,b,t and that works but how can we move thing via scripting?

Any ideas on how to get positioning of an DiagramObjects?

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13274
  • Karma: +556/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Element positioning missing (Top,Left,Bottom,Right) version 15.2.1554
« Reply #1 on: December 12, 2024, 12:48:01 am »
In the existing diagram DiagramObjects should have Top, Left, Bottom, Right.  This would help me to add the new relationship in the same spot.  But when I read this value, they're undefined.  I tried viewing their style and sure enough they're is no values for l,r,b,t.
How do you now these fields are undefined? Can you describe exactly what you are doing? You said you tried viewing their "style", but this information is not stored in the style at all.

Also, if you want to replace an old element with a new one, you can simply change the elementID of the diagramObject to the new ElementID. That avoids having to create a new DiagramObject and then deleting the old one.

Geert

Ruff

  • EA Novice
  • *
  • Posts: 8
  • Karma: +0/-0
    • View Profile
Re: Element positioning missing (Top,Left,Bottom,Right) version 15.2.1554
« Reply #2 on: December 12, 2024, 01:11:35 am »
Also, if you want to replace an old element with a new one, you can simply change the elementID of the diagramObject to the new ElementID.

Thank you! This I think is the answer. 


(Big fan of your posts, you help a lot of people, thank you for what you do.)

Ruff

  • EA Novice
  • *
  • Posts: 8
  • Karma: +0/-0
    • View Profile
Re: Element positioning missing (Top,Left,Bottom,Right) version 15.2.1554
« Reply #3 on: December 12, 2024, 01:13:19 am »
I know that they're all underfined as a printed out their value, when I got them returned as an object.
Code: [Select]
function OnDiagramScript()
{
// Get a reference to the current diagram
var currentDiagram as EA.Diagram;
currentDiagram = Repository.GetCurrentDiagram();

if ( currentDiagram != null )
{
// Get a reference to any selected connector/objects
var selectedConnector as EA.Connector;
var selectedObjects as EA.Collection;
selectedConnector = currentDiagram.SelectedConnector;
selectedObjects = currentDiagram.SelectedObjects;

if ( selectedConnector != null )
{
// A connector is selected
}
else if ( selectedObjects.Count > 0 )
{
forEachCollection( selectedObjects , dObject  =>{
out( get(dObject.ElementID).Name, dObject.InstanceGUID, dObject.Left+"") // short hand for Session.Output()

})
}
else
{
// Nothing is selected
}
}
else
{
Session.Prompt( "This script requires a diagram to be visible.", promptOK)
}

//currentDiagram.DiagramObjects.Update()
currentDiagram.Update()
Repository.ReloadDiagram(currentDiagram.DiagramID)
}

OnDiagramScript();

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13274
  • Karma: +556/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Element positioning missing (Top,Left,Bottom,Right) version 15.2.1554
« Reply #4 on: December 12, 2024, 01:45:31 am »
I'm not too familiar with the javascript (and shorthand) you are using, but if I execute this simple script it prints the left coördinates for me as expected.

Code: [Select]
function testDiagramObjects()
dim diagram as EA.Diagram
set diagram = Repository.GetDiagramByGuid("{5ECCE53D-B9EE-4d88-A188-20432D9EA8B9}")
dim diagramObject as EA.DiagramObject
for each diagramObject in diagram.DiagramObjects
Session.Output "left: " & diagramObject.left
next
end function

Geert

Ruff

  • EA Novice
  • *
  • Posts: 8
  • Karma: +0/-0
    • View Profile
Re: Element positioning missing (Top,Left,Bottom,Right) version 15.2.1554
« Reply #5 on: December 12, 2024, 02:33:33 am »
This seems to be a documentation issue.  'Left' is what is defined in the documentation but I saw you use 'left'
Code: [Select]
function main()
{
var diagram as EA.Diagram;
var diagramObject as EA.DiagramObject;
diagram = Repository.GetDiagramByGuid("{8D386671-458F-4285-B191-BEC91CDF7F20}")
const diagramObjectCollection = diagram.DiagramObjects
for( i = 0; i< diagramObjectCollection.Count; i++){
diagramObject = diagram.DiagramObjects.GetAt(i)
if (typeof diagramObject.Left !== 'undefined'){
Session.Output("Left:" +diagramObject.Left)
}else if(typeof diagramObject.left !== 'undefined'){
Session.Output("left:"+diagramObject.left)
}else{
Session.Output( diagramObject.ElementID + "Left/left is Undefined!")
}
}
}

main();

And in the output:
Code: [Select]
left:589
left:381
left:215
left:399
left:399
left:209
left:207
left:790
Thanks for helping me find this.

ea0522

  • EA User
  • **
  • Posts: 134
  • Karma: +5/-0
    • View Profile
Re: Element positioning missing (Top,Left,Bottom,Right) version 15.2.1554
« Reply #6 on: December 12, 2024, 05:58:57 pm »
When adding an Element to a Diagram, I used the following JavaScript:

Code: [Select]
const strAddNewNameObject      = "l=30;r=195;t=300;b=510;";

// Add the curElement to curDiagram
curDiagramObjects = curDiagram.DiagramObjects;
curDiagramObject  = curDiagramObjects.AddNew( strAddNewNameObject, "" );
curDiagramObject.ElementID = curElement.ElementID;
curDiagramObject.Update();
curDiagramObjects.Refresh();

The const strAddNewNameObject is defining the location of the Element in pixels.
Then use this const as Name for the AddNew method and assign the ElementID for the reference to the Element placed.
Ofcourse, the const can also be constructed by calculations...
« Last Edit: December 12, 2024, 06:01:40 pm by ea0522 »