Author Topic: first script to place a component on a diagram  (Read 1746 times)

ngong

  • EA User
  • **
  • Posts: 275
  • Karma: +2/-2
    • View Profile
first script to place a component on a diagram
« on: January 10, 2025, 03:15:35 am »
Need some help with this JavaScript:

Code: [Select]
function addElToDiag( element, diagram ) {
var diagObj as EA.DiagramObject;
var r = false;
let posL = 100;
let posT = 100;
diagObj = diagram.DiagramObjects.AddNew("l=100;t=100;", "");
diagObj.Update();
if (diagObj) {
diagObj.ElementID = element.ElementID;
diagObj.right = diagObj.left +100;
diagObj.bottom = diagObj.top +60;
diagObj.Sequence = 1;
diagObj.SetStyleEx("Selectable","1");
diagObj.SetStyleEx("Moveable","1");
diagObj.Update();
diagram.DiagramObjects.Refresh();
diagram.Update();
Repository.SaveDiagram(diagram.DiagramID);
Repository.ReloadDiagram(diagram.DiagramID);
r = true;
}
return r;

It should place a component in a component diagram, what it does. But something is wrong. The component cannot be selected and not be moved. Also the name is placed outside.

Any idea what I did wrong? My AI questions did not result in a solution.

If you like to see a stripped-down project for EA17 you may download the qeax file - testet with Firefox.
In package browser right-click on My Component package in the project/Detailed Design package and run the script add component to diagramm.
Thank you very mucn.
Rolf

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13288
  • Karma: +557/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: first script to place a component on a diagram
« Reply #1 on: January 10, 2025, 05:45:31 pm »
You are seriously complicating things.
All you need is this:

Code: [Select]
diagObj = diagram.DiagramObjects.AddNew("l=100;r=160;t=100;b=200", "");
diagObj.ElementID = element.ElementID;
diagObj.Update();
Repository.ReloadDiagram(diagram.DiagramID);

Geert

ngong

  • EA User
  • **
  • Posts: 275
  • Karma: +2/-2
    • View Profile
Re: first script to place a component on a diagram
« Reply #2 on: January 10, 2025, 08:44:37 pm »
Yes, thank you Geert.
Rolf