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

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?

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.

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?

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

Problem solved!!!

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.

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

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

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?

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?

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?

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?

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");

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 [2]