Sparx Systems Forum

Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: MatthiasVDE on September 05, 2020, 04:24:25 pm

Title: Add a diagram hyperlink to diagram
Post by: MatthiasVDE on September 05, 2020, 04:24:25 pm
Hi,


I have a landingpage,where I want to put hyperlinks to other diagrams.

Example: https://i.imgur.com/airVpHU.png

Code: [Select]
'add diagram hyperlink
dim diagramHyperlink as EA.Element
set diagramHyperlink = diagramPackage.Elements.AddNew("","Text")
'diagramHyperlink.Notes = "Some text"
diagramHyperlink.Alias = "Name of source diagram"
diagramHyperlink.Stereotype = "NavigationCell"
diagramHyperlink.Update()

dim doHyperlink as EA.DiagramObject
set doHyperlink = diagram.DiagramObjects.AddNew("l=200;r=300;t=-20;b=-40", "")
doHyperlink.ElementID = diagramHyperlink.ElementID
doHyperlink.Update()

diagram.Update()
diagram.DiagramObjects.Refresh()
Repository.ReloadDiagram(diagram.DiagramID)

I am unable to set the properties in such a way that I get a hyperlink like in my example. Am I looking wrong?
Title: Re: Add a diagram hyperlink to diagram
Post by: Uffe on September 05, 2020, 07:40:25 pm
Hello Matthias,


I haven't created navigation cells in scripts myself, but it looks like you're missing a couple of parts.

You've created a Text element, which is right, but there are many subtypes of Text element and they're not all hyperlinks, so EA won't treat your element as a hyperlink unless it's told to. The subtype for a navigation cell is 82, so just add diagramHyperlink.Subtype = 82 to your element creation.

Secondly, the Text element Alias just contains the name of the target diagram. That's not enough for EA to resolve the link when you click it. You also need to set the target DiagramID (integer, not GUID) in Element.MiscData(0).

If you look in the database, the columns to look at are t_object.NType and t_object.PDATA1.

If you want to set the symbol on the navigation cell, it looks like that's in StyleEx (both in the database and the API). StyleEx contains a semicolon-separated set of property=value pairs, but the actual properties and values are notoriously undocumented.
The property in this case is "NID". For the values you'll just have to create a navigation cell with an image you like and check what's in the database. I tested with the lightbulb from the WebEA image list, which came out NID=2-7; so presumably the first number is the image list and the second is the index in the list.

But as you've no doubt noticed, you can just leave this empty resulting in a navigation cell with the icon in the top-right corner but without a main image.

HTH,


/Uffe
Title: Re: Add a diagram hyperlink to diagram
Post by: MatthiasVDE on September 09, 2020, 11:40:38 pm
Hello Uffe,

I'm still working on this and I got stuck on the update of the PDATA1 value. Because this property is read-only in the api, I need to update it via SQL.

Code: [Select]
sub setPDATA1ForElement(pdata1, elementID)
dim updateQuery
updateQuery= "update t_object set PDATA1 = "& pdata1 & " where Object_ID = " & elementID
Repository.SQLQuery updateQuery
end sub

Quote
The SELECT statement includes a reserved word or an argument name that is misspelled or missing, or the punctuation is incorrect

I'm working on a EAP file.
Title: Re: Add a diagram hyperlink to diagram
Post by: Geert Bellekens on September 09, 2020, 11:45:34 pm
You are missing single quotes in your update statement

Code: [Select]
updateQuery= "update t_object set PDATA1 = '"& pdata1 & "' where Object_ID = " & elementID
Geert
Title: Re: Add a diagram hyperlink to diagram
Post by: MatthiasVDE on September 10, 2020, 12:08:57 am
Hi Geert,

This doesn't work neither

Code: [Select]
sub setPDATA1ForElement(pdata1, elementID)
dim updateQuery
updateQuery= "update t_object set PDATA1 = '"& pdata1 & "' where Object_ID = " & elementID
Repository.SQLQuery updateQuery
end sub

but this does:

Quote
sub setPDATA1ForElement(pdata1, elementID)
   dim updateQuery
   updateQuery= "update t_object set PDATA1 = "& pdata1 & " where Object_ID = " & elementID
   Repository.Execute updateQuery
end sub
Title: Re: Add a diagram hyperlink to diagram
Post by: Geert Bellekens on September 10, 2020, 12:45:56 am
I don't get it, what did you change from your first attempt?

Those single quotes should really be there though.

Geert
Title: Re: Add a diagram hyperlink to diagram
Post by: MatthiasVDE on September 10, 2020, 01:03:46 am
I don't get it, what did you change from your first attempt?

Those single quotes should really be there though.

Geert

I added the quotes, but still got the error.

In my last attempt I used Repository.Execute instead of Respository.SQLQuery

Maybe it works without quotes because I inserted an integer/number ?
Title: Re: Add a diagram hyperlink to diagram
Post by: Uffe on September 10, 2020, 03:07:33 am
Hello again,


Repository.SQLQuery() only supports select. You need to use .Execute().

The PDATA columns are strings, so you should make a habit of adding the string characters when you're updating those. The string character varies with the database engine, so it could be either an apostrophe or a quotation mark.


/Uffe
Title: Re: Add a diagram hyperlink to diagram
Post by: MatthiasVDE on September 10, 2020, 02:41:11 pm
I didn't know this, Execute() is not described in the object model references on the EA website.
Title: Re: Add a diagram hyperlink to diagram
Post by: Geert Bellekens on September 10, 2020, 03:43:21 pm
I didn't know this, Execute() is not described in the object model references on the EA website.
No, it's not.
It's an undocumented, unsupported feature, that can really ruin your day (try forgetting a where clause ;D)

That's basically Sparx saying: Use at your own risk, and don't come crying if you messed up your repository.

Geert