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

How to connect to the existing instance of acad, instead of creat a new instance?

2 REPLIES 2
Reply
Message 1 of 3
Anonymous
263 Views, 2 Replies

How to connect to the existing instance of acad, instead of creat a new instance?

In C#

using Autodesk.AutoCAD.Interop;

When I call

AcadApplication acadApp = new AcadApplication();

a new instance of acad.exe process will be launched.

How to connect to the existing instance of acad, instead of creat a new
instance?


Thanks.


Forrest
2 REPLIES 2
Message 2 of 3
Anonymous
in reply to: Anonymous

[code]
using System.Runtime.InteropServices;
//...
static void Main() {
AcadApplication acad = GetOrCreateAcadInstance();
if (acad != null) {
acad.Visible = true;
}
}
public static AcadApplication GetOrCreateAcadInstance()
{
AcadApplication acad = null;
try {
acad = (AcadApplication)Marshal.GetActiveObject("AutoCAD.Application");
}
catch {
try { acad = new AcadApplication(); } catch {}
}
return acad;
}
[/code] Message was edited by: Alexander Rivilis
Message 3 of 3
Anonymous
in reply to: Anonymous

Thanks.

Forrest

Alexander Rivilis wrote:
> [code]
> using System.Runtime.InteropServices;
> //...
> static void Main() {
> AcadApplication acad = GetOrCreateAcadInstance();
> if (acad != null) {
> acad.Visible = true;
> }
> }
> public static AcadApplication GetOrCreateAcadInstance()
> {
> AcadApplication acad = null;
> try {
> acad = (AcadApplication)Marshal.GetActiveObject("AutoCAD.Application");
> }
> catch {
> try { acad = new AcadApplication(); } catch {}
> }
> return acad;
> }
> [/code]
>
> Message was edited by: Alexander Rivilis

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