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 - BruceTOGAF2

Pages: [1] 2
1
// The following lines open the Word document successfully
var wdObj = new ActiveXObject("Word.Application");
wdObj.Visible = true;
var wdDoc = wdObj.Documents.Open(inputFileName);

Thank you Geert

2
Does anyone know how to use Sparx Jscript to find all headings in a Word document?

// The following lines open the Word document successfully
var wdObj = new ActiveXObject("Word.Application");
wdObj.Visible = true;
var wdDoc = wdObj.Documents.Open(inputFileName);

      
// The following line prints Bookmarks.Count correctly
Session.Output("wdDoc.Bookmarks.Count:" + wdDoc.Bookmarks.Count);

// The following line prints Sections.Count correctly
Session.Output("wdDoc.Sections.Count:" + wdDoc.Sections.Count);
      
// Following line seems to be working because it takes a while in a large document
var myHeadings = wdDoc.GetCrossReferenceItems(wdRefTypeHeading);
      
// Following line shows blank
Session.Output("myHeadings" + myHeadings);
      
// Following line errors with "Object expected"
var lheadingCount = UBound(myHeadings) - LBound(myHeadings) + 1;
      
// Following line errors with "'Count' is null or not an object"
Session.Output("myHeadings.Count:" + myHeadings.Count);
      
// Following line errors with "'length' is null or not an object"
Session.Output("myHeadings.length" + myHeadings.length);

3
// The following code succesfully opens a CSV file as a worksheet
var xlApp = new ActiveXObject( "Excel.Application");
var xlBook = xlApp.Workbooks.Open (inputFileName);
var xlSheet = xlBook.Worksheets(worksheetNo);
var wsSource = xlSheet;
wsCell = wsSource.Cells(2, 1);

How do I do the same with a Word document?

// The following code fails to open a Word Document
var wordApp = new ActiveXObject( "Word.Application");
// Above line seems to succeed
var wordDoc = wordApp.Open (inputFileName);
// Above line errors out 'Object doesn't support this property or method'


// The following code fails to open a Word Document
var wordApp = new ActiveXObject( "Word.Application");
// Above line seems to succeed
var wordDoc = wordApp.Document.Open (inputFileName);
// Above line errors out 'Document is null or not an object'

4
I have found 'Automation Scripts' as an other export option under Project, Data Management, Export Reference Data.  Both problems (RTF Templates and Automation Scripts) solved.  Thank you.

5
Sorry Geert.  I could not see the <Group Name>.  Phil has suggested another method which I have used successfully today. In EA Version 12, Reference Data Import/Export can be found in Project, Data Management, Export Reference Data. I used Export Reference Data to export my RTF Templates. Then I successfully Imported RTF Template Reference Data  into my target .EAP.   However I could not see any option to export scripts as Reference Data.

6
I am trying to import RTF template Fragments and JScripts from source.EAP file into my target.EAP file.

In source.EAP I used Tools, Generate MDG Technology File.  In the MDG Technology Wizard I
•   included my Jscripts
•   included my RTF Template Fragments
•   saved the XML file to ‘my_path’.

In my target.EAP file I used Extensions, MDG Technologies, Advanced, Add, Add Path to point to ‘my_path’ containing the above-described XML file.

I am now able to see my JScripts (from the XML file) in the Scripting Window of my target.EAP file, but I cannot see my RTF Template Fragments in the Generate Documentation, Templates window.  I tried ‘Import Reference Data’, but that did not help.

Do you have any idea why I cannot see my RTF Template Fragments in the Generate Documentation, Templates window?

7
Hi Geert,

I am trying to replicate your code in Jscript.

The following code produces a runtime error: 'TextFile' is undefined.
var mappingFile = new TextFile;

The following code produces a runtime error: ';' expected.
var mappingFile as TextFile;

Any ideas?

8
My Jscript imports a CSV file with dates into Sparx EA and stores the dates in a tagged value. The CSV file holds each date in the format “dd/mm/yyyy” e.g. "14/09/2017" = 14th September 2017.

If the day is greater than 12, then the Sparx import stores the date correctly, e.g. "28/09/2017" = 28th September 2017.

If the day is greater than 12, then the API assumes format “dd/mm/yyyy”.

If the day is 12 or less, then the Sparx import stores the date incorrectly. The API assumes the date format is “mm/dd/yyyy”

If the day is 12 or less, then the Excel.Application API converts the first 2 numbers to the month e.g. "11/09/2017" = 9th November 2017 (should be 11th September 2017).

Here is some sample code to demonstrate the process.

// Open CSV file as a worksheet
var xlApp = new ActiveXObject( "Excel.Application");
var xlBook = xlApp.Workbooks.Open (inputFileName);
var xlSheet = xlBook.Worksheets(worksheetNo);
var wsSource = xlSheet   

var my11thDateCell = wsSource.Cells(11, 8);  // CSV Sample "11/09/2017"
var my12thDateCell = wsSource.Cells(12, 8); // CSV Sample "12/10/2017"
var my13thDateCell = wsSource.Cells(13, 8); // CSV Sample "13/09/2017"
var my14thDateCell = wsSource.Cells(14, 8); // CSV Sample "14/09/2017"

// A snippet from the tagged value update function which receives parameter last_Modified_Date
if (foundTag.Name == "08-Last_Modified_On") {
foundTag.Value = last_Modified_Date;
   myPTag7Found = true;
   foundTag.Update();

I have tried string conversions and parsing, but the problem still persists. Is there a more fundamental way of configuring the Sparx API to read the CSV dates as format “dd/mm/yyyy” ?

9
Automation Interface, Add-Ins and Tools / Re: currentPkg.Elements.Count
« on: November 09, 2017, 10:06:10 pm »
As usual Geert, your inspiration has helped me fix the problem.  The following function works well.

/*-------------------------------------------------------------
' Author:   Bruce Singleton
' Fixer: Geert Bellekens
' Date:     09/11/2017
         var theToPackage As EA.Package;
         theToPackage = taggedValueGetPkg("01-Absolute_Number", Absolute_Number, "heading");
'------------------------------------------------------------- */
function taggedValueGetPkg(property, value, versionVal)  {
   var soughtPkg as EA.Package;
   sql = "select obj.Object_ID AS OBJ_ID from t_objectproperties prop, t_object obj ";   
   sql = sql + "WHERE prop.Object_ID=obj.Object_ID ";
   sql = sql + "AND obj.Object_Type='Package' ";
   sql = sql + "AND prop.Property='" + property + "' ";
   sql = sql + "AND prop.Value='" + value + "'";
   s = Repository.SQLQuery(sql);

   var myIDs = xmlColumn( s, "OBJ_ID");
   for ( var i = 0 ; i < myIDs.length; i++ ) {
      var currentElement as EA.Element;
      currentElement = Repository.GetElementByID(myIDs);
      if (currentElement) {
         if (currentElement.Version == versionVal) {
            var soughtElement as EA.Element;
            soughtElement = currentElement;
            var soughtGUID = soughtElement.ElementGUID;
            soughtPkg = Repository.GetPackageByGUID(soughtGUID);
            return soughtPkg;
         }
      }
   }

   return soughtPkg;
}

Thank you.

10
Automation Interface, Add-Ins and Tools / Re: currentPkg.Elements.Count
« on: November 09, 2017, 09:47:42 pm »
Geert,

My initial post (currentPkg.Elements.Count) failed to explain the problem ‘currentPkg.Elements.Count’ properly.

I have a main Jscript that finds packages and processes the elements contained in each package.  My main Jscript finds the package using function taggedValueGetPkg() illustrated below.

Function taggedValueGetPkg looks for a particular tagged value ("01-Absolute_Number") and identifies the element containing the search Value in "01-Absolute_Number".

My main Jscript then tests the package contents, using currentPkg.Elements.Count, but reports 0 elements.

The problem is due to function taggedValueGetPkg which declares “var soughtElement as EA.Element”.

My main Jscript is finding each package as follows:

var paragPkg as EA.Package;
paragPkg = taggedValueGetPkg("01-Absolute_Number", Absolute_Number, "paragraph");

I know that function taggedValueGetPkg() works quite well because my main Jscript can test paragPkg.Name successfully.

Function taggedValueGetPkg() works quite well but it returns an Element object NOT a Package object.

SQL query 'select obj.Package_ID AS PKG_ID' will not work because that returns the package containing the package I am seeking.

How do I get function taggedValueGetPkg() to return the Package object associated with soughtElement?


/*-------------------------------------------------------------
' Author:   Bruce Singleton
' Date:     08/11/2017
'------------------------------------------------------------- */
function taggedValueGetPkg(property, value, versionVal)  {
   var soughtElement as EA.Element;
   // sql = "select obj.Package_ID AS PKG_ID from t_objectproperties prop, t_object obj ";
   sql = "select obj.Object_ID AS OBJ_ID from t_objectproperties prop, t_object obj ";   
   sql = sql + "WHERE prop.Object_ID=obj.Object_ID ";
   sql = sql + "AND obj.Object_Type='Package' ";
   sql = sql + "AND prop.Property='" + property + "' ";
   sql = sql + "AND prop.Value='" + value + "'";
   s = Repository.SQLQuery(sql);

   var myIDs = xmlColumn( s, "OBJ_ID");
   for ( var i = 0 ; i < myIDs.length; i++ ) {
      var currentElement as EA.Element;
      currentElement = Repository.GetElementByID(myIDs);
      if (currentElement) {
         // Session.Output("taggedValueGetPkg '" + currentElement.Name + "' " + currentElement.Version)
         if (currentElement.Version == versionVal) {
            soughtElement = currentElement;
            return soughtElement
         }
      }
   }

   return soughtElement;
}

11
Automation Interface, Add-Ins and Tools / currentPkg.Elements.Count
« on: November 09, 2017, 08:42:23 pm »
I have a package ‘Element Counter Test’ containing  5 elements. The following Jscript functions perfectly. It reports 5 (currentPkg.Elements.Count) elements

However I have another enormous Jscript that finds packages and processes the elements contained in each package.  It tests the package contents, using the same code as that shown below (currentPkg.Elements.Count), but reports 0 elements.

Any idea?

/* ========================================================================================
' Script Name: js_Element_Counter_Test
' Author: Bruce Singleton
' Purpose: Count elements in selected package
' Date: 07/11/2017
' ========================================================================================*/

 
function main()
{
       
       // Get the currently selected package in the Project Browser
       var currentPkg as EA.Package;
       currentPkg = Repository.GetTreeSelectedPackage();

       if (currentPkg)
       {
              Session.Output("Found package '" + currentPkg.Name + "' with " + currentPkg.Elements.Count + " elements");
       }
       else
       {
              Session.Output( "Package NOT selected.");
       }
       
}

12
Thank you to Dermot (Sparx Systems Support) for providing the specific solution to problem with ‘docGenerator & Diagrams with frame & diagram name in top left corner’.  I did the following:
- Opened the Generate Documentation dialog
- Unchecked the option "Hide Diagram Borders". 

The following Sparx Jscript code prints a diagram into docGenerator.NewDocument:
docGenerator.DocumentDiagram( currentDiagram.DiagramID, 0, "my_diagram_rtf_fragment");
The borders do now do appear in my RTF report. Excellent result!

13
I have copied paragraphs from a large MS-Word document and pasted them into Artifact Document Linked Documents. Each Artifact Document element contains one or more paragraphs. Each Artifact Document element is contained in a package. In the Sparx project browser, there are also Sparx diagrams nestling between the Artifact Document elements.
My automation script prints the selected package as an RTF document. My Jscript includes recursive function recursiveDocGen that drills through the package hierarchy and prints paragraphs and diagrams e.g.
•   docGenerator.InsertLinkedDocument(currentElement.ElementGUID);
•   docGenerator.DocumentDiagram( currentDiagram.DiagramID, 0, "my_diagram_rtf_fragment");


"my_diagram_rtf_fragment" generates a caption by including fields Diagram.Figure and Diagram.Name that were inserted from the Sparx RTF template editor.

The original MS-Word document includes the section number in the diagram caption e.g. Figure 5-1: Solution Strategy

The customer wants to see the same Figure numbering (section number prefix) in the caption beneath each diagram in the Sparx-generated document.

I have tried copying the MS-Word style reference codes from the caption of the MS-Word document into "my_diagram_rtf_fragment", but docGenerator prints the style reference code as a literal when printing the diagram caption. The printed document contains the printed literal 'STYLEREF' e.g. STYLEREF 1 \s- Figure  «STYLEREF» 1:Component Diagram Example.

The old trick of copying MS-Word style reference codes into an RTF Fragment works well for some MS-Word style reference codes but not for these codes.

I almost have a way round it.

My function recursiveDocGen can track & calculate which document section number is being generated. How can I insert a custom field (section number) into "my_diagram_rtf_fragment" as a prefix to Diagram.Figure?

14
The following Sparx Jscript code prints a diagram into docGenerator.NewDocument.
generationSuccess = docGenerator.DocumentDiagram( currentDiagram.DiagramID, 0, "my_diagram_rtf_fragment");
In the saved RTF document there is no frame around the diagram and the name of the diagram is not in the top left corner.

If I save a Sparx diagram as an image then insert it into a Word document, then there is a frame around the diagram and the name of the diagram is in the top left corner.   If I copy a Sparx diagram to the clipboard then paste it into a Word document, then there is a frame around the diagram and the name of the diagram in the top left corner.

The Sparx automation interface does not produce a frame or name in the corner.  Is there a way to configure "my_diagram_rtf_fragment" so that there is a frame around the diagram and the name of the diagram in the top left corner?

15
I do not know about Word API.  I typed 'Word API' into the Sparx Enterprise Architect User Guide and got zero search results.  Please can you pint to me a useful resource about Word API.

Pages: [1] 2