I'm in a situation where I need to connect to specific instances of AutoCAD and Plant3D.
The Running Object Table (ROT) only holds one instance so GetObject wont work.
I've tried getting the correct instance using the hwnd with the AccessibleObjectFromWindow function.
Does anyone have a solution to this problem?
I'am thinking the easiest way is to autoload a plugin to communicate with, maybe through a service.
Check this out, all you should have to do is put it in a vb .net class project and include the 5 usual references to acad dlls and it should be ready to go.
I'm trying to figure this out as well. From my external application, I need to open a drawing file in AutoCAD, but I need to be able to distinguish between AutoCAD, CIvil 3D, and other verticals which are installed and may be running simultaneously. I would use Process.Start, but that starts a new instance instead of openinig the file in an already running instance.
GetObject works great if only one instance of AutoCAD is running, but I don't see a way to deal with multiple instances. Can anyone point me in the right direction? I'm not understanding how sszabo's linked post solves this issue.
As I was thinking and as sszabo suggested I solved this problem by writing a WCF service that is hosted in each instance of AutoCAD.
When you want to open a drawing, just loop through the services (if any are listening) and ask which application its
been loaded into. If correct application is returned, ask the service to open the drawing for you.
For the service to be autoloaded you need to use AutoCAD 2012 or later.
You might also have been able to solve the problem using the RunningObjectTable, as it should contain an entry for every open document that has a filename, from all running instances of AutoCAD.
I didn't say that GetObject() will work, I said there will be an entry in the ROT for files drawings that have filenames, but you would have to get the IDispatch interface for the IAcadDocument from the ROT, and then get the application object from that.
And yes, if there are no open documents or no documents with filenames, you can't get a reference to the Application, but usually the need to get a specific application has something to do with one of the open documents in it, since there's not much else to distinguish them.
the easiest way to identify a running process is to start the process with an 'identifying' command line arg... For instance,
acad.exe /projectName Test12345
once you have the app started, you can scan the ROT, then extract the command line parameters and know which one is the one you want.