Blog Post

Generating Documents using Document Scripts in Enterprise Architect

Sparx Systems Enterprise Architect is one of the very few tools that has the capability to generate document on go from a centralized repository. Enterprise Architect has features to customize document contents using user templates, fragments, style sheets, cover pages and headers and footers.

  • Document Script in fragments is a new option which is introduced in Enterprise Architect 13.
  • Used generally for generating complex documents from Enterprise Architect.

Custom Script vs Document Script

  • Custom script (Introduced in EA 11): Script returns a value which can be used in the fragment using the ‘custom’ field.
  • Document script (Introduced in EA 13): A combination of scripts and templates. Script calls another Template and passes ID of an object to be reported

How Document Script works?

Document Script

Advantages of Document Script:

  • Flexibility in reporting desired fields in desired order
  • Loop through or mix and match details in a custom way, as per the requirements.
  • Removes need to write external addin to generate custom documents from the model.

Steps to create Document using Document Scripts:

create Document

  • From Above business process diagram, we are going to generate all the diagram objects from the parent package.
  • Initially have created a Template like below with package and element section enabledsparx AE
  • Under the Diagram Objects heading have inserted a new fragment and inside the fragment have enabled the Custom Section as belowSparx AE
  • To create a document script Fragment -> Document Options ->Custom Query -> Document Script and in the dropdown select the script which is written for document generation.

sparx EA

  • Reference the ID of the element or Package currently being processed by the document template, using the #OBJECTID# or #PACKAGEID#
  • Process Package script does the magic of rendering the objects in an order to a document.
  • Script which need be used in the Document script should always return an rtf

        var docGenerator as EA.DocumentGenerator;

        docGenerator = Repository.CreateDocumentGenerator();

        if ( docGenerator.NewDocument(“”) )

        {

            docGenerator.DocumentElement(ElementID,Heading Depth,”templateName”); // Used to add the element details in rtf

var rtf = docGenerator.GetDocumentAsRTF();

return rtf;

       }

  • For more details on attributes and methods of DocumentGenerator class please refer Sparx Help on Document Generator class
  • In document script a template should be referred so that the data will be formatted and printed based on that template.
  • For e.g. From the below package structure in Enterprise Architect

Sparx AE

  • If the documentation is generated in the package level (BP00100) and the script for rendering all the diagram objects of a diagram
  • We need to pass the packageID as the parameter in document script.
  • In the script main function rtf should be returned

function main(packageID)

{

var docGenerator as EA.DocumentGenerator;

docGenerator = Repository.CreateDocumentGenerator();

if ( docGenerator.NewDocument(“”) )

{

try

   {

var package as EA.Package;

package = Repository.GetPackageByID(packageID);

var  diagram as EA.Diagram;

diagram = package.Diagrams.GetAt(0);

var  diagramObjects as EA.Collection;

diagramObjects = diagram.DiagramObjects;

        for( var i = 0 ; i < diagramObjects.Count ; i++ )

       {

var diagramObject as EA.DiagramObject;

diagramObject = diagramObjects.GetAt( i );

var currentElement as EA.Element;

currentElement = Repository.GetElementByID(diagramObject.ElementID);

if(currentElement.Type != “Note” && currentElement.Type != “ActivityPartition” &&                                      currentElement.Type != “Pool” && currentElement.Type != “Lane”)

docGenerator.DocumentElement(currentElement.ElementID,1,ACTIVITY_TEMPLATE);

         }

   }

catch(e)

  {

Session.Output(e);

  }

var rtf = docGenerator.GetDocumentAsRTF();

return rtf;

}

return “”;

}

  • Templates inside the script can be mentioned as below

var ACTIVITY_TEMPLATE = “Activity_Report”;

Conclusion:

  • Above described is an example for generating a document using document script .You can download this entire sample model with document generation scripts and templates from http://sparxsystems.in/downloads/DocumentScriptTest.eap
  • Any complex logics can be used in the script but finally it should return an RTF. 

For more details or assistance please drop a mail to info@sparxsystems.in

 

 

10 Comments

  1. Quando tiver dúvidas sobre as atividades de seus filhos ou a segurança de seus pais, você pode hackear seus telefones Android em seu computador ou dispositivo móvel para garantir a segurança deles. Ninguém pode monitorar o tempo todo, mas há um software espião profissional que pode monitorar secretamente as atividades dos telefones Android sem alertá-los.

    Reply
  2. Your article helped me a lot, is there any more related content? Thanks!

    Reply
  3. Wow, marvelous weblog layout! How long have you
    been running a blog for? you make running a blog look easy.
    The entire glance of your site is fantastic, let alone the content material!
    You can see similar here sklep online

    Reply
  4. excellent issues altogether, you just won a brand new reader.
    What would you suggest in regards to your
    publish that you made a few days ago? Any certain? I saw similar here: Dobry sklep

    Reply
  5. Hey there! Do you know if they make any plugins to assist
    with Search Engine Optimization? I’m trying to get my blog to rank for
    some targeted keywords but I’m not seeing very good success.
    If you know of any please share. Cheers! You can read similar art here: Sklep online

    Reply
  6. Thanks for sharing. I read many of your blog posts, cool, your blog is very good.

    Reply
  7. Hey there! Do you know if they make any plugins to assist with Search Engine Optimization? I’m trying to get my site to rank for some targeted keywords but I’m not
    seeing very good results. If you know of any please share.
    Kudos! I saw similar text here: Backlink Building

    Reply
  8. Howdy! Do you know if they make any plugins to assist with Search Engine Optimization? I’m trying to get my blog to rank for some targeted
    keywords but I’m not seeing very good results.
    If you know of any please share. Thanks! I saw similar article here: GSA Verified List

    Reply
  9. Thank you for your sharing. I am worried that I lack creative ideas. It is your article that makes me full of hope. Thank you. But, I have a question, can you help me?

    Reply
  10. Wow, incredible blog format! How long have you ever been running a blog
    for? you make running a blog glance easy. The full glance
    of your website is excellent, let alone the content! You can see similar here e-commerce

    Reply

Leave a Comment

*