[CommandMethod("TESTSAVE")]
public void TestSave()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = Application.DocumentManager.MdiActiveDocument.Database;
db.SaveAs(doc.Name, false, DwgVersion.Current, null);
}
[CommandMethod("QsaveNClose","qnc", CommandFlags.Modal | CommandFlags.Session )]
public static void QuickSave()
{
Document dwg = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Database db = dwg.Database;
dwg.SendStringToExecute("_QSAVE ", true, false, false);
dwg.SendStringToExecute("_CLOSE ", true, false, false);
}
Why am I getting an eFileSharingViolation with this code?Code: [Select][CommandMethod("TESTSAVE")]
public void TestSave()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = Application.DocumentManager.MdiActiveDocument.Database;
db.SaveAs(doc.Name, false, DwgVersion.Current, null);
}
I'm working on an app that needs to force a save after completing some operations and I get this error everytime I tried to SaveAs the currrent document. So I wrote this test app to find a solution and I found that even the bare minimum code caused the error.
I'm using SendStringToExecute as a work around but the AutoCAD .NET Developers Guide shows using the SaveAs method
Thanks Tony, works great. I hate depending on SendStringToExecute() since I have no way of knowing when and if it fired.
I don't know how it works since AcadDocument and its Save method are undocumented but it works and thats all I care about.
I am using C3D 2011 version.
I am using C3D 2011 version.
Sorry, the code I posted uses dynamic which requires .NET 4.0.
See my revision to that post for a version that works on any framework version.
Imports Autodesk.AutoCAD.ApplicationServices
Module MyDocExtensions
Sub New()
End Sub
<System.Runtime.CompilerServices.Extension()> _
Public Sub Save(ByVal doc As Document)
Dim acadDoc As Object = doc.AcadDocument
acadDoc.Save()
End Sub
<System.Runtime.CompilerServices.Extension()> _
Public Function IsDocSaved(ByVal doc As Document) As Boolean
Dim acadDoc As Object = doc.AcadDocument
If acadDoc.Saved Then
Return True
Else
Return False
End If
End Function
End Module
Code: [Select]If acadDoc.Saved Then
Return True
Else
Return False
End If
No need to make VB more VerBose than it is:Code: [Select]Return acadDoc.Saved