Sparx Systems Forum

Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: MrSnow on March 01, 2019, 08:28:18 pm

Title: Writing to text file from JScript in EA
Post by: MrSnow on March 01, 2019, 08:28:18 pm
Hi,

I am working on extracting all information from a class diagram to create a basis for a JSON Schema for the specific diagram i EA. I am using JScript "inside" EA and working up against a database. I am getting an error using this line of code:

"var fh = fopen("c:\\MyFile.txt", 3); // Open the file for writing

Therefore my questions are:


All help and comments are appreciated!
Title: Re: Writing to text file from JScript in EA
Post by: qwerty on March 01, 2019, 09:01:30 pm
You could script outside of EA and connect to an EA instance. J* (IIRC) is supported meanwhile but I don't know much about that J*-stuff.

As a side note: using path strings is always a secret sauce. Try with a plain name before adding paths and then experiment with slashes/back-slashes.

q.
Title: Re: Writing to text file from JScript in EA
Post by: Geert Bellekens on March 02, 2019, 05:27:42 am
"an error" doesn't really help to narrow it down.

Anyway, you can do almost anything from inside EA that you can do from outside EA.

I use VBscript a lot; see https://github.com/GeertBellekens/Enterprise-Architect-VBScript-Library/blob/master/Framework/Utils/TextFile.vbs (https://github.com/GeertBellekens/Enterprise-Architect-VBScript-Library/blob/master/Framework/Utils/TextFile.vbs) for a VBScript class that handles reading and writing to textfiles

If you search the repository for TextFile and you'll find a bunch of usages of the class.

It should be rather straightforward to translate the VBScript to JScript

Geert
Title: Re: Writing to text file from JScript in EA
Post by: qwerty on March 02, 2019, 05:44:37 am
Look into the JScript-CSV in the EaScriptlib. There's a file access for reading (as a start).

q.