.NET

Reply
Contributor
annse
Posts: 15
Registered: ‎04-04-2012
Message 1 of 9 (668 Views)

Handle multiple instances of AutoCAD

668 Views, 8 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
sszabo
Posts: 86
Registered: ‎09-05-2012
Message 2 of 9 (651 Views)

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
BMcAnney
Posts: 406
Registered: ‎12-09-2003
Message 3 of 9 (576 Views)

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
annse
Posts: 15
Registered: ‎04-04-2012
Message 4 of 9 (566 Views)

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
DiningPhilosopher
Posts: 370
Registered: ‎05-06-2012
Message 5 of 9 (543 Views)

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
annse
Posts: 15
Registered: ‎04-04-2012
Message 6 of 9 (534 Views)

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
DiningPhilosopher
Posts: 370
Registered: ‎05-06-2012
Message 7 of 9 (514 Views)

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
annse
Posts: 15
Registered: ‎04-04-2012
Message 8 of 9 (509 Views)

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
fenton.webb
Posts: 352
Registered: ‎07-24-2007
Message 9 of 9 (385 Views)

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


Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.