Book a Demo

Author Topic: Adding a hyperlink to a diagram via JScript creates the wrong stereotype  (Read 4923 times)

StefanBrandmeier

  • EA Novice
  • *
  • Posts: 17
  • Karma: +0/-0
    • View Profile
Hi,
when adding a hyperlink using this code:
contentElement = relatedElement.Elements.AddNew("Glossary" ,"Hyperlink");
a hyperlink is created but of the stereotype "Wireframing::WireframeHyperlink".

When adding the hyperlink stereotype from the EA GUI - found in the profile common then the right stereotype is added to the diagramm.

As a workaround: how to set the actual URL in script JScript for the WireframeHyperlink ? It should be set such that the link is clickable in the html exports of our Models.

Thanks for any support on this.
Cheers
Stefan

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Since you did not use the FQN for the stereotype EA starts guessing. Either use the correct FQN (what ever that might be - ask Sparx) or you turn off the Wireframe MDG.

As Geert said below and correctly: it's the wrong type (I was in a hurry and got mixed up with stereotypes which are not supplied here). But obviously it looks for a metatype in activated MDGs. Effect is the same...

q.
« Last Edit: May 18, 2022, 10:27:54 pm by qwerty »

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
A standard hyperlink is not of type "Hyperlink" but of type "Text", with subtype 19

So you'd do

Code: [Select]
contentElement = relatedElement.Elements.AddNew("Glossary" ,"Text");
contentElement.SubType = 19
contentElement.Update

If you supply a type that EA doesn't know, it will look into all available MDG's to find a stereotype that matches the type, and use the first one it finds.
(like a box of chocolates, you never know what you're going to get)

Geert

StefanBrandmeier

  • EA Novice
  • *
  • Posts: 17
  • Karma: +0/-0
    • View Profile
Hello Geert, thanks with your help my code now does create the right object. However, while it did add the wireframehyperlink to the class on my diagram (i.e. the hyperlink was then part of the class) - it does not add it to the class now but just drops it on the diagram. When adding a hyperlink via the EA GUI it also does not create an object which is visible on the project browser. Maybe that's why this object type cannot be added to the elements collection of a class element ?
Is there another way to add this object type to the elements list than what I did ?

Thank you for your help
Cheers

// create the object as part of the original class element
// the subtype 19 makes it a correct "hyperlink" object
contentElement = relatedElement.Elements.AddNew("Glossary" ,"Text");

// with this code it creates a wireframehyperlink and later successfully adds it to the class on the diagram
//contentElement = relatedElement.Elements.AddNew("Glossary" ,"Hyperlink");

contentElement.Subtype = 19;
contentElement.Update();
Session.Output("contentElement: " + contentElement.Alias + " stereotypeex: " + contentElement.StereotypeEx);
               
// create the diagram object and replace the ElementID with the hyperlink created above
diagramHyperlink = currentDiagram.DiagramObjects.AddNew("l=100;r=100;t=100;b=10;", "Text" );
diagramHyperlink.ElementID(contentElement.ElementID);
diagramHyperlink.Update();
currentDiagram.Update();


Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Yes indeed.
You are not supposed to add Text elements as an owned element of another element. (EA's GUI won't let you do that either)

Text elements are "diagram local" elements and are supposed to live where the diagram lives. (they also move together with the diagram)
If your diagram is owned by a package you can add the Text element using the package.Elements collection.

I'm not sure what happens if your diagram is owned by another element. In that case it would seem logical to add it to the owning element's Elements collection, but EA is not necessarily logical.
You better test it by first adding one manual, and then checking what it created in the database (is the parentID filled in or not)

Geert

StefanBrandmeier

  • EA Novice
  • *
  • Posts: 17
  • Karma: +0/-0
    • View Profile
In fact, using the EA GUI you can drop a hyperlink directly onto a class and it is embedded. Try it yourself.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
In fact, using the EA GUI you can drop a hyperlink directly onto a class and it is embedded. Try it yourself.
In that case I stand corrected. I assumed it was not possible.
I should know better than to assume things when it comes to EA's GUI  ;D

Geert

StefanBrandmeier

  • EA Novice
  • *
  • Posts: 17
  • Karma: +0/-0
    • View Profile
Not a problem Geert. I am also puzzled at why code lets me add the hyperlink to the class but then
shows it outside the class. Given the behavior for the wireframehyperlink it was my assumption that it
should work as well with the hyperlink(text with subtype 19).
I opened a ticket with sparx about the wireframehyperlink that is created in my original code. They will hopefully
come back with the same sort of insight you gave in your initial reply.
I will try to "complain" about the problem with adding the hyperlink to the class' elements collection.
Will keep you posted if there is a solution. Please let me know if some idea pops up at your end.

Thanks
Stefan

StefanBrandmeier

  • EA Novice
  • *
  • Posts: 17
  • Karma: +0/-0
    • View Profile
what is also interesting - when adding the hyperlink using the subtype 19 it is set to a link type "File". I can set the Address via element.Name
but I have no clue how to change the link type to "web site". Could it be that I have to go to the dirty ways of SQL interaction with the repository
to do this ?

I found it: contentElement.Name = "$inet://https://..../asset/fbe3455c-f811-4b8f-b747-1343ebfd808d" will change the link type to "web site".

And with a bit of trial and error I found:

- the hyperlink object is actually added to the diagramobject
- it is the z-order that needs to be fixed and the location where I drop the hyperlink via code. So

diagramObject.Sequence = diagramHyperlink.Sequence+1;

after I make sure the hyperlink is created on (geometrically) in the area of the diagramObject.

So now I have the solution I was looking for

Cheers
« Last Edit: May 20, 2022, 01:55:19 am by StefanBrandmeier »