I have a vb.net application that works fine in acad2012. I converted it to 2013 (new references, including accoremgd.dll) and I'm aware of the document extension aspect of the CloseAndDiscard method, although I don't fully understand the "big split" and its details. I'm using Visual Studio 2010 Express.
Everything works until the end of the application where I need to close the drawing. I'll paste in the last bit of code (this thing wraps the longer code lines):
So, just before EndSub, I'm trying to close the drawing (not exit ACAD, just close the drawing). Does anyone know what I'm missing here? I've been looking online to find how other users do this and this code is what I've found. But it's not working for me.
You should set CommandFlags.Session in your custom AutoCAD command. Otherwise, it will fail to close the current AutoCAD drawing session (the opened document, not AutoCAD application).
DocumentExtension.CloseAndSave(Application.DocumentManager.MdiActiveDocument) will save and the close the working document.
DocumentExtension.CloseAndDiscard will close document without saving. Here is the code for testing:
<CommandMethod("CloseAndSave", CommandFlags.Session)> _
Public Shared Sub CloseAndSave()
Dim doc As Document = Application.DocumentManager.MdiActiveDocument
Dim db As Database = doc.Database
Using trans As Transaction = db.TransactionManager.StartTransaction()
Dim blockTable = DirectCast(trans.GetObject(db.BlockTableId, OpenMode.ForRead), BlockTable)
Dim modelSpace = DirectCast(trans.GetObject(blockTable(BlockTableRecord.ModelSpace), OpenMode.ForWrite), BlockTableRecord)
Dim line = New Line(Point3d.Origin, New Point3d(5, 5, 0))