Using COM of an already running E3 instance

HI!

I am developing an application using Visual Studio 2017 that process an E3 project.

Instead of creating a new instance of the COM with this line of code:

e3App = Activator.CreateInstance(Type.GetTypeFromProgID("CT.Application")) as IApplicationInterface;

and then using e3App object to open the project file and do stuff, I would like to get the already running instance and use directly the opened project (if both are available...)

Is it possible? How?

 

Thanks in advance for your support.

 

Best regards

Michele Mura

0

Comments

10 comments
  • Set e3App = CreateObject("CT.Application")

  • Did you see in the COM help that there's a section under Dispatcher called "Examples with Running Object Table (ROT)"?

    It will return all of the running E3 applications.

     

     

  • Hi everybody!

    Both answers were very interesting..

    Let's proceed step by step.. I have found that using:

    Process[] pname = Process.GetProcessesByName("E3.series");

    and then testing the .Length of the array pname, I can check if more than one E3 instances are running.

    Then, using the method .GetE3ByProcessId of the dispatcher and giving the process ID (.Id property of pname[0]) I think I can attach to an existing E3 Application object and start using it (instead of creating a new one like in my previous post).

    The problem now is:

    What I have to do to create a CT.Dispatcher object? (to call the .GetE3ByProcessId method)


    Thanks again for all your replies.

    mm

  • The Running Object Table is an alternative approach to Dispatcher. It does not require to have the Dispatcher installed.

    There's C# code example for Running Object Table in the Help... (at least for E3 2017). The sample code creates a dictionary of running E3 processes. You'd need to create a dialog that allows the user to pick the running process when more than one is running.

    If you just have one running instance of E3, you can just use the line of code you posted. It will latch onto to the running process. If you have multiples, the CT.Application seems to latch onto first instance of a process it sees which burns me every time I forget to shut down other E3 sessions.

  • Ah, ok... Now is clearer... The Dispatcher must be installed in order to be able to create a CT.Dispatcher object...

     

    So you are saying if I call:

    e3App = Activator.CreateInstance(Type.GetTypeFromProgID("CT.Application")) as IApplicationInterface;

    and I have only one instance of E3 running, e3App will point to that one and no second instance will be launched?

     

    Another question.. When I create an object of CT.Application type.. I will execute Cable or Schematics module?

    Thanks again for your support

     

    mm

  • I don't know a lot about the inner workings of the CT.Application but it doesn't seem to create a new instance if E3 is already running. If E3 was not running, it may create an instance.

    The CT.Application will work for either Cable, Schematic, Formboard, Panel but is dependent on your license.

  • For C#:

    using System.Runtime.InteropServices;

    private void E3connect()

    {

          dynamic e3Application = Marshal.GetActiveObject("CT.Application");

          dynamic Job = e3App.GreateJobObject();

     } 

    OR 

    using System.Runtime.InteropServices;

    using e3; //COM e3.series

    private void E3connect()

    {

        e3Application e3App = 

        (e3Application)Marshal.GetActiveObject("CT.Application");

        e3Job job = e3App.CreateJobObject();

    }

  • Hi Nikolay!

    I also tried your code but I get this error (both solution)

    when I call the method .GetActiveObject

    Obviously E3 is running - already checked with

    Process[] pname = Process.GetProcessesByName("E3.series");

    What I am doing wrong?

     

    Thanks

    mm

  • E3.series and C #  application must be opened by one user. (Exception : if Visual Studio is opend by an administrator, but C# application - not)

  • HI!

    Sorry for the delay but I was really busy..

    I have tried this way (now both are opened as Admin - VS and E3) - only a small part of the code

    Process[] pname = Process.GetProcessesByName("E3.series");
    if (pname.Length > 0)
    {
       if (pname.Length == 1)
       {
          e3App = (e3Application)Marshal.GetActiveObject("CT.Application");
          e3Job = e3App.CreateJobObject();
       }

    and the object e3Job has a correct value!

     

    Thanks everybody for your support.

    mm

Please sign in to leave a comment.

Didn't find what you were looking for?

New post