.NET

Reply
Active Member
jjlaseca
Posts: 9
Registered: ‎11-21-2005
Message 1 of 5 (647 Views)

Get instance AutoCAD with c#

647 Views, 4 Replies
11-30-2005 02:00 AM
Hello,

In order to create a AutoCAD instance with c# is necessary this source code:

private Autodesk.AutoCAD.Interop.AcadApplicationClass _app = new Autodesk.AutoCAD.Interop.AcadApplicationClass();


Is it possible get an existing instance of AutoCAD with c#?

thanx
*Bobby C. Jones
Message 2 of 5 (647 Views)

Re: Get instance AutoCAD with c#

12-08-2005 02:02 PM in reply to: jjlaseca
System.Runtime.InteropServices.Marshal.GetActiveObject()
--
Bobby C. Jones
http://www.acadx.com


wrote in message news:5025254@discussion.autodesk.com...
Hello,

In order to create a AutoCAD instance with c# is necessary this source code:

private Autodesk.AutoCAD.Interop.AcadApplicationClass _app = new
Autodesk.AutoCAD.Interop.AcadApplicationClass();


Is it possible get an existing instance of AutoCAD with c#?

thanx
Member
tfurness
Posts: 4
Registered: ‎05-14-2004
Message 3 of 5 (647 Views)

Re: Get instance AutoCAD with c#

02-20-2006 12:27 PM in reply to: jjlaseca
You can start acad as a process by:

Process myProcess = new Process();
myProcess.StartInfo.FileName = acadFilePath + "acad.exe";
myProcess.StartInfo.WindowStyle = myProcessssWindowStyle.Hidden;
myProcess.Start();
object obj = null;
obj = Marshal.GetActiveObject("AutoCAD.Application");

obj now points to an autocad object

or if you want to get the process:
System.Diagnostics.Process [] p = Process.GetProcessesByName("acad");

hope this helps
Distinguished Contributor
jbooth
Posts: 223
Registered: ‎02-17-2006
Message 4 of 5 (647 Views)

Re: Get instance AutoCAD with c#

02-20-2006 04:21 PM in reply to: jjlaseca
This is just something on the side, but you CAN call some of those custom methods that VB programmers are so used to (in C#). You do so by using the Microsoft.VisualBasic namespace.

For example: you can get the Autocad application object by using
Microsoft.VisualBasic.Interaction.GetObject("", "AutoCAD.Application");

However. the solution posted previously is more correct, since that's what the Marshal class is for. This is just FYI.
Valued Contributor
Jean-Marc68
Posts: 94
Registered: ‎01-03-2007
Message 5 of 5 (647 Views)

Re: Get instance AutoCAD with c#

08-15-2008 08:31 AM in reply to: jjlaseca
Hello everybody,

I used something similar to run a #net code called by an icon. That mean I need to find the existing AcadProcess and not open an new Acad instance.
But I have a problem: If different instances of Acad are opened, it always find the first Acad instance. What I try to do is finding the calling Acad instance, what's the instance where click the icon.
But how to do ?

Thanks for code, help or advices,
Jean-Marc

PS: I'm under AcadMap2004.
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.