.NET

.NET

Reply
Contributor
18 Posts
0 Kudos
Registered: ‎04-04-2012
Post 1 of 10

Handle multiple instances of AutoCAD

808 Views, 9 Replies
02-05-2013 08:07 AM

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

Valued Contributor
86 Posts
11 Kudos
Registered: ‎09-05-2012
Post 2 of 10

Re: Handle multiple instances of AutoCAD

02-05-2013 10:15 AM 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...

Distinguished Contributor
406 Posts
2 Kudos
Registered: ‎12-09-2003
Post 3 of 10

Re: Handle multiple instances of AutoCAD

03-21-2013 07:39 AM 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.

Contributor
18 Posts
0 Kudos
Registered: ‎04-04-2012
Post 4 of 10

Re: Handle multiple instances of AutoCAD

03-21-2013 08:18 AM 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

Valued Mentor
370 Posts
175 Kudos
Registered: ‎05-06-2012
Post 5 of 10

Re: Handle multiple instances of AutoCAD

03-22-2013 08:33 PM 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.

Contributor
18 Posts
0 Kudos
Registered: ‎04-04-2012
Post 6 of 10

Re: Handle multiple instances of AutoCAD

03-22-2013 11:11 PM in reply to: annse

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

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

 

//Annse

Valued Mentor
370 Posts
175 Kudos
Registered: ‎05-06-2012
Post 7 of 10

Re: Handle multiple instances of AutoCAD

03-23-2013 06:12 PM 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.

Contributor
18 Posts
0 Kudos
Registered: ‎04-04-2012
Post 8 of 10

Re: Handle multiple instances of AutoCAD

03-23-2013 11:41 PM 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

 

ADN Support Specialist
352 Posts
27 Kudos
Registered: ‎07-24-2007
Post 9 of 10

Re: Handle multiple instances of AutoCAD

07-03-2013 09:05 AM 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

Developer Technical Services

Autodesk Developer Network


Valued Contributor
92 Posts
6 Kudos
Registered: ‎08-13-2008
Post 10 of 10

Re: Handle multiple instances of AutoCAD

01-20-2015 04:38 AM 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?

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are you interested in helping shape the future of the Autodesk Community? To participate in this brief usability study, please click here. Your time and input is greatly appreciated!