Multiple Processes to Multiple Inventor.Application objects
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have introduced a new batch modification tool that runs with such a large batch it would be better to open multiple Inventor threads, and leave them open for the user, each having a threshold maximum number of files, before the next thread is created. The machines can handle more processing than the Inventor platform, so naturally, I run multiple Inventor threads. This is all working out fine, but cleaning things up is not so easy.
This tool's purpose is to start the work for the user and let them follow up adding custom changes, then close everything. With this tool, and others like it I find a strong need to be able to capture every instance of the processes named "Inventor" and cast each one into an Inventor.Application object. My attempt to apply a similar process written for Excel has not been productive, so I am calling on the advanced developers for help. Here is my code so far:
For Each p As Process In Process.GetProcessesByName("Inventor") 'Debug.Print(p.ProcessName) Dim guid As New Guid("{B6B5DC40-96E3-11d2-B774-0060B0F159EF}") Dim obj As Object = Nothing Dim OBJID_NATIVEOM As Long = &HFFFFFFF0 Dim h As IntPtr = AccessibleObjectFromWindow(p.MainWindowHandle, OBJID_NATIVEOM, guid.ToByteArray, obj) Dim iApp As Inventor.Application = obj.Application
Next
I can't get the AccessibleObjectFromWindow to not throw an error (Exception thrown: 'System.OverflowException'), it was imported properly like so:
<DllImport("Oleacc.dll")> Private Function AccessibleObjectFromWindow(hwnd As Int32, dwObjectID As UInt32, riid As Byte(), ByRef ptr As Object) As Int32 End Function
My best guess is I'm not fully understanding the required inputs. With Process.GetProcessesByName, I successfully get all (4 for my test) Inventor's running. Next I need to turn those processes into class instances of Inventor.Application, so I can work with each one.
With the Inventor Apps I create, using (invApp = Marshal.GetActiveObject("Inventor.Application")), I keep the class references. But I need full control over all instances of Inventor on the machine to make sure nothing is duplicating (say during a crash event that leaves things running), and to inspect open documents before processing.
I feel there is something I'm missing, and that it should be way simpler to late bind to a process than the googlites say. Please help.
Thanks,
jvj