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 - Jan van Duuren

Pages: [1]
1
General Board / Re: OpenAPI support in EA
« on: May 02, 2024, 11:54:43 pm »
At the global automotive company I am currently working for, we have developed an add-in that imports OpenAPI yaml files, to create interfaces, methods and data objects.
It has been developed by Helmut Ortmann (Technowelle). As it is intellectual property of the company, we cannot simply share it.

https://sparxsystems.com/forums/smf/index.php?action=profile;u=138263

2
Herewith the JScript MsgBox and InputBox example for EA 16 64bit


!INC Local Scripts.EAConstants-JScript

/*
 * Script Name: JScript MsgBox (EA 16 x64)
 * Author     : Jan van Duuren
 * Purpose    : Test MsgBox and InputBox with JScript in EA 16 64bit
 * Date       : 02.05.204
 */
 
// global vars
var fso = new ActiveXObject("Scripting.FileSystemObject");
var WSH = new ActiveXObject("WScript.Shell");

function main()
{
   var result = InputBox("Please enter here", "MyInput", "default_text");
   MsgBox(result, "MyTitle", 64);
   
}

main();

function MsgBox(prompt, title, style) {
   if (prompt == null) prompt = "";
   if (title == null) title = "MsgBox";
   if (style == null) style = 0;
      
   style += 4096; // to make the popup active (foreground)
   return WSH.Popup(prompt, 0, title, style);
}

function InputBox(prompt, title, defaultText) {
   if (prompt == null) prompt = "Input";
   if (title == null) title = "InputBox";
   if (defaultText == null) defaultText = "";
   
   var vbsScriptFile = WSH.ExpandEnvironmentStrings("%TEMP%\\ea_inputbox.vbs");
   var tmpInputFile  = WSH.ExpandEnvironmentStrings("%TEMP%\\ea_input.tmp");

   if (!fso.FileExists(vbsScriptFile)) {
      CreateInputboxVBS(vbsScriptFile);
   }

   var cmd = 'WScript "' + vbsScriptFile + '" "' + tmpInputFile + '" "' + prompt + '" "' + title + '" "' + defaultText + '"';
   Session.Output(cmd);
   WSH.Run(cmd, 1, true);
   var ForReading = 1;
   var file = fso.OpenTextFile(tmpInputFile, ForReading);
   if (!file.AtEndOfStream) {
      return file.ReadAll();
   }
}

function CreateInputboxVBS(vbsScriptFile) {
   // function to create the inputbox VBS sripts in folder
   var vbsScriptContent = "dim tmpInputFile, prompt, title, defaultText, input\r\n\
      Set objArgs = WScript.Arguments\r\n\
      If objArgs.Count = 4 Then\r\n\
         tmpInputFile = objArgs(0)\r\n\
         prompt       = objArgs(1)\r\n\
         title        = objArgs(2)\r\n\
         defaultText  = objArgs(3)\r\n\
         input        = InputBox(prompt, title, defaultText)\r\n\
      End if\r\n\
      \r\n\
      Const ForWriting = 2, CreateIfNeeded = true\r\n\
      set fso = CreateObject(\"Scripting.FileSystemObject\")\r\n\
      set file = fso.OpenTextFile(tmpInputFile, ForWriting, CreateIfNeeded)\r\n\
      file.write input\r\n\
      file.close".replace(/\t\t/g, '');
   
   var overwrite=true, unicode=true;
   var file = fso.CreateTextFile(vbsScriptFile, overwrite, unicode);
   file.Write(vbsScriptContent);
   file.Close();
}

3
We have solved this problem with scripting, by reopening the generated (word/rtf) document with Word in the background (ActiveXObject or COMObject). Then we update whatever we want in the document, such as heading levels, insert footers, update the Table of Content etc. It gives you full control over the formatting of the generated document.
Basically all our document generation is done by scripts with the "CreateDocumentGenerator()" API.
It works also with EA 16 without any problems.

I could create an example script, if you are intersted.

4
Yes, I did use it for retrieving some documentation from multiple PDFs.
I grabed all PFD files, itterate through each PDF file, searched for some fixed text (tags) and then inserted them as new elements in EA.
So it is doable and repeatable.

5
You could create a script for that. Generating a document by script provides a huge flexibility.
Below I provided a small script, which documents a single element by (ElementID).
It uses a template with name "Test_Element". So you need to create a template under "Resources -> Document Publishing -> Custom Templates".
In the template you can select for example section "Element", "Attribute" and "Method".

Code: [Select]
!INC Local Scripts.EAConstants-JScript

/*
 * Script Name:
 * Author:
 * Purpose:
 * Date:
 */
 
function main()
{
docGenerator = Repository.CreateDocumentGenerator();
if (docGenerator.NewDocument("")) {
docGenerator.DocumentElement(188685, 0, "Test_Element");
docGenerator.SaveDocument("C:\\Temp\\Test_Element.docx", dtDOCX);
}
}

main();

6
You could use NODEJS with a PDF text Reader package (npm) to open your EA repository and PDF-Files to create elements.
such script will not run inside EA, but on Windows itself.

Steps you would need are:
  • download and install nodejs engine from Internet
  • installl npm package 'winax' to use ActiveXObjects (COMObjects)
  • install npm package 'pdf-text-reader'
  • create a js script in which you:
    • open your EA repository as ActiveXObject
    • retrieve required info from PDF file
    • create EA elements retrieved from PDF
    • close EA repository


7
Bugs and Issues / Re: EA16 JavaScript DLGInputBox bug
« on: December 22, 2023, 10:37:37 pm »
herewith a working script

Code: [Select]
!INC Local Scripts.EAConstants-JScript

/*
 * Script Name:
 * Author:
 * Purpose:
 * Date:
 */
 
function main()
{
var testVal = InputBox("enter your input here", "My InputBox");
MsgBox(testVal);
}

main();

function MsgBox(prompt="", title="MsgBox", style=0) {
style += 4096; // to make the popup active (foreground)
var WSH = new COMObject("WScript.Shell");
return WSH.Popup(prompt, 0, title, style);
}

function InputBox(prompt="Input", title="Inputbox", defaultText="") {
const fso = new COMObject("Scripting.FileSystemObject");
const WSH = new COMObject("WScript.Shell");
const vbsScriptFile = WSH.ExpandEnvironmentStrings("%TEMP%\\ea_inputbox.vbs");
const tmpInputFile  = WSH.ExpandEnvironmentStrings("%TEMP%\\ea_input.tmp");

if (!fso.FileExists(vbsScriptFile)) {
CreateInputboxVBS(vbsScriptFile);
}

WSH.Run(`WScript "${vbsScriptFile}" "${tmpInputFile}" "${prompt}" "${title}" "${defaultText}"`, 1, true);
const ForReading = 1;
const file = fso.OpenTextFile(tmpInputFile, ForReading);
if (!file.AtEndOfStream) {
return file.ReadAll();
}
return "";
}

function CreateInputboxVBS(vbsScriptFile) {
// function to create the inputbox VBS sripts in folder
const fso = new COMObject("Scripting.FileSystemObject");
const vbsScriptContent = `dim tmpInputFile, prompt, title, defaultText, input
Set objArgs = WScript.Arguments
If objArgs.Count = 4 Then
tmpInputFile = objArgs(0)
prompt       = objArgs(1)
title        = objArgs(2)
defaultText  = objArgs(3)
input        = InputBox(prompt, title, defaultText)
End if

Const ForWriting = 2, CreateIfNeeded = true
set fso = CreateObject("Scripting.FileSystemObject")
set file = fso.OpenTextFile(tmpInputFile, ForWriting, CreateIfNeeded)
file.write input
file.close`.replace(/\t\t/g, '');

const overwrite=true, unicode=true;
const file = fso.CreateTextFile(vbsScriptFile, overwrite, unicode);
file.Write(vbsScriptContent);
file.Close();
}

8
Bugs and Issues / Re: EA16 JavaScript DLGInputBox bug
« on: December 22, 2023, 09:36:15 pm »
yes, I have a global variable for fso.
You just can add the following line to function "CreateInputboxVBS(vbsScriptFile)"

 const fso = new COMObject("Scripting.FileSystemObject");

Code: [Select]
function InputBox(prompt="Input", title="Inputbox", defaultText="") {
   const fso = new COMObject("Scripting.FileSystemObject");
   const WSH = new COMObject("WScript.Shell");
   const vbsScriptFile = WSH.ExpandEnvironmentStrings("%TEMP%\\ea_inputbox.vbs");
   const tmpInputFile  = WSH.ExpandEnvironmentStrings("%TEMP%\\ea_input.tmp");
   
   if (!fso.FileExists(vbsScriptFile)) {
      CreateInputboxVBS(vbsScriptFile);
   }
   
   WSH.Run(`WScript "${vbsScriptFile}" "${tmpInputFile}" "${prompt}" "${title}" "${defaultText}"`, 1, true);
   const ForReading = 1;
   const file = fso.OpenTextFile(tmpInputFile, ForReading);
   if (!file.AtEndOfStream) {
      return file.ReadAll();
   }
}

function CreateInputboxVBS(vbsScriptFile) {
   // function to create the inputbox VBS sripts in folder
   const fso = new COMObject("Scripting.FileSystemObject");
   const vbsScriptContent = `dim tmpInputFile, prompt, title, defaultText, input
      Set objArgs = WScript.Arguments
      If objArgs.Count = 4 Then
         tmpInputFile = objArgs(0)
         prompt       = objArgs(1)
         title        = objArgs(2)
         defaultText  = objArgs(3)
         input        = InputBox(prompt, title, defaultText)
      End if
         
      Const ForWriting = 2, CreateIfNeeded = true
      set fso = CreateObject("Scripting.FileSystemObject")
      set file = fso.OpenTextFile(tmpInputFile, ForWriting, CreateIfNeeded)
      file.write input
      file.close`.replace(/\t\t/g, '');
   
   const overwrite=true, unicode=true;
   const file = fso.CreateTextFile(vbsScriptFile, overwrite, unicode);
   file.Write(vbsScriptContent);
   file.Close();
}

9
Automation Interface, Add-Ins and Tools / Re: MSScript for EA 16 64 Bit
« on: December 21, 2023, 07:12:09 pm »
I found a solution, which works, whithout using ScriptControl or Tablacus solution.

you find my solution here:
https://sparxsystems.com/forums/smf/index.php/topic,46571.msg279900.html#msg279900

10
Automation Interface, Add-Ins and Tools / Re: COMObject Error
« on: December 21, 2023, 06:40:27 pm »
Sorry for a rather late reply, but I found a solution for Javascript using COMObject to open a Word document
the trick is the second argument of COMObject. It needs to be set to "true".

var wdAlertsNone    =  0;
var wordDoc = new COMObject("Word.Application", true);
if (wordDoc != null) {
   wordDoc.DisplayAlerts  = wdAlertsNone;
   wordDoc.Visible = false;
   ...
}


I tested it with Javascript on EA 15.2 (32bit) and 16.1 (32bit and 64bit).


11
General Board / Re: Finding messages that are not operations
« on: December 21, 2023, 06:13:58 pm »
I use the following SQL query (MySQL) to retrieve the linked operation of a message in a sequence diagram.

SELECT CONN.CONNECTOR_ID, IFACE.OBJECT_ID AS [INTERFACE_ID], IFACE.NAME AS [INTERFACE], IFACE.OBJECT_TYPE, OPER.OPERATIONID, OPER.NAME AS [OPERATION],
OPER.STYLE AS [REQUEST], OPER.TYPE AS [RETURN], CONN.PDATA4 AS [IS_RETURN]
FROM T_CONNECTOR CONN
LEFT JOIN T_CONNECTORTAG CONNTAG ON CONN.CONNECTOR_ID=CONNTAG.ELEMENTID AND CONNTAG.PROPERTY='operation_guid'
LEFT JOIN T_OPERATION OPER ON OPER.EA_GUID=CONNTAG.[VALUE]
LEFT JOIN T_OBJECT IFACE ON OPER.OBJECT_ID=IFACE.OBJECT_ID
WHERE CONN.CONNECTOR_ID IN (83509, 89807)


result:
CONNECTOR_ID;INTERFACE_ID;INTERFACE         ;OBJECT_TYPE;OPERATIONID;OPERATION         ;REQUEST;RETURN;IS_RETURN;
83509       ;32126       ;OneApp Vehicle API;Interface  ;11076      ;getParkingPosition;       ;void  ;0        ;
89807       ;            ;                  ;           ;           ;                  ;       ;      ;0        ;


first connector does have a linked operation
second connector does not have a linked operation

12
Bugs and Issues / Re: EA16 JavaScript DLGInputBox bug
« on: December 21, 2023, 05:28:44 pm »
I did find a solution for a messagebox and inputbox using EA 16.x (64 bit) and Javascript.

for a MessageBox it is rather simple solution. Instead of using Scriptcontrol you can use WScript.Shell:

function MsgBox(prompt="", title="MsgBox", style=0) {
   style += 4096; // to make the popup active (foreground)
   var WSH = new COMObject("WScript.Shell");
   return WSH.Popup(prompt, 0, title, style);
}


Regarding an inputbox it is a little more complex. I am using two steps. First it creates a small vbs script in %TEMP% folder. Then it uses this vbs script to display the input box.

function InputBox(prompt="Input", title="Inputbox", defaultText="") {
   const fso = new COMObject("Scripting.FileSystemObject");
   const WSH = new COMObject("WScript.Shell");
   const vbsScriptFile = WSH.ExpandEnvironmentStrings("%TEMP%\\ea_inputbox.vbs");
   const tmpInputFile  = WSH.ExpandEnvironmentStrings("%TEMP%\\ea_input.tmp");
   
   if (!fso.FileExists(vbsScriptFile)) {
      CreateInputboxVBS(vbsScriptFile);
   }
   
   WSH.Run(`WScript "${vbsScriptFile}" "${tmpInputFile}" "${prompt}" "${title}" "${defaultText}"`, 1, true);
   const ForReading = 1;
   const file = fso.OpenTextFile(tmpInputFile, ForReading);
   if (!file.AtEndOfStream) {
      return file.ReadAll();
   }
}

function CreateInputboxVBS(vbsScriptFile) {
   // function to create the inputbox VBS sripts in folder
   const vbsScriptContent = `dim tmpInputFile, prompt, title, defaultText, input
      Set objArgs = WScript.Arguments
      If objArgs.Count = 4 Then
         tmpInputFile = objArgs(0)
         prompt       = objArgs(1)
         title        = objArgs(2)
         defaultText  = objArgs(3)
         input        = InputBox(prompt, title, defaultText)
      End if
         
      Const ForWriting = 2, CreateIfNeeded = true
      set fso = CreateObject("Scripting.FileSystemObject")
      set file = fso.OpenTextFile(tmpInputFile, ForWriting, CreateIfNeeded)
      file.write input
      file.close`.replace(/\t\t/g, '');
   
   const overwrite=true, unicode=true;
   const file = fso.CreateTextFile(vbsScriptFile, overwrite, unicode);
   file.Write(vbsScriptContent);
   file.Close();
}

Pages: [1]