Author Topic: Document Script Fragments  (Read 12651 times)

Uffe

  • EA Practitioner
  • ***
  • Posts: 1859
  • Karma: +133/-14
  • Flutes: 1; Clarinets: 1; Saxes: 5 and counting
    • View Profile
Document Script Fragments
« on: May 01, 2016, 02:08:54 am »
Hi all,


I'm trying to get to grips with document script fragments (hey, it's Saturday night), but I'm not getting anywhere and the help page is pretty uninformative.

Does the function script have to be called main(), or do I specify the function within the script like with Custom Script fragments?

Can I include an argument like #OBJECTID#?

In confusion,


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

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13303
  • Karma: +557/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Document Script Fragments
« Reply #1 on: May 01, 2016, 05:14:28 pm »
I'm pretty sure you have to call a specific operation in your template, so your function or sub can be named anything you want (just like the regular script fragments).

And if I'm right that means you can pass #OBJECTID# as a parameter in your function call.

Geert


Uffe

  • EA Practitioner
  • ***
  • Posts: 1859
  • Karma: +133/-14
  • Flutes: 1; Clarinets: 1; Saxes: 5 and counting
    • View Profile
Re: Document Script Fragments
« Reply #2 on: May 01, 2016, 06:22:51 pm »
Sounds right, and that's what I'm doing. But my RTF data, a linked document as returned from Element.GetLinkedDocument(), does not appear in the generated document.

But maybe I'm not including it correctly. How should I refer to the result in the template fragment?

With an SQL or regular script fragment, I return custom data fields, which I refer to in the fragment using the Custom section.

But if my script returns an entire document, what field "catches" it in the template? There's nothing like "RTF raw data" in the Custom section of the template editor. ... aaaaaand nothing in the help. :|

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

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13303
  • Karma: +557/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Document Script Fragments
« Reply #3 on: May 01, 2016, 07:42:22 pm »
Hmm, I actually don't know, I've never actually used one of those  :-\.
I would expect it to go in between the <custom tag.

I would send an email to sparx support and wait for their answer on Monday morning

Geert


Uffe

  • EA Practitioner
  • ***
  • Posts: 1859
  • Karma: +133/-14
  • Flutes: 1; Clarinets: 1; Saxes: 5 and counting
    • View Profile
Re: Document Script Fragments
« Reply #4 on: May 04, 2016, 02:42:34 pm »
OK, got it to work with a lot of help from Dermot over at Sparx support.

As per 1229, the only help page which discusses these Document Script fragments is Custom Query Fragments. They're not mentioned on Creating a Template Fragment, which they should be (in row 7). Until such time as the help pages are fixed, here's the scoop.

1) As with Custom Script template fragments, you specify a script and a function to be called within the script. It doesn't have to be called main().
2) JScripts work. I haven't tested the others, but I certainly suspect that VBScripts don't work.
3) The script has to return a text string containing RTF (as opposed to Custom Scripts, which return XML).
4) The script may take parameters, and passing #OBJECTID# works.
5) Passing #PACKAGEID# doesn't work. It parses, but comes out 0.
6) The RTF data is included in the template fragment by placing an empty custom> section in it. No fields in the section (another difference from Custom Script fragments).

That's it. Works like a charm.


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

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13303
  • Karma: +557/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Document Script Fragments
« Reply #5 on: May 04, 2016, 03:02:19 pm »
Thanks Uffe,

Saves me the hassle when I will ever need one of those.

Geert

Paolo F Cantoni

  • EA Guru
  • *****
  • Posts: 8599
  • Karma: +256/-129
  • Inconsistently correct systems DON'T EXIST!
    • View Profile
Re: Document Script Fragments
« Reply #6 on: May 04, 2016, 04:39:16 pm »
Thanks Uffe,

Saves me the hassle when I will ever need one of those.

Geert
+1

Can anyone confirm VBScripts do/don't work?

Paolo
Inconsistently correct systems DON'T EXIST!
... Therefore, aim for consistency; in the expectation of achieving correctness....
-Semantica-
Helsinki Principle Rules!

Glassboy

  • EA Practitioner
  • ***
  • Posts: 1367
  • Karma: +112/-75
    • View Profile
Re: Document Script Fragments
« Reply #7 on: May 05, 2016, 07:23:53 am »
I was very excited when the new feature document fragments was announced, but from all the posts on it it seems as much fun as stabbing yourself in the leg with a fork.

Uffe

  • EA Practitioner
  • ***
  • Posts: 1859
  • Karma: +133/-14
  • Flutes: 1; Clarinets: 1; Saxes: 5 and counting
    • View Profile
Re: Document Script Fragments
« Reply #8 on: May 05, 2016, 08:03:53 pm »
For me it's not so much the fragments as the RTF editor that makes me want to stab myself in the leg, gouge my eyes out and run head-first into a brick wall. YMMV.

But these Document Script fragments actually turn out to be pretty nifty. Since the script has access to the whole of the API, including DocumentGenerator, it should now be possible to generate arbitrarily complex documents, completely independent of the package hierarchy, with everything sorted the way you want it, without having to write a browser script and without having to model your documents.

Doubleplusgood. :)

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

Glassboy

  • EA Practitioner
  • ***
  • Posts: 1367
  • Karma: +112/-75
    • View Profile
Re: Document Script Fragments
« Reply #9 on: May 06, 2016, 06:44:24 am »
But these Document Script fragments actually turn out to be pretty nifty. Since the script has access to the whole of the API, including DocumentGenerator, it should now be possible to generate arbitrarily complex documents, completely independent of the package hierarchy, with everything sorted the way you want it, without having to write a browser script and without having to model your documents.

Anything would be better than having crazy filters to get documentation customization at the element level.

Pawel Zubkiewicz

  • EA User
  • **
  • Posts: 78
  • Karma: +2/-1
    • View Profile
    • zubkiewicz.com
Re: Document Script Fragments
« Reply #10 on: June 28, 2016, 07:00:39 pm »
Hi Guys,

I encountered a strange situation while developing custom template with Fragments and Document Scripts which generate RTF.

Firstly I tried to call  document fragment script from other document fragment scirpt and that failed, so I reckoned this is too much for EA. So I change the approach.

I have one document script that internally uses two different templates to produce RTF file. If I run it as a script i works great, when I run it from Project Broswser (F8) EA freezes....
When I disable in the script one template evaluation (does not matter which) report is generated properly, so only combination of both makes EA crash.

I have a feeling it might be memory problem... What I did to test it? I save the generated by script RTF as a file and then loaded it by script. Now if I sava and load at once EA crashes as well, but when in the first run of script I just save generated file and in the second run I load it from disk (without generating it) the report is generated properly and EA does not crash.

Scripts are pretty simple and amount of data is very small (saved file from script takes 93KB) so it's strange that it could be memory.. but on the other hand every part seems to work in isolation...

Could you give me some advice on how  to proceed?

This is not my first time with Document Scripts, I wrote this post on subject http://zubkiewicz.com/nonlinear-generation-of-documentation-in-sparx-enterprise-architect/ so I have some experience, but this time I'm lost.
Enhanced Requirement Attributes Addin for Enterprise Architect (ERA Addin) - http://zubkiewicz.com/?p=239

Uffe

  • EA Practitioner
  • ***
  • Posts: 1859
  • Karma: +133/-14
  • Flutes: 1; Clarinets: 1; Saxes: 5 and counting
    • View Profile
Re: Document Script Fragments
« Reply #11 on: June 28, 2016, 08:58:12 pm »
Hi Pawel,

This thread refers to document script fragments, a specific type of template fragments.
Yours is more of a general document generation problem, so please repost it in its own thread. Otherwise, things get very confusing.

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

Pawel Zubkiewicz

  • EA User
  • **
  • Posts: 78
  • Karma: +2/-1
    • View Profile
    • zubkiewicz.com
Re: Document Script Fragments
« Reply #12 on: June 28, 2016, 09:24:28 pm »
Sorry Uffe, I didn't want to "mess" your thread I will start new one :P

However, I do believe I have problem with document scripts triggered by fragments in templates... anyway I think those are bugs in EA and requested install of newest 12.1.1230 build, currently I'm using 12.1.1225. I hope this will solve my problems
Enhanced Requirement Attributes Addin for Enterprise Architect (ERA Addin) - http://zubkiewicz.com/?p=239

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13303
  • Karma: +557/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Document Script Fragments
« Reply #13 on: June 28, 2016, 09:26:17 pm »
Yes, there have been some improvements in the template area in the latest v 12.1 releases.

Geert

Pawel Zubkiewicz

  • EA User
  • **
  • Posts: 78
  • Karma: +2/-1
    • View Profile
    • zubkiewicz.com
Re: Document Script Fragments
« Reply #14 on: June 30, 2016, 05:12:27 pm »
Yes, I was right on build 1230 my code works fine, on 1225 does not.
Enhanced Requirement Attributes Addin for Enterprise Architect (ERA Addin) - http://zubkiewicz.com/?p=239