Author Topic: COMObject Error  (Read 17260 times)

pha

  • EA User
  • **
  • Posts: 39
  • Karma: +0/-0
    • View Profile
COMObject Error
« on: April 21, 2013, 01:05:54 am »
Hello!

When creating a simulation script I'm trying to create an object:
Code: [Select]
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
« Last Edit: April 21, 2013, 01:08:35 am by 666999 »

pha

  • EA User
  • **
  • Posts: 39
  • Karma: +0/-0
    • View Profile
Re: COMObject Error
« Reply #1 on: April 22, 2013, 04:18:05 am »
Any ideas? :-)

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: COMObject Error
« Reply #2 on: April 22, 2013, 05:04:51 am »
Quote
Any ideas? :-)
Probably not at weekends...

q.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13387
  • Karma: +566/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: COMObject Error
« Reply #3 on: April 22, 2013, 04:06:45 pm »
I would first make sure your code works outside of EA, and only then try it from within EA.

Geert

pha

  • EA User
  • **
  • Posts: 39
  • Karma: +0/-0
    • View Profile
Re: COMObject Error
« Reply #4 on: April 22, 2013, 04:17:23 pm »
Quote
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.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13387
  • Karma: +566/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: COMObject Error
« Reply #5 on: April 22, 2013, 04:33:13 pm »
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

Paulus

  • EA User
  • **
  • Posts: 152
  • Karma: +0/-0
    • View Profile
Re: COMObject Error
« Reply #6 on: April 22, 2013, 11:02:45 pm »
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")

pha

  • EA User
  • **
  • Posts: 39
  • Karma: +0/-0
    • View Profile
Re: COMObject Error
« Reply #7 on: April 22, 2013, 11:09:08 pm »
Quote
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:
Quote
One very important feature of the implementation of Javascript in Enterprise Architect's simulator is that it supports the creation of COM objects.

Paulus

  • EA User
  • **
  • Posts: 152
  • Karma: +0/-0
    • View Profile
Re: COMObject Error
« Reply #8 on: April 23, 2013, 04:27:46 am »
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!

Jan van Duuren

  • EA Novice
  • *
  • Posts: 14
  • Karma: +1/-0
    • View Profile
Re: COMObject Error
« Reply #9 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).

EA scripting since 2013 (JScript, Javascript and Node.js)