Sparx Systems Forum
Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: ngong on January 10, 2025, 03:15:35 am
-
Need some help with this JavaScript:
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 (https://cloud.august.de/nextcloud/remote.php/webdav/Public/add-component-to-diagramm.qeax)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.
-
You are seriously complicating things.
All you need is this:
diagObj = diagram.DiagramObjects.AddNew("l=100;r=160;t=100;b=200", "");
diagObj.ElementID = element.ElementID;
diagObj.Update();
Repository.ReloadDiagram(diagram.DiagramID);
Geert
-
Yes, thank you Geert.