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

How to detect and get running AutoCAD

11 REPLIES 11
Reply
Message 1 of 12
ognyandim
2005 Views, 11 Replies

How to detect and get running AutoCAD

Hi all,
I searched the forum history, but did not find such a thread.

I know how to start AutoCAD (programmatically), but I don`t know how to detect if there is already a running version of AutoCAD. I want to do this in order not to load another instance of AutoCAD, but to use the already opened instance (programmatically).

Thanks for any tips or links to any articles. Edited by: ognyandim on Jul 20, 2009 12:32 PM
11 REPLIES 11
Message 2 of 12
arcticad
in reply to: ognyandim

This was already discussed here.

http://discussion.autodesk.com/forums/thread.jspa?messageID=6212728챸
---------------------------



(defun botsbuildbots() (botsbuildbots))
Message 3 of 12
ognyandim
in reply to: ognyandim

Thanks a lot.
Message 4 of 12
ognyandim
in reply to: ognyandim

Hi again.
I read the post that you gave me. After that I read this:
http://discussion.autodesk.com/forums/thread.jspa?messageID=3705449
and this:
http://www.cadforums.net/ftopic3541.html
and this:
http://www.cadtutor.net/forum/archive/index.php/t-16223.html
and this:
http://discussion.autodesk.com/forums/thread.jspa?threadID=464492

but still can`t start AutoCAD from C# code and then use it through the Managed Class (.NET not COM).

See the code in the ZIP file. Try it. It works (Acad 2008,2007) but I dont know how to finish it.
Read the comments I left in the last try-catch section.

class Program
{
static void Main(string[] args)
{
AcadApplication autoCADApplication;
try
{
autoCADApplication = (AcadApplication)System.Runtime.InteropServices.Marshal.GetActiveObject("AutoCAD.Application");
Console.WriteLine("Autocad has been catched!");
return;
}
catch(System.Exception e)
{
Console.WriteLine("No AutoCAD instance : " + e.Message);
try
{
Console.WriteLine("Loading AutoCAD.\n");
autoCADApplication = new Autodesk.AutoCAD.Interop.AcadApplicationClass();
autoCADApplication.Visible = true;
//It works to this line
// And my idea is to somehow get this "autoCADApplication" from COM to .NET in order to declare object like these:
//Document doc = Application.DocumentManager.MdiActiveDocument;
//Editor ed = doc.Editor;
//Database db = doc.Database;
//Transaction tr = db.TransactionManager.StartTransaction();
....

My idea is to look for AutoCAD, if not present - start it, and then use it with the .NET managed class, not COM interface.

Edited by: ognyandim on Jul 21, 2009 2:53 PM

Correct me if this is not possible at all. Edited by: ognyandim on Jul 21, 2009 2:57 PM
Message 5 of 12
norman.yuan
in reply to: ognyandim

See comments inline (of your code).

class Program
{
static void Main(string[] args)
{
AcadApplication autoCADApplication;
try
{

=================
This code should get an COM AcadApplication object instance, if there is an running AutoCAD session.
However, since you "return" right after you obtained the AcadApplication, your application ends immediately.
=================

autoCADApplication = (AcadApplication)System.Runtime.InteropServices.Marshal.GetActiveObject("AutoCAD.Application");
Console.WriteLine("Autocad has been catched!");
return;
}
catch(System.Exception e)
{
Console.WriteLine("No AutoCAD instance : " + e.Message);
try
{
Console.WriteLine("Loading AutoCAD.\n");
autoCADApplication = new Autodesk.AutoCAD.Interop.AcadApplicationClass();
autoCADApplication.Visible = true;
//It works to this line

=====================
So, the above a few lines of code worked, as they should, as long as you have Acad Type library referenced in your project.

But the code below will absolutely not work: you cannot run Acad .NET API code
outside AutoCAD (in your stand-alone application!
=====================


// And my idea is to somehow get this "autoCADApplication" from COM to .NET in order to declare object like these:
//Document doc = Application.DocumentManager.MdiActiveDocument;
//Editor ed = doc.Editor;
//Database db = doc.Database;
//Transaction tr = db.TransactionManager.StartTransaction();

Norman Yuan

Drive CAD With Code

EESignature

Message 6 of 12
ognyandim
in reply to: ognyandim

Thanks 🙂 I got it now.
I will start Acad with the standalone app and then load my .dll inside Acad and then call its internals from the standalone. I was confused a bit, but you made it clear. Thanks once again.
Message 7 of 12
Anonymous
in reply to: ognyandim

So, this link would be helpful to your case:

http://through-the-interface.typepad.com/through_the_interface/2009/05/interfacing-an-external-com-application-with-a-net-module-in-process-to-autocad.html

"ognyandim" wrote in message news:6222612@discussion.autodesk.com...
Thanks 🙂 I got it now.
I will start Acad with the standalone app and then load my .dll inside Acad
and then call its internals from the standalone. I was confused a bit, but
you made it clear. Thanks once again.
Message 8 of 12
ognyandim
in reply to: ognyandim

Thanks once again. I read this blog daily, but missed that post for sure. 🙂

I am sure that this Forum Thread has all the sufficient links for anybody who wants to solve such a problem or get oriented in the environment of Acad COM/NET interfaces.

Edited by: ognyandim on Jul 23, 2009 8:10 AM

I will add this link too:

Launch AutoCAD from .NET application.
http://through-the-interface.typepad.com/through_the_interface/2007/12/launching-autoc.html

A very-very good article dor COM interop with .NET assembly 🙂
http://through-the-interface.typepad.com/through_the_interface/2009/05/interfacing-an-external-com-application-with-a-net-module-in-process-to-autocad-redux.html

Edited by: ognyandim on Jul 23, 2009 8:14 AM
Message 9 of 12
rajpaul75
in reply to: ognyandim

Hi All,

Can some one tell How to detect and get running autocad in Vb.net . I have a standalone application in Visual express 2008.

Thanks for your help
Paul
Message 10 of 12
ognyandim
in reply to: ognyandim

Hi there!

1. Look at the last tree links to http://through-the-interface.typepad.com/
2. Get the code you want.
3. Get this tool : http://msdn.microsoft.com/en-us/magazine/cc163652.aspx
4. Install it.
5. Copy-Paste your code in your VB project.
Message 11 of 12
ognyandim
in reply to: ognyandim

Another link for converting C# <-> VB
http://through-the-interface.typepad.com/through_the_interface/2009/07/converting-between-c-and-vbnet.html Edited by: ognyandim on Jul 24, 2009 9:03 AM
Message 12 of 12
rajpaul75
in reply to: ognyandim

Hi

Thanks for your quick response. This website http://through-the-interface.typepad.com/ is not loading in Dubai(Middle East) I tryed 6 locations with high speed internet connections.


Could you please send me the messages in the last three links as you specified

my email is rajpaul75@gmail.com or post here.

It will be more helpful for me.


I installed the next MSDN tool .


I appreciate your help

Thank you
Paul

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