Author Topic: Creating clickable links in generated documents  (Read 1663 times)

thompp

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
Creating clickable links in generated documents
« on: January 20, 2023, 03:10:38 am »
Hi.
I was wondering if any of you knowledgeable people can help me.
In EA Sparx (v15.2) we have notes in entities which get listed out in generated docs. These links often contain url links. Is there any way to make these links clickable in the generated docs? unfortunately <a>url</a> doesn't seem to work

Thanks
Pete

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13295
  • Karma: +557/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Creating clickable links in generated documents
« Reply #1 on: January 20, 2023, 04:51:19 am »
IIRC, if you a link into the notes with the proper icon, it translates into a clickable link in the document.

An alternative, for example to generate a WebEA or HTML Export link, is to use a script fragment.

Here's the one I use:

Code: [Select]
'[path=\Projects\Project A\Template fragments]
'[group=Template fragments]
option explicit

!INC Local Scripts.EAConstants-VBScript

'
' Script Name: DiagramLink
' Author: Geert Bellekens
' Purpose: get the hyperlink for a diagram
' Date: 2019-12-02
'

function getObjectDiagramLink(objectID, baseUrl)
dim element
set element = Repository.GetElementByID(objectID)
'get diagram
dim diagram
set diagram = getFirstDiagram(element)
'get the xml data
getObjectDiagramLink = getRTFData(diagram, baseUrl)
end function

function getPackageDiagramLink (packageID, baseUrl)
dim package as EA.Package
set package = Repository.GetPackageByID(packageID)
'get diagram
dim diagram
set diagram = getFirstDiagram(package)
'get the xml data
getPackageDiagramLink = getRTFData(diagram, baseUrl)
end function

function getRTFData(diagram, baseUrl)

dim diagramUrl
diagramUrl = getDiagramLink(diagram, baseUrl)

dim xmlDOM
set  xmlDOM = CreateObject( "Microsoft.XMLDOM" )
'set  xmlDOM = CreateObject( "MSXML2.DOMDocument.4.0" )
xmlDOM.validateOnParse = false
xmlDOM.async = false

dim node
set node = xmlDOM.createProcessingInstruction( "xml", "version='1.0'")
    xmlDOM.appendChild node
'
dim xmlRoot
set xmlRoot = xmlDOM.createElement( "EADATA" )
xmlDOM.appendChild xmlRoot

dim xmlDataSet
set xmlDataSet = xmlDOM.createElement( "Dataset_0" )
xmlRoot.appendChild xmlDataSet

dim xmlData
set xmlData = xmlDOM.createElement( "Data" )
xmlDataSet.appendChild xmlData

dim xmlRow
set xmlRow = xmlDOM.createElement( "Row" )
xmlData.appendChild xmlRow

dim formattedAttr
set formattedAttr = xmlDOM.createAttribute("formatted")
formattedAttr.nodeValue="1"

dim xmldiagramLink
set xmldiagramLink = xmlDOM.createElement( "DiagramLink" )

xmldiagramLink.text = "<a href=""$inet://" & diagramUrl &"""><font color=""#0000ff""><u>" & diagram.Name & "</u></font></a>"
xmldiagramLink.setAttributeNode(formattedAttr)
xmlRow.appendChild xmldiagramLink

getRTFData = xmlDOM.xml
end function

function getFirstDiagram(diagramOwner)
set getFirstDiagram = nothing 'initialize
'get first diagram
dim diagram as EA.Diagram
for each diagram in diagramOwner.Diagrams
set getFirstDiagram = diagram
exit function
next
end function

function getDiagramLink(diagram, baseUrl)
dim link
link = baseUrl & "/?guid="
'get diagram GUID
link = link & diagram.DiagramGUID
'remove braces
link = replace(link, "{","")
link = replace(link, "}","")
'return
getDiagramLink = link
end function

'msgbox MyPackageRtfData(3357,"")
function test
dim outputString
dim fileSystemObject
dim outputFile

outputString =  getPackageDiagramLink (1783, "http://myserver.local")
'outputString =  getObjectDiagramLink (7220, "http://myserver.local")

set fileSystemObject = CreateObject( "Scripting.FileSystemObject" )
set outputFile = fileSystemObject.CreateTextFile( "C:\Users\gbl\Documents\Temp\diagramLink.xml", true )
outputFile.Write outputString
outputFile.Close
end function

'test

Geert

thompp

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
Re: Creating clickable links in generated documents
« Reply #2 on: January 20, 2023, 11:44:38 pm »
Thanks for your reply, Geert.
By the way, previously, I've used your excellent Excel macros for exchanging data between Excel and Sparx.
I'm not sure what you've suggested is exactly what I'm looking for. On our site, we frequently embed links to external web sites (for example, the web site for an organisation or a government department) within the text of the notes of an entity, such as an organisational actor. When this text gets produce in generated document from a template into a Word document, can we get these links to be clickable links within the generated Word document?
Regards
Pete

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13295
  • Karma: +557/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Creating clickable links in generated documents
« Reply #3 on: January 21, 2023, 01:34:15 am »
If those these links are formatted as links in EA (using the hyperlink button on the notes dialog) then they should be clickable in the generated document.

If that is not the case you might want to report a bug.

In the meantime, or if the urls are not formatted, you can create a script fragment that takes your notes, figures out where the hyperlinks are, and formats them such that they become clickable links in Word. You can use the script I posted as a basis on how to do that.

Geert