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.


Topics - BruceTOGAF2

Pages: [1]
1
I am using docGenerator.DocumentDiagram( currentDiagram.DiagramID, 0, myRtfTemplateFragment) to "print" large diagrams in an RTF document.
After the RTF document has been built, I have to resize each diagram to fit neatly into an A4 page.

How can I force docGenerator to "print" those diagrams within the bounds of an A4 page?

In Tools, Options, Diagrams, Default Page Size is 'A4 Sheet, 210- by 297-millimeters'
In Tools, Options, Diagrams, Diagram Frames, there is a check box 'On printed Images'
In Tools, Options, Diagrams, General, there is a check Box 'Zoom to best scale'
In Tools, Options, Diagrams, I cannot find a check Box for 'Zoom to best scale' On printed Images

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

5
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” ?

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

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

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

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


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

11
Automation Interface, Add-Ins and Tools / method LoadLinkedDocument
« on: August 25, 2017, 01:33:11 am »
Pawel Zubkiewicz's post about linked documents is 120 days old, so I figured I had better start a new post. 
Geert Bellekens has answered Pawel's query, but I am stll failing to understand how to use a VBScript method LoadLinkedDocument
to create a linked document attached to a package.

My package has already been declared and created.

dim myDoc
myDoc = myPackage.LoadLinkedDocument("d:\Profiles\bsingleton\AppData\Local\Temp\82600.tmp")

The above code errors "Object doesn't support this property."

Where am I going wrong?  What is the correct syntax?

12
I have discovered that ‘Run-time error '-2147417851 (80010105)’’ is a known bug when using Excel+VBA to import Excel spreadsheets into Sparx .   So, I am taking a new approach to importing spreadsheets into Sparx.  Instead of using Excel+VBA to PUSH data into Sparx, I am trying to use a Sparx Jscript to PULL data into Sparx.

Most of my Sparx code is in Sparx EA JScript (not VBScript). I am looking for the Sparx EA JScript equivalent of Sparx VBScript CreateObject( "Excel.Application"). 

Here is a Sparx EA VBScript that provides a user dialogue that successfully opens an Excel spreadsheet and gets ready to read the cells from xlSheet
===============================================================================
filterString = "All Files |*.*|Excel *.xlsx|*.xlsx|Excel *.xls|*.xls|"
filterIndex = 0
flags = 0
WorksheetNo = 1

inputFileName = InvokeFileDialog(filterString, filterIndex, flags)
LOGInfo("Using the Excel Spreadsheet: " & inputFileName)
Set xlApp = CreateObject( "Excel.Application")
Set xlBook = xlApp.Workbooks.Open (inputFileName)
Set xlSheet = xlBook.Worksheets(worksheetNo)
================================================================================

Here is a Sparx EA JScript that provides a user dialogue that successfully identifies the Excel spreadsheet filename but CreateObject( "Excel.Application") produces error "Object expected"
================================================================================
   
var inputFileName = InvokeFileDialog(filterString, filterIndex, flags, InitialDirectory, OpenorSave)

Session.Output(" Importing from file: " + inputFileName);

// The following code produces error "Object expected"
var xlApp = CreateObject( "Excel.Application");

13
Suggestions and Requests / GetLinkedDocument from a package
« on: April 11, 2017, 08:43:00 pm »
I would really like to see the macro built by Ronaldo Juliattio (posted October 30, 2008).

Ronaldo's macro makes use of GetLinkedDocument() method, and checks the size of the returned string, for all the elements in a traversed tree. Sounds great.  I am still a GetLinkedDocument beginner.  GetLinkedDocument() works with elements, but not with packages.

In my Jscript I cannot get GetLinkedDocument() method to retrieve a LinkedDocument from a package. 

How can I get GetLinkedDocument() from a package?

Pages: [1]