Sparx Systems Forum
Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: Helmut Ortmann on September 22, 2023, 06:14:59 pm
-
Hello,
I want to use MSScript for EA 16 64 Bit to start a JScript. The existing MSScript seems not to run in the EA 64 Bit environment.
Is there a way to start a JScript via MSScript or a workaround?
Thanks for your help.
Helmut
-
Hello,
The error seems to be known and confirmed by SPARX:
- https://sparxsystems.com/forums/smf/index.php?topic=46571.0
-
Hello,
OpenSource tsc64.dll (64 bit Tablacus Scripting Control) solves the issue. It's a 64-bit replacement of Microsoft ScriptControl ActiveX.
See:
https://tablacus.github.io/scriptcontrol_en.html
Good luck,
Helmut
-
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 (https://sparxsystems.com/forums/smf/index.php/topic,46571.msg279900.html#msg279900)
-
Whilst a solution has been found for Javascript, there isn't any for JScript + EA 16 64 bits. Is it unlilkely there will be any solution in the future (feasbility issue) ?
Options are:
- Use EA 16.1 32 bits: whilst using 64 bits is a default recommendation, I'm not convinced yet there will be any major impact for users in installing the 32 bits version
- Migrate the code to Javascript and use the custom solution: this can be time consuming if there is quite a lot of code to make compatible with Javascript
Notes:
- there doesn't seem to be any impact for VBScript projects with EA 16 64 bits
- Session.input is unfortunately limited as it doesn't support a custom text to be displayed e.g. provide the name of the diagram to process: A, B, C...
-
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();
}
-
Hi Jan,
Thank you for sending the new script which works in EA16 64 bits :D
-
Hi Jan
Fantastic! Thanks a lot.
Does anyone out there have a JavaScript version of this?
Phil
-
Hi Jan
Apologies I found your JavaScript version just after posting my previous message :)
Thanks again for both versions of this script
Phil