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):
acDoc.Database.SaveAs(OPORPath,True, DwgVersion.AC1024, acDoc.Database.SecurityParameters)
MsgBox("POR layout has been saved to the Official folder")
'End the last transaction
'remove the documentlock
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.
Thanks so much,
Solved! Go to Solution.
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.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 doc.LockDocument() Using trans As Transaction = db.TransactionManager.StartTransaction() Dim blockTable = DirectCast(trans.GetObject(db.BlockTableId, OpenMode.ForRead), BlockTable) Dim modelSpace = DirectCast(trans.GetObject(blockTable(BlockTableRe
cord.ModelSpace), OpenMode.ForWrite), BlockTableRecord) Dim line = New Line(Point3d.Origin, New Point3d(5, 5, 0)) modelSpace.AppendEntity(line) trans.AddNewlyCreatedDBObject(line, True) trans.Commit() End Using doc.TransactionManager.FlushGraphics() End Using doc.CloseAndSave(doc.Name) 'doc.CloseAndDiscard(); End Sub
Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register
Start with some of our most frequented solutions to get help installing your software.