Sparx Systems Forum
Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: pha on April 21, 2013, 01:05:54 am
-
Hello!
When creating a simulation script I'm trying to create an object:
var newObj = new COMObject ("Word.Application");
newObj.Visible = true;
but when I run the simulation EA shows an error "Failed to create object from CLSID"
I enter the javascript code in the Simulation window when editing a script in Execute Analyzer.
How to solve this problem?
IAT
-
Any ideas? :-)
-
Any ideas? :-)
Probably not at weekends...
q.
-
I would first make sure your code works outside of EA, and only then try it from within EA.
Geert
-
I would first make sure your code works outside of EA, and only then try it from within EA.
Geert
Geert, to try this code into my OS I simply create and run .js-file. It works fine. But from EA I can't call external application.
-
Ah, I think that's crucial information for anyone to be able to help you.
Have you tried searching the forum (using the top left button)?
I think I've seen similar topics.
Unfortunately I don't know how to solve it. :-[
Geert
-
As far as i known you can't create ActiveX objects from within Javascript in EA.
Try changing to vbscript or jscript, for instance,
dim oWord: Set oWord = CreateObject("Word.Application")
-
As far as i known you can't create ActiveX objects from within Javascript in EA.
Try changing to vbscript or jscript, for instance,
dim oWord: Set oWord = CreateObject("Word.Application")
Paulus, I've read this earlier: http://www.sparxsystems.com/cgi-bin/yabb/YaBB.cgi?num=1256123373/1#1
EA supports Dynamic Simulation with JavaScript: One very important feature of the implementation of Javascript in Enterprise Architect's simulator is that it supports the creation of COM objects.
-
Well... even though that may be the case, i'd like to see someone present an example that actually works.
The fact is that it's impossible to get the EA Javascript engine to properly create and use COM/ActiveX objects and though the other two languages for scripting in EA have no problems with COM they can't be used in simulation scripts... :-?
I'd gladly proven to be wrong though!
-
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).