Book a Demo

Author Topic: Document generation: Hyperlinks  (Read 7395 times)

Uffe

  • EA Practitioner
  • ***
  • Posts: 1859
  • Karma: +133/-14
  • Flutes: 1; Clarinets: 1; Saxes: 5 and counting
    • View Profile
Document generation: Hyperlinks
« on: November 16, 2019, 12:30:26 am »
Hi everybody,


I've got a bunch of elements which each has a name and one (1) "Web Address" File.
I want to output these elements in a table with hyperlinks which work in Word.

There is a field {ElemFile.Hyperlink} available in the template which gives me what I want, except the URL is used both for the link target and the displayed link text. I instead want the displayed text to be the element name.

Is there a way to do this?

I've tried inserting a hyperlink in the RTF editor, and setting the link text to {Element.Name} and the link code (as it's referred to in that dialog) to {ElemFile.FilePath} in the hope that the document generation would recognize them as fields and perform the substitution, but that didn't work.

I've also tried storing a brief text in the File Note, hoping EA would pick that up and use it for the link text, but no luck.

Any other suggestions?


/Uffe
My theories are always correct, just apply them to the right reality.

Uffe

  • EA Practitioner
  • ***
  • Posts: 1859
  • Karma: +133/-14
  • Flutes: 1; Clarinets: 1; Saxes: 5 and counting
    • View Profile
Re: Document generation: Hyperlinks
« Reply #1 on: November 16, 2019, 12:58:42 am »
Oh, and I'm using the DocumentGenerator API so if there's a way to do it using .InsertText() or .DocumentCustomData() I'm up for it.

/U
My theories are always correct, just apply them to the right reality.

Uffe

  • EA Practitioner
  • ***
  • Posts: 1859
  • Karma: +133/-14
  • Flutes: 1; Clarinets: 1; Saxes: 5 and counting
    • View Profile
Re: Document generation: Hyperlinks
« Reply #2 on: November 16, 2019, 04:04:54 am »
Found it. It's DocumentGenerator.DocumentCustomData() to the rescue.

All you do is
  • Create a template fragment with a custom field "LinkedName" or whatever.
    The template fragment should have no script reference or SQL query, just leave that part empty.
  • When you create the XML data, construct a hyperlink in EA's internal format.
    <a href="$inet://https://sparxsystems.com"><font color="#0000ff"><u>LINK_LABEL_HERE</u></font></a>
  • Give the XML element an attribute "formatted=1".
  • Pass your XML data to the template fragment.
That $inet:// thing is EA's way of separating web-type hyperlinks from in-project ones. I haven't tested stripping that out, but EA gets rid of it during document generation so Word recognizes the link as a well-formed URL without further intervention from me.

Easy peasy.

/Uffe

EDIT 2019-11-19:
The originally posted solution only works when the template fragment is local to the project. If you deploy it through an MDG Technology, you must use a full template instead of a fragment.
« Last Edit: November 20, 2019, 04:01:51 am by Uffe »
My theories are always correct, just apply them to the right reality.

Uffe

  • EA Practitioner
  • ***
  • Posts: 1859
  • Karma: +133/-14
  • Flutes: 1; Clarinets: 1; Saxes: 5 and counting
    • View Profile
Re: Document generation: Hyperlinks
« Reply #3 on: November 16, 2019, 04:06:07 am »
Wow Uffe, that's really useful.

Thanks for taking the time.  :)
My theories are always correct, just apply them to the right reality.

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Document generation: Hyperlinks
« Reply #4 on: November 16, 2019, 08:37:15 am »
You know what? I don't use that document generator. I wrote my own generator that creates LaTeX. And a secret: If I find a bug, I can fix it. TeX itself is almost bug free (go try to find one and earn a couple of thousand dollars from Donald Knuth) and LaTeX/the packages you need are also well tested by many many scientists. So if somethings runs wrong I use the debugger and some of my time to make it right. Mean, I know...

q.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Document generation: Hyperlinks
« Reply #5 on: November 16, 2019, 09:36:31 pm »
Wow Uffe, that's really useful.

Thanks for taking the time.  :)
Thanks Uffe, I think that will be useful for me one day.

Geert

PS. If you write an url as a simple text then you can force Word to make it into clickable hyperlinks with a small macro. (of even a key combination, but I don't remember which one exactly)

Sunshine

  • EA Practitioner
  • ***
  • Posts: 1353
  • Karma: +121/-10
  • Its the results that count
    • View Profile
Re: Document generation: Hyperlinks
« Reply #6 on: November 17, 2019, 06:18:33 am »
Wow Uffe, that's really useful.

Thanks for taking the time.  :)
Thanks Uffe I'm sure it will be useful one day.
Happy to help
:)

Sunshine

  • EA Practitioner
  • ***
  • Posts: 1353
  • Karma: +121/-10
  • Its the results that count
    • View Profile
Re: Document generation: Hyperlinks
« Reply #7 on: November 17, 2019, 06:36:12 am »
You know what? I don't use that document generator. I wrote my own generator that creates LaTeX. And a secret: If I find a bug, I can fix it. TeX itself is almost bug free (go try to find one and earn a couple of thousand dollars from Donald Knuth) and LaTeX/the packages you need are also well tested by many many scientists. So if somethings runs wrong I use the debugger and some of my time to make it right. Mean, I know...

q.
You know many years ago I did the same thing and I wrote my own document generator using MS Word Macro. It generated docs from Popkin System Architect. Then I moved to Sparx EA when it only had that legacy doc generator so I convert my custom MS Word Generator to use Sparx EA which worked fine for about a five years. Later Sparx Systems added the current document generator and I've moved over to using that and found that's been good enough once I got used to all its nuances. Not come across many bugs with it.
From time to time I've tried other tools in the top gartner magic quadrant and their doc generation tools aren't that great. So I consider Sparx EA is a better choice.
 
Happy to help
:)

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Document generation: Hyperlinks
« Reply #8 on: November 17, 2019, 09:01:37 am »
I only used the doc generator in the beginning (V3 or 4) and it was honestly just crap. I heard it got better. Obviously, since the number of complaints isn't that high. Now, why am I still not using it? There are two reasons: first I can compile any complex requirement for a document as I'm using my preferred language (which is simply Python but any other would do as well). The second even more important reason: it produces PDF and no choice to have Word at all. Now, why is it that important? Because any 馬鹿 wants Word to just starting to correct things in that export. A r/w export is just a fail in itself. PDF still allows to comment, but it's not that easy as in a Word document. That's why people get used to make the changes where they ought to be: in the model. Not having Word means: stepping towards the single source of truth. Using Word means open the gates to hell. Where is the truth? In which version of which copy on whose desk?

q.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Document generation: Hyperlinks
« Reply #9 on: December 02, 2019, 10:03:09 pm »
I knew I would need it shortly, and indeed I did.

My use case was that I needed a hyperlink
I used Uffe's trick to make an "Custom Script" fragment, in which I call my script using the line

MyRtfData(#PACKAGEID#, "http://myDomain.local")

In the script I have specified the following

Code: [Select]
function MyRtfData (packageID, 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" )

dim diagramUrl
diagramUrl = getDiagramLink(packageID, baseUrl)
xmldiagramLink.text = "<a href=""$inet://" & diagramUrl &"""><font color=""#0000ff""><u>" & diagramUrl & "</u></font></a>"
xmldiagramLink.setAttributeNode(formattedAttr)
xmlRow.appendChild xmldiagramLink

MyRtfData = xmlDOM.xml
end function

function getDiagramLink(packageID, baseUrl)
dim package as EA.Package
set package = Repository.GetPackageByID(packageID)
dim link
link = baseUrl & "/?guid="
dim diagram as EA.Diagram
for each diagram in package.Diagrams
'get diagram GUID
link = link & diagram.DiagramGUID
'remove braces
link = replace(link, "{","")
link = replace(link, "}","")
exit for
next
'return
getDiagramLink = link
end function

Geert

Ian Mitchell

  • EA User
  • **
  • Posts: 507
  • Karma: +22/-4
  • The eaDocX and Model Expert guy
    • View Profile
Re: Document generation: Hyperlinks
« Reply #10 on: December 07, 2019, 02:04:30 am »
eaDocX has been doing this for years - it finds a URL, and prints a hyperlink in Word.
And you don't need to be a programming genius to use it.
...but I recognize everyone in this thread is already a programming genius...
Just trying to help...
Ian Mitchell, Designer, eaDocX


www.eaDocX.com
www.theartfulmodeller.com