I do trigger my export during the SaveComplete event:
public void Initialize()
{
Application.DocumentManager.DocumentCreated += DocumentManager_DocumentCreated;
foreach (Document doc in Application.DocumentManager)
{
doc.Database.SaveComplete += OnDatabaseSaveComplete;
}
}
and my event handler:
private void OnDatabaseSaveComplete(object sender, DatabaseIOEventArgs e)
{
// ignore when the document is being auto saved
if (e.FileName.Contains(".sv$"))
return;
Document doc = Application.DocumentManager.MdiActiveDocument;
var currentFilename = doc.Name;
if ((currentFilename.Contains("-CSA-")) ||
(currentFilename.Contains("-S-")) ||
(currentFilename.Contains("-B-")) ||
(currentFilename.Contains("-F-")))
{
ExportTo3dDwf();
}
}
and ExportTo3dDwf detaches all xrefs and thaws all layers... but my intention is to not modify the database.. I want to leave the DWG as is before I detach xrefs and thaw layers in preparation to export to dwf.
So I am using some of the nifty routines found here.. this is the how I am Thawing all layers:
[CommandMethod("Thawall")]
public static void ThawAll()
{
Database db = HostApplicationServices.WorkingDatabase;
LayerTableRecord layer;
string curLayer = (string)Application.GetSystemVariable("CLayer");
using (Transaction tr = db.TransactionManager.StartTransaction())
{
LayerTable lt = tr.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable;
foreach (ObjectId layerId in lt)
{
layer = tr.GetObject
(layerId, OpenMode.ForWrite) as LayerTableRecord;
if (layer.Name != curLayer)
layer.IsFrozen = false;
}
tr.Commit();
Application.DocumentManager.MdiActiveDocument.Editor.Regen();
}
}
So how can I do this, and NOT save / modify the DWG? I have tried removing the commit, but it still modifies the DWG.
In some old LISPs, I see (acad-push-dbmod)
to prevent saving the changes to the drawing. How do I do that in C#?