I was inspired by Enterprise Architect scripting with java – add CustomProperty
I have no issues adding the legend to be added to the diagram but they entries to the legend aren’t added. Any ideas why this my not work are welcome. (version 15.2.1554)
function addLegendEntries( legendGUID, arr=[{ 'BackgroundColor': -1, 'Stereotype' : 'Stereotype'}] ){
let description = ""
let customPropertyIndex = 0;
arr.forEach( ({BackgroundColor, Stereotype}) => {
description += "@PROP=@NAME="+Stereotype+"@ENDNAME;@TYPE=LEGEND_OBJECTSTYLE@ENDTYPE;@VALU=#Back_Ground_Color#="+BackgroundColor+";#Pen_Color#=16777215;#Pen_Size#=1;#Legend_Type#=LEGEND_OBJECTSTYLE;@ENDVALU;@PRMT="+customPropertyIndex++ +"@ENDPRMT;@ENDPROP;"
})
description += "@PROP=@NAME=Legend@ENDNAME;@TYPE=LEGEND_STYLE_SETTINGS@ENDTYPE;@VALU=@ENDVALU;@PRMT=@ENDPRMT;@ENDPROP;"
const sqlInsertStmt="INSERT INTO t_xref "
+ "("
+ "Client,"
+ "XrefID,"
+ "Type,"
+ "Name,"
+ "Visibility,"
+ "`Partition`,"
+ "Supplier,"
+ "Description"
+ ") "
+ " VALUES ("
+"'"+legendGUID+ "',"
+ "'{"+ generateGUID() +"}',"
+ "'element property',"
+ "'CustomProperties',"
+ "'Public',"
+ "'0',"
+ "'<none>',"
+ "'"+description+"'"
+ ");"
out( sqlInsertStmt )
out( Repository.SQLQuery( sqlInsertStmt ) )
}
function addLegend(diagramID, arr=[{ 'BackgroundColor': -1, 'Stereotype' : 'Stereotype'}])
{
Repository.EnsureOutputVisible( "Script" );
Repository.ClearOutput("Script");
var pkg as EA.Package;
pkg = Repository.GetTreeSelectedPackage();
elements = pkg.Elements;
var legend = elements.AddNew('Diagram Legend', 'Text');
legend.Subtype = 76;
legend.Update();
var diagram as EA.Diagram;
diagram = Repository.GetDiagramByID(diagramID);
Session.Output(diagram.Name);
diagramObjects = diagram.DiagramObjects;
diagramObject = diagramObjects.AddNew("l=100; r=100; t=100; b=500;", "");
addLegendEntries( legend.ElementGUID , arr )
diagramObject.ElementID = legend.ElementID;
diagramObject.Update();
diagram.Update()
}
Repository.EnsureOutputVisible( "Script" );
Repository.ClearOutput("Script");
const diagram = Repository.GetDiagramByGuid("{4FA59731-72DF-402c-AF60-1C3381BC2052}"); // Get the current diagram
out(diagram.DiagramID)
addLegend(diagram.DiagramID, collectColorsInDiagram(diagram))
Repository.ReloadDiagram(diagram.DiagramID)
out("Done")
Here’s the SQL statement that is generated:
INSERT INTO t_xref
(Client,XrefID,Type,Name,Visibility,Partition,Supplier,Description)
VALUES
('{9CCF46B8-D221-41b1-B1B9-EF7072547F74}','{cb940358-f76f-9fdd-dfca-d4537143e394}','element property','CustomProperties','Public','0','<none>',
'@PROP=@NAME=ArchiMate_Grouping@ENDNAME;@TYPE=LEGEND_OBJECTSTYLE@ENDTYPE;@VALU=#Back_Ground_Color#=13458026;#Pen_Color#=16777215;#Pen_Size#=1;#Legend_Type#=LEGEND_OBJECTSTYLE;@ENDVALU;@PRMT=0@ENDPRMT;@ENDPROP;@PROP=@NAME=ArchiMate_Capability@ENDNAME;@TYPE=LEGEND_OBJECTSTYLE@ENDTYPE;@VALU=#Back_Ground_Color#=15528442;#Pen_Color#=16777215;#Pen_Size#=1;#Legend_Type#=LEGEND_OBJECTSTYLE;@ENDVALU;@PRMT=1@ENDPRMT;@ENDPROP;@PROP=@NAME=ArchiMate_Capability@ENDNAME;@TYPE=LEGEND_OBJECTSTYLE@ENDTYPE;@VALU=#Back_Ground_Color#=16777184;#Pen_Color#=16777215;#Pen_Size#=1;#Legend_Type#=LEGEND_OBJECTSTYLE;@ENDVALU;@PRMT=2@ENDPRMT;@ENDPROP;@PROP=@NAME=ArchiMate_Capability@ENDNAME;@TYPE=LEGEND_OBJECTSTYLE@ENDTYPE;@VALU=#Back_Ground_Color#=16443110;#Pen_Color#=16777215;#Pen_Size#=1;#Legend_Type#=LEGEND_OBJECTSTYLE;@ENDVALU;@PRMT=3@ENDPRMT;@ENDPROP;@PROP=@NAME=ArchiMate_Grouping@ENDNAME;@TYPE=LEGEND_OBJECTSTYLE@ENDTYPE;@VALU=#Back_Ground_Color#=13434880;#Pen_Color#=16777215;#Pen_Size#=1;#Legend_Type#=LEGEND_OBJECTSTYLE;@ENDVALU;@PRMT=4@ENDPRMT;@ENDPROP;@PROP=@NAME=@ENDNAME;@TYPE=LEGEND_OBJECTSTYLE@ENDTYPE;@VALU=#Back_Ground_Color#=-1;#Pen_Color#=16777215;#Pen_Size#=1;#Legend_Type#=LEGEND_OBJECTSTYLE;@ENDVALU;@PRMT=5@ENDPRMT;@ENDPROP;@PROP=@NAME=Legend@ENDNAME;@TYPE=LEGEND_STYLE_SETTINGS@ENDTYPE;@VALU=@ENDVALU;@PRMT=@ENDPRMT;@ENDPROP;');
The sql statement appears that it isn’t working and there is nothing in DBError.txt