Book a Demo

Author Topic: Insert a Legend  (Read 10368 times)

Benny

  • EA Novice
  • *
  • Posts: 15
  • Karma: +0/-0
    • View Profile
Insert a Legend
« on: April 13, 2017, 11:35:13 pm »
Hi,

I managed to insert a Legend in a Diagram with a Script

Code: [Select]
set legend = currentPackage.Elements.AddNew( "", "Text")
hyperLink.Subtype = 76

How can I fill these legend with values using a script.

I inserted a legend using the "normal" way in sparx and searched for any reference in the database.
But I just found the SubType 76 Statement and some values in the StyleEx Row.
But where are the values and colors of the Legend defined ?

Maby someone has hint for me?


/Benny

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Insert a Legend
« Reply #1 on: April 14, 2017, 05:57:59 am »
That's a bit tricky. AFAIK there is no API for filling a legend (yes, we deal with EA). So what it does, is creating an entry in t_xref (where else). And it uses one of those coding that look like an armadillo has been rolled over the keyboard. Anyway, here's what they do. For the Legend a single entry in t_xref is created.

Name = CustomProperties
Type = element property
Visibility = public
Description = "the armadillo part, see below"
Client = <the ea-guid of the legend object>

So here's what a legend with "a" and "b" where "b" has a custom color and a 2-size line style produces:

Description;

@PROP=@NAME=a@ENDNAME;@TYPE=LEGEND_OBJECTSTYLE@ENDTYPE;@VALU=#Back_Ground_Color#=16777215;#Pen_Color#=0;#Pen_Size#=1;#Legend_Type#=LEGEND_OBJECTSTYLE;@ENDVALU;@PRMT=0@ENDPRMT;@ENDPROP;@PROP=@NAME=b@ENDNAME;@TYPE=LEGEND_OBJECTSTYLE@ENDTYPE;@VALU=#Back_Ground_Color#=2124031;#Pen_Color#=16711680;#Pen_Size#=2;#Legend_Type#=LEGEND_OBJECTSTYLE;@ENDVALU;@PRMT=1@ENDPRMT;@ENDPROP;@PROP=@NAME=Legend@ENDNAME;@TYPE=LEGEND_STYLE_SETTINGS@ENDTYPE;@VALU=#TITLE#=Legend;@ENDVALU;@PRMT=@ENDPRMT;@ENDPROP;;


I guess you can decode that without assistance. The best is to create an empty model with just one legend and inspect the t_xref entry on how it changes with different parameters.

Good luck (I might add that to my Inside book soon).

q.

Benny

  • EA Novice
  • *
  • Posts: 15
  • Karma: +0/-0
    • View Profile
Re: Insert a Legend
« Reply #2 on: April 19, 2017, 01:05:21 am »
Thank you very much.  :D

philchudley

  • EA User
  • **
  • Posts: 750
  • Karma: +22/-0
  • EA Consultant / Trainer - Sparx Europe
    • View Profile
Re: Insert a Legend
« Reply #3 on: April 19, 2017, 05:59:49 pm »
Following on from QWERTY's post

I have done this for a client using a script (jscript) and yes it is very convoluted.

Once you have deciphered the t_xref entry you then have to:

a) create a legend element
b) insert this entry into the t_xref table, which includes the link to the element created in a)
c) add the legend to the diagram

You will also have to investigate the type of element a legend is and discover a way to generate a GUID for the t_xref entry.

As there is no API to add directly into t_xref, I used the undocumented function execute on a SQL INSERT statement for the t_xref

Oh, the colours in the t_xref entry do not appear to be standard integer values from RGB!

As QWERTY suggested, create yourself a little eap create a diagram and then add a legend, then inspect the underlying tables. This is what I did to work it all out.

Best of luck!

Phil
Models are great!
Correct models are even greater!

KP

  • EA Administrator
  • EA Expert
  • *****
  • Posts: 2919
  • Karma: +55/-3
    • View Profile
Re: Insert a Legend
« Reply #4 on: April 20, 2017, 08:54:37 am »
Oh, the colours in the t_xref entry do not appear to be standard integer values from RGB!

They are decimal values of 6 character hexadecimals. Red is 255 (FF16), Green is 65280 (FF0016), Blue is 16711680 (FF000016) etc
The Sparx Team
[email protected]

Benny

  • EA Novice
  • *
  • Posts: 15
  • Karma: +0/-0
    • View Profile
Re: Insert a Legend
« Reply #5 on: May 04, 2017, 08:08:50 pm »
Hi,

i managed to generate a full legend and everything is working fine... in my local test *.EAP  ;D



Code: [Select]
dim legend as EA.Element
dim SQL
dim xrefGUID

set legend = currentPackage.Elements.AddNew( "", "Text")
legend.Subtype = 76
'legend.Notes = ""
legend.Update

xrefGUID = GUIDGenerateGUID()
SQL = "INSERT INTO `t_xref`" &_
  "(`XrefID`, `Name`, `Type`, `Visibility`, `Namespace`, `Requirement`, `Constraint`, `Behavior`, `Partition`, `Description`, `Client`, `Supplier`, `Link`)"&_
  "VALUES('" & xrefGUID & "', 'CustomProperties', 'element property', 'Public', NULL, NULL, NULL, NULL, '0', '@PROP=@NAME=Test Eins@ENDNAME;@TYPE=LEGEND_OBJECTSTYLE@ENDTYPE;@VALU=#Back_Ground_Color#=55295; [cut]', '"& legend.ElementGUID &"', '<none>', NULL);"

Repository.Execute SQL

But in my productive Project *.EAP it does not work  >:(
It seems there is an SQL Syntax failure or something ?
The productive Project runs on an MS OLEDB SQL Server

I tryed to get rid of the " ` " but it does not help.

Does anyone know what the Problem is?
It runs perfecly fine on the local EAP file.

/Benny

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Insert a Legend
« Reply #6 on: May 04, 2017, 09:58:42 pm »
You need to tinker with that. Mickeysoft's products prefer square brackets at all places. Look into %appdata%\...\dberror.txt. It might have a hint.

q.

Benny

  • EA Novice
  • *
  • Posts: 15
  • Karma: +0/-0
    • View Profile
Re: Insert a Legend
« Reply #7 on: May 05, 2017, 01:05:40 am »
THANKS  ;D


Code: [Select]
xrefGUID = GUIDGenerateGUID()
SQL = "INSERT INTO [t_xref] " &_
  "([XrefID], [Name], [Type], [Visibility], [Namespace], [Requirement], [Constraint], [Behavior], [Partition], [Description], [Client], [Supplier], [Link])"&_
  " VALUES('" & xrefGUID & "', 'CustomProperties', 'element property', 'Public', NULL, NULL, NULL, NULL, '0', '@PROP=@NAME=Eins@ENDNAME;@TYPE=LEGEND_OBJECTSTYLE@ENDTYPE;@VALU=#Back_Ground_Color#=55295;#Pen_Color#=0;#Pen_Size#=1;#Legend_Type#=LEGEND_OBJECTSTYLE;@ENDVALU;@PRMT=0@ENDPRM.....);"
msgbox(SQL)
Repository.Execute SQL

square brackets ....  I hate them  :P

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Insert a Legend
« Reply #8 on: May 05, 2017, 05:04:03 am »
Mickeysoft has a hand for finding hateful things xD Latest that Tay AI...

q.

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: Insert a Legend
« Reply #9 on: May 05, 2017, 08:32:55 am »
The square brackets are not from or for Microsoft products. They are interpreted by EA to escape keywords as needed for each database type, using the syntax of that database.