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

Get instance AutoCAD with c#

4 REPLIES 4
Reply
Message 1 of 5
jjlaseca
2883 Views, 4 Replies

Get instance AutoCAD with c#

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
4 REPLIES 4
Message 2 of 5
Anonymous
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
Message 3 of 5
tfurness
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
Message 4 of 5
jbooth
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.
Message 5 of 5
Jean-Marc68
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.

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