Community
AutoCAD Forum
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Opening AutoCAD From .NET Visual Studio with C#

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

Opening AutoCAD From .NET Visual Studio with C#

Hey guys,

 

If you could look at my stackoverflow.com question and see if you could help out, it would be much appreciated.  Essentailly, I'm trying to launch AutoCAD from a C# library, but it is giving me an error message and not launching.  Like I said, if you have experience and know what could help out, just let me know here or on my stackoverflow.com question.

 

Regards,

Archer

2 REPLIES 2
Message 2 of 3
cad-pe
in reply to: Anonymous

Try this:

 

using System.IO;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Runtime;
 
[CommandMethod("OpenDrawing", CommandFlags.Session)]
public static void OpenDrawing()
{
  string strFileName = "C:\\campus.dwg";
  DocumentCollection acDocMgr = Application.DocumentManager;
 
  if (File.Exists(strFileName))
  {
      acDocMgr.Open(strFileName, false);
  }
  else
  {
      acDocMgr.MdiActiveDocument.Editor.WriteMessage("File " + strFileName +
                                                     " does not exist.");
  }
}

 

From:

AutoCAD .NET Developer's Guide

 

http://docs.autodesk.com/ACD/2010/ENU/AutoCAD%20.NET%20Developer's%20Guide/index.html?url=WS73099cc1...

Message 3 of 3
Anonymous
in reply to: cad-pe

cad-pe, I appreciate the help, but I think this is supposed to be invoked in-process as an AutoCAD command after NETLOADing the .dll, no?  I'm looking for a way to open AutoCAD from a C# program and then invoke commands on it.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost