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

How to use CloseAndDiscard in 2013?

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
edweberg
1933 Views, 2 Replies

How to use CloseAndDiscard in 2013?

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)

 

Application.SetSystemVariable("ISAVEBAK", 1)

 

Application.SetSystemVariable("FILEDIA", 1)

 

MsgBox("POR layout has been saved to the Official folder")

 

'End the last transaction

EndUsing

 

'remove the documentlock

EndUsing

 

DocumentExtension.CloseAndDiscard(Application.DocumentManager.MdiActiveDocument)

 

EndSub

 

------------------------------

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,

 

Erik

 

2 REPLIES 2
Message 2 of 3
khoa.ho
in reply to: edweberg

Hi,

 

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 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(BlockTableRecord.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

 

-Khoa

Message 3 of 3
edweberg
in reply to: khoa.ho

Such a tiny thing, but it made all the difference.  Thank you!

Erik

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