Sparx Systems Forum

Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: Ruff on January 03, 2025, 07:18:19 am

Title: Adding a legend with values to a diagram via script.
Post by: Ruff on January 03, 2025, 07:18:19 am
I was inspired by Java inserting into a legend  (https://stackoverflow.com/questions/26280146/enterprise-architect-scripting-with-java-add-customproperty)
I have no issues adding the legend 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)

Here's the SQL statement in generates (https://carbon.now.sh/?bg=rgba%28171%2C+184%2C+195%2C+1%29&t=seti&wt=none&l=auto&width=680&ds=true&dsyoff=20px&dsblur=68px&wc=true&wa=true&pv=56px&ph=56px&ln=false&fl=1&fm=Hack&fs=14px&lh=133%25&si=false&es=2x&wm=false&code=%250AHere%27s%2520the%2520SQL%2520statement%2520in%2520generates%253A%250A%255Bcode%255D%250A%2522INSERT%2520INTO%2520t_xref%2520%250A%2520%2520%2520%28Client%252CXrefID%252CType%252CName%252CVisibility%252CPartition%252CSupplier%252CDescription%29%2520%2520%250AVALUES%2520%250A%2520%2520%2520%28%27%257B9CCF46B8-D221-41b1-B1B9-EF7072547F74%257D%27%252C%27%257Bcb940358-f76f-9fdd-dfca-d4537143e394%257D%27%252C%27element%2520property%27%252C%27CustomProperties%27%252C%27Public%27%252C%270%27%252C%27%2526lt%253Bnone%2526gt%253B%27%252C%250A%27%2540PROP%253D%2540NAME%253DArchiMate_Grouping%2540ENDNAME%253B%2540TYPE%253DLEGEND_OBJECTSTYLE%2540ENDTYPE%253B%2540VALU%253D%2523Back_Ground_Color%2523%253D13458026%253B%2523Pen_Color%2523%253D16777215%253B%2523Pen_Size%2523%253D1%253B%2523Legend_Type%2523%253DLEGEND_OBJECTSTYLE%253B%2540ENDVALU%253B%2540PRMT%253D0%2540ENDPRMT%253B%2540ENDPROP%253B%2540PROP%253D%2540NAME%253DArchiMate_Capability%2540ENDNAME%253B%2540TYPE%253DLEGEND_OBJECTSTYLE%2540ENDTYPE%253B%2540VALU%253D%2523Back_Ground_Color%2523%253D15528442%253B%2523Pen_Color%2523%253D16777215%253B%2523Pen_Size%2523%253D1%253B%2523Legend_Type%2523%253DLEGEND_OBJECTSTYLE%253B%2540ENDVALU%253B%2540PRMT%253D1%2540ENDPRMT%253B%2540ENDPROP%253B%2540PROP%253D%2540NAME%253DArchiMate_Capability%2540ENDNAME%253B%2540TYPE%253DLEGEND_OBJECTSTYLE%2540ENDTYPE%253B%2540VALU%253D%2523Back_Ground_Color%2523%253D16777184%253B%2523Pen_Color%2523%253D16777215%253B%2523Pen_Size%2523%253D1%253B%2523Legend_Type%2523%253DLEGEND_OBJECTSTYLE%253B%2540ENDVALU%253B%2540PRMT%253D2%2540ENDPRMT%253B%2540ENDPROP%253B%2540PROP%253D%2540NAME%253DArchiMate_Capability%2540ENDNAME%253B%2540TYPE%253DLEGEND_OBJECTSTYLE%2540ENDTYPE%253B%2540VALU%253D%2523Back_Ground_Color%2523%253D16443110%253B%2523Pen_Color%2523%253D16777215%253B%2523Pen_Size%2523%253D1%253B%2523Legend_Type%2523%253DLEGEND_OBJECTSTYLE%253B%2540ENDVALU%253B%2540PRMT%253D3%2540ENDPRMT%253B%2540ENDPROP%253B%2540PROP%253D%2540NAME%253DArchiMate_Grouping%2540ENDNAME%253B%2540TYPE%253DLEGEND_OBJECTSTYLE%2540ENDTYPE%253B%2540VALU%253D%2523Back_Ground_Color%2523%253D13434880%253B%2523Pen_Color%2523%253D16777215%253B%2523Pen_Size%2523%253D1%253B%2523Legend_Type%2523%253DLEGEND_OBJECTSTYLE%253B%2540ENDVALU%253B%2540PRMT%253D4%2540ENDPRMT%253B%2540ENDPROP%253B%2540PROP%253D%2540NAME%253D%2540ENDNAME%253B%2540TYPE%253DLEGEND_OBJECTSTYLE%2540ENDTYPE%253B%2540VALU%253D%2523Back_Ground_Color%2523%253D-1%253B%2523Pen_Color%2523%253D16777215%253B%2523Pen_Size%2523%253D1%253B%2523Legend_Type%2523%253DLEGEND_OBJECTSTYLE%253B%2540ENDVALU%253B%2540PRMT%253D5%2540ENDPRMT%253B%2540ENDPROP%253B%2540PROP%253D%2540NAME%253DLegend%2540ENDNAME%253B%2540TYPE%253DLEGEND_STYLE_SETTINGS%2540ENDTYPE%253B%2540VALU%253D%2540ENDVALU%253B%2540PRMT%253D%2540ENDPRMT%253B%2540ENDPROP%253B%27%29%253B%2522%2520):(I can't post code but a paste link like this works?!?)


Link to Stack Overflow  (https://stackoverflow.com/questions/79324802/enterprise-architect-adding-an-label-to-a-legend-in-in-javascript)since I can't post code here.
Title: Re: Adding a legend with values to a diagram via script.
Post by: Geert Bellekens on January 03, 2025, 08:00:50 pm
What I've answered on SO:

Quote
You can't execute update or insert statements using Repository.SQLQuery()

You can use the undocumented and unsupported method Repository.Execute(), but you better be damn sure of what you are doing. This has the potential to seriously corrupt your model.

Geert
Title: Re: Adding a legend with values to a diagram via script.
Post by: philchudley on January 03, 2025, 11:20:25 pm
Hi All

I have achieved this via a Model Based add-in, but as Geert says it is NOT trivial.

In addition to creating a Text element with a subtype = 76, all the legend stuff is located in t_xref with a specific ; delimited string and the RGB values must be stored in EA's own integer values this entry is then cross referenced to the Text element. This requires a new entry per legend to be created in t_xref with each having its own GUID.

Phil