.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Handle multiple instances of AutoCAD

9 REPLIES 9
Reply
Message 1 of 10
annse
2178 Views, 9 Replies

Handle multiple instances of AutoCAD

Hi!

 

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.

 

Thanks!

Annse

9 REPLIES 9
Message 2 of 10
sszabo
in reply to: annse

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.

 

http://forums.autodesk.com/t5/NET/Catastrophic-failure-HRESULT-0x8000FFFF-E-UNEXPECTED/m-p/3767399#M...

Message 3 of 10
BMcAnney
in reply to: annse

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.

Message 4 of 10
annse
in reply to: annse

Hi!

 

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.

 

//Annse

Message 5 of 10
DiningPhilosopher
in reply to: annse

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.

Message 6 of 10
annse
in reply to: annse

GetObject("MyDrawing.dwg").Application does not work.

What if the instance doesn't have an active drawing?

 

//Annse

Message 7 of 10
DiningPhilosopher
in reply to: annse

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.

Message 8 of 10
annse
in reply to: annse

Ok, I'll definitely do some more digging in the ROT. Thank you!

 

I needed all instances even those without an active drawing.

 

//Annse

 

Message 9 of 10
fenton.webb
in reply to: annse

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.




Fenton Webb
AutoCAD Engineering
Autodesk

Message 10 of 10
bjhuffine
in reply to: fenton.webb

I'm in a similar boat where I need to retrieve the AcadApplication instance of a particular session assuming there are multiple sessions open.  Maybe I'm missing something, but if you scan the ROT, AutoCAD seems to only list the first one opened therefore other sessions will not be seen.  Am I overlooking something?  Or has someone come up with a sound way of doing this?  What should that look like?

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

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost