.NET

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

Get instance AutoCAD with c#

598 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 (598 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
Posts: 4
Registered: ‎05-14-2004
Message 3 of 5 (598 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
Posts: 223
Registered: ‎02-17-2006
Message 4 of 5 (598 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
Posts: 94
Registered: ‎01-03-2007
Message 5 of 5 (598 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.

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Welcome to the new Autodesk Community!
If this is your first visit, click here to get started and make the most of the Community. Let us know what you think of the new experience in the Community Feedback Forum.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community