Book a Demo

Author Topic: Setting Project Constants via Script / Addin  (Read 7704 times)

skrauss

  • EA Novice
  • *
  • Posts: 8
  • Karma: +0/-0
    • View Profile
Setting Project Constants via Script / Addin
« on: September 01, 2011, 12:47:20 am »
Is there a way to set automatically project constants for the document generator via EA script or addin?

My problem is a follows:

In a project I have several packages which reflects documents (for example SRS, SDD, etc)

Each document has its own number and release number but it shall use the same template, so it should be updated before generating.

For eaxample, I have 10 SRS for 10 projects which share the same SRS template. I have a lot of projects in a server based repository, so defining a project constant for each document is not possible.

SRS = SW Requirements Specification
SDD = SW Design Description

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Setting Project Constants via Script / Addin
« Reply #1 on: September 06, 2011, 04:43:53 pm »
I'm sorry, I really don't understand your requirement.
What exactly are you trying to achieve?

Geert

skrauss

  • EA Novice
  • *
  • Posts: 8
  • Karma: +0/-0
    • View Profile
Re: Setting Project Constants via Script / Addin
« Reply #2 on: September 06, 2011, 04:49:12 pm »
Thank you Geert for your answer.

I want to put the document number and release on top of each page.

I have defined project constants like document_number and document_release, but I have to change them manually for each document before document generating.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Setting Project Constants via Script / Addin
« Reply #3 on: September 06, 2011, 05:38:20 pm »
I don't really see it in the api documentation, so you might have to figure out where in the database it is stored and update it there.

Geert

skrauss

  • EA Novice
  • *
  • Posts: 8
  • Karma: +0/-0
    • View Profile
Re: Setting Project Constants via Script / Addin
« Reply #4 on: September 06, 2011, 09:33:43 pm »
For anybody who wants to know where this information is stored in the database:
It is in table "t_rtf" where dataset field Type is "ProjectOpts" and
field "Template" contains project constants in Format CONSTANT_1=VALUE_1;

Don't like to update the database directly.
Perhaps a filename constant could be a workaround.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Setting Project Constants via Script / Addin
« Reply #5 on: September 06, 2011, 09:45:52 pm »
I can understand your reluctance to edit the database directly, but after a while I'm afraid you're going to give up. :(
There's just too much that is not properly exposed in the API...

As a consolation, if you use the undocumented operation Repository.Execute(SQLUpdateString) then you don't have to mess around with your own database connections and stuff like that.

Geert

skrauss

  • EA Novice
  • *
  • Posts: 8
  • Karma: +0/-0
    • View Profile
Re: Setting Project Constants via Script / Addin
« Reply #6 on: September 06, 2011, 11:39:58 pm »
okay, I managed to do it!

Here's the script variant:
CWAT_SRS is my template name
IDENTNR is project constant name for identification number, which is placed as project constant on each page header.

...
' Code for when a package is selected
dim thePackage as EA.Package
set thePackage = Repository.GetTreeSelectedPackage()

Dim prj as EA.Project
set prj = Repository.GetProjectInterface()
Dim sql
sql = "UPDATE t_rtf SET Template='IDENTNR=" & thePackage.Name & ";' WHERE Type='ProjectOpts'"
Repository.Execute sql

prj.RunReport thePackage.PackageGUID, "CWAT_SRS", "X:\" & thePackage.Name & ".rtf"

Stefan Bolleininger

  • EA User
  • **
  • Posts: 308
  • Karma: +0/-0
    • View Profile
Re: Setting Project Constants via Script / Addin
« Reply #7 on: September 07, 2011, 03:54:21 pm »
That's a nice thing.

Does it change the Constant as permanent?

Little ideas for that:
Let your script search and use the latest baseline for your package.
This may help you to handle correct revision and changedates.

Edit: Some ideas for SQl without any test of funcion:

Dim Variable As Mysql_query = "SELECT Version
FROM `t_document`
WHERE `DocType` = 'Baseline'
AND DocName LIKE 'thepackage.Name'
ORDER BY `t_document`.`DocDate` DESC
LIMIT 0 , 1 "

Maybe you two could correct it and integrate it to your script? It would be much nicer to get the revision-Number into your documents footer.

 BTW: How do you make sure not to overwrite other project constants?
« Last Edit: September 07, 2011, 06:00:54 pm by sethordefaye »
Enterprise Architect in "safetycritical development" like medical device industry. My free Add-in at my Website

clicht

  • EA Novice
  • *
  • Posts: 12
  • Karma: +0/-0
    • View Profile
Re: Setting Project Constants via Script / Addin
« Reply #8 on: September 08, 2011, 12:15:40 am »
Is it possible to use the Package.Version or a Package.TaggedValue at the selected Package therefore?
It is only an idea. I have no experience with RTF documentation.

Stefan Bolleininger

  • EA User
  • **
  • Posts: 308
  • Karma: +0/-0
    • View Profile
Re: Setting Project Constants via Script / Addin
« Reply #9 on: September 08, 2011, 12:49:30 am »
Very good idea.

But to spin this around i got this:

Dim statement1
Dim statement2

statement1 = Repository.SQLQuery("select Template from t_rtf where Type='ProjectOpts'")
statement2 = statement1 & "Requirement_Specification_Filename=" & thePackage.Version & ";"
Session.Output( "Statement2: " & statement2 )
' Repository.Execute ("UPDATE t_rtf SET Template='" & statement2 & "' WHERE Type='ProjectOpts'")

' prj.RunReport thePackage.PackageGUID, "Requirement_Specification", "Z:\" & thePackage.Name & ".rtf"


My output is as expected:

Statement2: <?xml version="1.0"?>
      
<EADATA version="1.0" exporter="Enterprise Architect">
      
      <Dataset_0><Data><Row><Template>000_item=000_Sperritem;Projectmanager=Someone;Projectname=Project0815;Projectnr=0815;Requirement_Specification_Filename=0815_Requirements_Specification_AE12;</Template></Row></Data></Dataset_0></EADATA>
Requirement_Specification_Filename=AE09;      

That is what i expected, but i want to get rid of the xml tags to write it back to the t_rtf

How can i do that?
Enterprise Architect in "safetycritical development" like medical device industry. My free Add-in at my Website

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Setting Project Constants via Script / Addin
« Reply #10 on: September 12, 2011, 05:35:06 pm »
So you are trying to parse and xml string hé :o
Maybe, just maybe you are not the first to try need this, and maybe, just maybe there's already some feature in your programming language libraries that takes care of all that fancy xml stuff.... 8-)

Geert