Book a Demo

Author Topic: Creating Document Script including formatted notes  (Read 4812 times)

PeteEA

  • EA Novice
  • *
  • Posts: 13
  • Karma: +0/-0
    • View Profile
Creating Document Script including formatted notes
« on: June 17, 2020, 12:44:24 am »
I am creating a custom document output using a document Fragment with Document Script. I'm using Repository.CreateDocumentGenerator to create the document.

Most of it gets created fine. The sticking point are the Notes fields - they may include bold, bullet lists etc. Simply adding the Notes property results in the formatting being HTML-like (e.g. <B> for bold text </B>) and included in the final document.

A partial solution is to use Repository.GetFormatFromField("RTF", element.Notes), save that to a temporary file and then use reporting.LoadDocument to include that RTF formatted text in my document section.

The problem is that the font style changes - while text generated using reporting.InsertText, reporting.InsertLinkedDocument and the export to a file are identified as "Normal", it seems like there are two different definitions of Normal in the final document, which I didn't realise was possible. InsertLinkedDocument  and export RTF/LoadDocument are one type of Normal font setting while InsertText is a different Normal font setting. Having written this I'm not even sure that EA is showing the paragraph style correctly in the document editor - everything I put the cursor on is Normal, even if I change it or select a line that is specifically a heading! (so maybe they are not all being generated as Normal even though it looks like they are).

I am happy to change tack completely - all I want to achieve is to getting notes with their formatting included in a Word output and all other text generated in the document in the same font style.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Creating Document Script including formatted notes
« Reply #1 on: June 17, 2020, 03:19:23 am »
Any reason you chose Document Script instead of Script fragment or SQL Fragment?
Both have an option to mark a field as formatted text.

I've never actually needed to use a Document Script fragment, and I've done quite a few document generation projects so far.

Geert

PeteEA

  • EA Novice
  • *
  • Posts: 13
  • Karma: +0/-0
    • View Profile
Re: Creating Document Script including formatted notes
« Reply #2 on: June 17, 2020, 06:33:10 pm »
I'm trying to build a document of the details of all conveyed items on connectors connected to an element - it seemed easiest to pass the element to the document script, iterate the connectors of the element, iterate the conveyed items and then build the document as the script progressed.

I'm including the connected element in the heading.

So this morning, I've looked at using a script fragment - if I passed the connector in then I could build it section by section, running a script on each connector and returning the conveyed items in XML, but it looks like the Template Fragment can only work on an element (Insert Template is only available in the "element>" section and not the "connector>" section of a document template). So I'd have to pass the element to the script, compile XML with each connector, the source or destination element and any conveyed item details, to build back up in the document with certain parts as headings.

I've only used a script fragment to return one or a small number of elements in one section of a document, with the small template repeated for every element.

At first sight it looks like it would be harder to build the XML to get everything in the right place in the document compared to building the whole thing in a Document Script.

Should I switch to a Script Fragment?

Uffe

  • EA Practitioner
  • ***
  • Posts: 1859
  • Karma: +133/-14
  • Flutes: 1; Clarinets: 1; Saxes: 5 and counting
    • View Profile
Re: Creating Document Script including formatted notes
« Reply #3 on: June 17, 2020, 07:15:56 pm »
Hi Pete,


I don't think you need a script fragment, or any fragment, if you're using DocumentGenerator. The most flexible way of using that is with custom templates and .DocumentCustomData(), passing the content as an XML document. This method gives the highest degree of control, but you do have to write all the content retrieval and model traversal into your script. Which I prefer anyway, but that's just me.

There are two ways of passing formatted data to .DocumentCustomData().

Method #1: Dot-Formatted
  • In the template, place a custom field {MyField.Formatted}  .
  • In the XML document, give the corresponding XML element the name "MyField-Formatted"  .
Method #2: "formatted" attribute
  • In the template, place a custom field {MyField}  .
  • In the XML document, give the corresponding XML element the name "MyField"  .
  • In the XML document, give the "MyField" element an attribute "formatted" with the value "1"  .

I can't think offhand if there's a situation in which one of these works but not the other, but I'm pretty sure the Dot-Formatted method can also be used with non-custom templates.

HTH,


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

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Creating Document Script including formatted notes
« Reply #4 on: June 17, 2020, 09:36:00 pm »
Pete,

What I do in cases like that is use a script to build my virtual document.
Each model document often refers to a single element (using query with guid as parameter)

The advantage of this approach is that you can keep the templates themselves pretty simple, and you can manually adjust stuff after generating the virtual document (change order, remove sections, add a introduction section,...)

There are many ways to get to the same result, depends a bit on what you are familiar with, and your specific requirements.

Geert