Author Topic: Concept code: Functioning COM object in simulation  (Read 1531 times)

MartijnB

  • EA Novice
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Concept code: Functioning COM object in simulation
« on: April 04, 2014, 11:13:42 pm »
I had a lot of problems using the JavaScript COM objects function in simulation, multiple searches on this forum also did not answer my questions. But I found out that the creation of the COM objects worked perfectly, only their functions could not be used due to still unknown reasons.

Quite by chance I found one COM object which did function, and which I am now using to store simulation variables in an external file. For all the other users which also ran agains this problem I now post my concept solution here. The solution uses xmlhttp and will transmit a http post request to a server. To test the code a requestbin could be made on the  the site http://requestb.in and the URL should be entered in the code shown here:

Code: [Select]
var RequestBinURL = "http://requestb.in/12xzt9y1";
var Data = "Hello world!";
var xmlhttp = new COMObject("Msxml2.XMLHTTP.3.0");
xmlhttp.open("POST",RequestBinURL, false, "", "");
xmlhttp.send(Data);

When this code is working when the simulation is running the posibilities are endless. I my case the post request is transmitted to a local webserver on the same PC which uses a PHP script to store the transmitted data in a file.
Good luck with your application  ;)
« Last Edit: April 04, 2014, 11:18:50 pm by MartijnB »

Mhatch

  • EA User
  • **
  • Posts: 27
  • Karma: +0/-0
    • View Profile
Re: Concept code: Functioning COM object in simula
« Reply #1 on: April 24, 2014, 04:26:37 am »
Was your issue by any chance errors calling the com object method, where you would get an error in javascript code that said 'method is not a function'?

I am seeing this error as well and would like to know if there is a solution.  This only occurs in scripts created specifically as type 'JavaScript', but not JScript.

AltSteven

  • EA Novice
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Re: Concept code: Functioning COM object in simulation
« Reply #2 on: July 19, 2019, 08:46:47 pm »
5 years later.

I am trying to do the exact same thing. I want to communicate with Enterprise architect in Simulation mode from an external application.

I've made an add-in that I can load into Enterprise Architect (Tutorial see: https://bellekens.com/2011/01/29/tutorial-create-your-first-c-enterprise-architect-add-in-in-10-minutes/)

And I now call it from a simulation script (as described here: https://sparxsystems.com/enterprise_architect_user_guide/14.0/model_simulation/dynamic_simulation_with_javasc.html)

Code: [Select]
this.EAInterfaceObject = new COMObject("EAInterface.EAInterfaceClass");
this.EAInterfaceObject.send("CD Stopped");

But in the Simulation output i get:

Code: [Select]
[10035272]      TypeError: sim.EAInterfaceObject.send is not a function
Any insight would be highly appreciated!