Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - skrauss

Pages: [1]
1
General Board / Re: Swimlanes
« on: September 01, 2011, 12:54:27 am »
I have created a script to create automatically some swimlanes on a diagram. But you have to open the swimlines dialog to reflect the changes.

option explicit

!INC Local Scripts.EAConstants-VBScript

'
' This code has been included from the default Diagram Script template.
' If you wish to modify this template, it is located in the Config\Script Templates
' directory of your EA install path.
'
' Script Name: Create swimlanes for Model Driven RE
' Author:      Sven Stefan Krauss
'                  Curtiss-Wright Antriebstechnik GmbH
' Purpose:     Creat swimlines on a diagram
' Date:        01.07.2011
'
' Current issue:
' You have to open the swimlines dialog to show the results.
' Any ideas?
'
' Diagram Script main function
'
sub OnDiagramScript()

      ' Get a reference to the current diagram
      dim currentDiagram as EA.Diagram
      set currentDiagram = Repository.GetCurrentDiagram()

      if not currentDiagram is nothing then
            ' Get a reference to any selected connector/objects
            dim selectedConnector as EA.Connector
            dim selectedObjects as EA.Collection
            set selectedConnector = currentDiagram.SelectedConnector
            set selectedObjects = currentDiagram.SelectedObjects

            Repository.EnsureOutputVisible("Script")
            Repository.ClearOutput("Script")
            Session.Output currentDiagram.Name
            Session.Output "Creating Swimlane: Customer Requirements..."
            currentDiagram.SwimlaneDef.Swimlanes.Add "Customer Requirements",200
            Session.Output "Creating Swimlane: Components..."
            currentDiagram.SwimlaneDef.Swimlanes.Add "Components",100
            Session.Output "Creating Swimlane: Design Concept..."
            currentDiagram.SwimlaneDef.Swimlanes.Add "Design Concept",100
            Session.Output "Creating Swimlane: Verfication..."
            currentDiagram.SwimlaneDef.Swimlanes.Add "Verfication",100
            Session.Output "Creating Swimlane: Child Requirements..."
            currentDiagram.SwimlaneDef.Swimlanes.Add "Child Requirements",100
            currentDiagram.Update()

            if not selectedConnector is nothing then
                  ' A connector is selected
            elseif not selectedObjects.Count > 0 then
                  ' One or more diagram objects are selected
            else

                  ' Nothing is selected
                  
            end if
      else
            Session.Prompt "This script requires a diagram to be visible", promptOK
      end if

end sub

OnDiagramScript

2
I would recommend to use the Generator Class.

Here an idea for implementation:
1. Create a Document Generator object
2. Add the text needed with gendoc.AddText "<Text>", "<Style>"
3.  Save the document temporarly as RTF with gendoc.SaveDocument rtf_filename, 0 ' 0 = RTF, 1=HTML
4. Import the generated document with element.LoadLinkedDocument

Dim gendoc as EA.DocumentGenerator
Set gendoc = Repository.CreateDocumentGenerator()
gendoc.NewDocument("<your Template name here>")
gendoc.AddText("<Add your text, whereever it comes from>" & vbCrLf, "Heading 1")
...
gendoc.SaveDocument "C:\tmp\tmp.rtf", 0 ' 0 = RTF, 1=HTML
element.LoadLinkedDocument("C:\tmp\tmp.rtf")


If you create a template with the needed formattig, you can specify it with InsertText. For example if you add "Strong" the text will be bold in the standard template.

Sven

3
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"

4
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.

5
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.

6
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

7
Thank you Geert for your answer.

The project interface would be a good place for the API.
I will create a feature request.

8
Is there a way to create entries in Team Review via EA Script or Addin?

Pages: [1]