You are here:

AutoCAD/Code reopen current drawing

Advertisement


Question
Mr. R, i've been using autocad for several years now. I also know the basic concept of programming in autolisp. However, I've been reading up on c# & recently purchased my book & copy of Visual Studio. Very intimidating I might add. I'm looking for a simple code in c# for autocad to reopen the current drawing (disregarding any changes to its dbase & not saving any data at all). I'm still not sure how to start the code but anything you can provide I can surely dissect and learn from. Thank you for your time.

-Best regards,
Mike

Answer
Hi Mike,

First you need create the Project of type Class Library and take the below mentioned dlls as reference which are exist in AutoCAD installation folder or Object ARX SDK installed folder.

acdbmgd.dll
acmgd.dll

Before using the below code please go through the SDK Help documents which gives you more information.


using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Runtime;
using AcadApp = Autodesk.AutoCAD.ApplicationServices.Application;

public static void OpenDrawing(string strFileName )
{
 DocumentCollection acDocMgr = AcadApp.DocumentManager;

 if (File.Exists(strFileName))
 {
     acDocMgr.Open(strFileName, false);
 }
 else
 {
     acDocMgr.MdiActiveDocument.Editor.WriteMessage("File " + strFileName +
         " does not exist.");
 }
}


public void CloseDrawing()
{
  Document oDoc = AcadApp.DocumentManager.MdiActiveDocument as Document;
  oDoc.CloseAndDiscard();
}

The above code is not tested. I am not having the environment.

The remain things you can get from the documents available with the Object ARX SDK. I think this will provide you a start with AutoCAD with c#. Still you need any information...don't hesitate to post me a question.

AutoCAD

All Answers


Answers by Expert:


Ask Experts

Volunteer


Ramanjaneyulu .J

Expertise

Any doubts bound to AutoCAD Customization with AutoLISP, VLISP, VBA, Objectarx and also with C#

Experience

I hold experience in the GIS industry in delivering the customized breakthroughs for the below products. AutoCAD AutoCAD Map AutoCAD Overlay

Organizations
Cyient(Infotech Enterprises Ltd) (Current) Avineon India Pvt Ltd DSM soft Alcor Technologis Pvt Ltd

Education/Credentials
Diplioma in Mechanical Engineering

©2016 About.com. All rights reserved.