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] 3
16
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” ?

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

18
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;
}

19
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.");
       }
       
}

20
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!

21
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?

22
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?

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

24
I already posted 'Method LoadLinkedDocument' which shows how I paste the content of a spreadsheet cell into a Linked Document. 

This post is to enquire about Jscript getting the contents of the Windows Clipboard. 

I would like to manually highlight some text in a MS-Word document and copy (Ctrl-C) the highlighted text into the Windows Clipboard, then run a Sparx Jscript that
  • copies the content of the Windows Clipboard into a string var called Clipboard_Text
  • creates a docGenerator document i.e. docGenerator.NewDocument("");
  • pastes the string Clipboard_Text into the docGenerator document  i.e. docGenerator.InsertText(Clipboard_Text, "Normal");
  • saves the docGenerator document as an RTF file  i.e. docGenerator.SaveDocument( "myTempDocument.rtf", dtRTF);
  • Creates new artefact document i.e. artifElement = myElements.AddNew( artifName, "Artifact"); artifElement.Stereotype = "Document";
  • Attaches the linked document to Artifact element i.e. var myDoc = artifElement.LoadLinkedDocument("myTempDocument.rtf");

Can a Sparx Jscript get access to the content of the Windows Clipboard?


25
Automation Interface, Add-Ins and Tools / Re: method LoadLinkedDocument
« on: October 25, 2017, 01:35:55 am »
Success!  I needed to update the content of the LinkedDocument. I found a solution with Geert's inspiration.  I followed Geert's idea ("create a temporary file with the contents ....". See function storeArtiFile) then use LoadLinkedDocument. The following code works well.

var tempFileName = storeArtiFile(Absolute_Number, Object_Text);
// Attach linked document to Artifact element
var myDoc
myDoc = artifElement.LoadLinkedDocument(tempFileName);

function storeArtiFile(Absolute_Number, Object_Text)
{
   var tempFileName = "c:\Reports\\" + Absolute_Number + ".rtf";
   // Create a document generator object
   var docGenerator as EA.DocumentGenerator;
   docGenerator = Repository.CreateDocumentGenerator;
            
   // Create a new document
   if (docGenerator.NewDocument("")) {
      var generationSuccess;
      generationSuccess = false;
      generationSuccess = docGenerator.InsertText(Object_Text, "Normal");
               
      var saveSuccess;
      saveSuccess = false;
      saveSuccess = docGenerator.SaveDocument( tempFileName, DOCUMENTATION_TYPE );
   }
   if (saveSuccess) {
      return tempFileName;
   }
   else {
      return "";
   }
}

26
Problem solved!!!

Tools/Options/Links
I unchecked the checkbox 'strict connector syntax'

My Jscript function connectSupplierClient() now works well when building a "UseCase" connector between an Actor and a UseCase

Thank you Geert and qwerty.

27
According to 'Manage Add-Ins', I only have 2 Available Add-Ins. They are enabled and set to Load on Startup:
Visual Studio
Eclipse

How do I turn off this restriction? 
Do I use 'EA_OnPreNewConnector()' at the top of my Jscripts?
What is the syntax?

28
Even though I can build this connector manually, why is my Jscript being prevented from building a "UseCase" connector between an Actor client and a UseCase?

My Jscript function connectSupplierClient() has 3 input parameters
•   mySupplier
•   myClient
•   connectorType

function connectSupplierClient() works well for a range of elements types and connector types, but refuses to work with
•   an Actor element
•   a UseCase element
•   connector type "UseCase"

I have tried passing the
•   Actor element as mySupplier
•   UseCase element as myClient

I have tried passing the
•   UseCase element as mySupplier
•   Actor element as myClient

In both cases, I get runtime error message "UseCase is not legal for Actor --> UseCase"

There is nothing to stop me building the above model using the toolbox, but I cannot build the above model with Jscript. Any idea why?

29
Hi Geert, When using the EA.DocumentGenerator class to save an RTF file containing a string, what determines the default font in the RTF file? How can I make the default font Calibri 12? Does this point to an RTF Fragment, RTF Template of RTF Style?

Please explain ‘Normal’  in docGenerator.InsertText(Object_Text, "Normal"); I have tried creating my own RTF fragment ‘Calb_12’ containing codes for Font Calibri 12, but this is not being used by  docGenerator.InsertText(Object_Text, "Calib_12");.

Please explain the "" parameter in  docGenerator.NewDocument(""). Is this an opportunity to define an RTF Template?

30
Automation Interface, Add-Ins and Tools / Re: method LoadLinkedDocument
« on: August 25, 2017, 06:04:29 pm »
I am delighted that Aaron has replied instantly with a workable syntax for LoadLinkedDocument.  The following VBScript code works a treat.

dim myDoc
myDoc = repPackage.Element.LoadLinkedDocument("c:\Reports\Object_Text.docx")

I am trying to fill the Linked Document with text from an imported spreadsheet row. The following code creates var Object_Text
dim Object_Text
Set wsCell = wsSource.Cells(RowNumber, 11)
Object_Text = wsCell.Value

GetLinkedDocument() returns the content of the LinkedDocument. I need to do the opposite. I need to update the content of the LinkedDocument.

My next task is to follow Geert's idea ("create a temporary file with the contents ....") then use LoadLinkedDocument

How do I create the temporary file "c:\Reports\Object_Text.docx" with the contents of Object_Text?

Pages: 1 [2] 3