Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Starting Inventor via Com - Closing will hold the Process open

8 REPLIES 8
Reply
Message 1 of 9
FelixWe
966 Views, 8 Replies

Starting Inventor via Com - Closing will hold the Process open

Hello,

 

im calling the Inventor-API via COM in C#. Frist I'm creating the Object, then setting the Visible-Property to true. After that im releasing the object (I'm not calling the Quit-Method). If the user then closes the Inventor Window, the process will stuck in the Taskmanager, and also wont be able to be interopted anymore.

 

[CODE]

Inventor.Application app = Activator.CreateInstance(Type.GetTypeFromProgID("Inventor.Application")) as Inventor.Application;

app.Visible = true; 

Marshal.FinalReleaseComObject(app);
app = null;

[/CODE]

 

How can i tell Inventor, to really close completly after the User closes the Window?

 

Greetings

  Felix

8 REPLIES 8
Message 2 of 9
xiaodong_liang
in reply to: FelixWe

Hi  Felix,

 

It’s as expected. Starts Inventor through CreateIntance, Inventor is embedded run (i.e. the main(parent) process calls Inventor as a sub(child) process). So main process should explicitly quit Inventor (Application.Quit). It is suggested that you terminate the sub process when your application closes. e.g.

 

Private oApp As Inventor.Application

 

Private Sub Form_Load()

 Set oApp = CreateObject("Inventor.Application")

 MsgBox "Inventor was created!"

  

End Sub

 

Private Sub Form_Terminate()

 If oApp Is Nothing Then

 MsgBox "Inventor was quit!"

 Else

 oApp.Quit  ‘ terminate the Inventor process

Set oApp = Nothing

End If

End Sub

 

 

Regards,

Xiaodong Liang

Developer Technical Services

 

 

Message 3 of 9
FelixWe
in reply to: xiaodong_liang

So there is no way, that i can open Autodesk, create any file, and keep it open so the user can edit it?

 

Do i always have to create a new Instance, Create the File, Close the Instance, and start a new Instance via ShellExecute? 

 

Other Applications, like Microsoft Word, doesnt have this behavior. 

Message 4 of 9
jeppe_99
in reply to: xiaodong_liang

I am having the same problem. Want to start Inventor, create or open a specific file and let the user edit it. However, we end with zombie inventor processes that have to be ended in the Task manager.

We are using AI 2010. Has this been fixed in 11 or 12?

 

Best regards

Jeppe

Message 5 of 9
vince_123
in reply to: FelixWe

Is there a workaround available for this issue? Using Inventor 2013, and stuck up with background Inventor processes that fail to close when i had started inventor via COM.

Message 6 of 9
Mike.Wohletz
in reply to: FelixWe

Using createObject should not be left hanging like this as I don't think the application is designed like that. If this is what you are looking for then why not use something like process start and execute the inventor.exe and they wait a little bit for it to be up and then connect to it via com and do your thing.
Message 7 of 9
FelixWe
in reply to: Mike.Wohletz

So currently i start an "embedded" instance via CreateInstance.

I leave that Instance in background for later usage, due to high startup times.

 

If that instance is running and i open up a file via the explorer, it wont start another instance. Instead it will popup my hidden "embedded" instance, which is set to SilentOperation and have different other settings too, and keeps using this. How can i disable the "reusage" of my "embedded" instance?

 

Regards

 Felix

Message 8 of 9
Mike.Wohletz
in reply to: FelixWe

Try something like the below as this will always try to get a running instance before creating a new one. 

 

    Try
            'this will connect to a current running instance of inventor
            oApp = System.Runtime.InteropServices.Marshal.GetActiveObject("Inventor.Application")

        Catch ex As Exception
            'if the instance was not started to connect to then we will create a new instance
            oApp = CreateObject("Inventor.Application")

        End Try

 

 

Message 9 of 9
FelixWe
in reply to: Mike.Wohletz

I have written a small example of the problem.

 

[Code]

static void Main(string[] args)
        {
            Console.WriteLine("COM-Instance-Problem");

            Type tInventor = Type.GetTypeFromProgID("Inventor.Application");
            Inventor.Application oInventor = (Inventor.Application)Activator.CreateInstance(tInventor);
            Inventor.Document oInventorDocument = oInventor.Documents.Add(Inventor.DocumentTypeEnum.kPartDocumentObject, string.Empty, true);

            Console.WriteLine("At this point, im doing some actions, i emulate them with this ReadLine");
            Console.ReadLine();

            oInventorDocument.Close(true);
            oInventor.Quit();

        }

[/Code]

 

So when you now would start this up with no Inventor running, it will create an instance of it. While the program stops at the ReadLine(), you can open up a file in the explorer. That opening will REUSE the active Inventor-Process! (I tested this with microsoft word, which will start a new process).

 

First thing is, the process seems to be some kind of bugged (Im using Inventor 2014), as it wont display the Ribbon correctly.

But more critical is, that when my operation is finished (Go back to the Program and push Enter), it will completely kill the Inventor, and also the opened File which you might be working on.

 

My question now is: How do i handle this? Is it supposed to "reuse" my "embedded" inventor process?

 

Regards

Felix

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report