Bonjour à tous, Dans le but de créer plusieurs sauvegardes automatiques d'un fichier DWG, j'ai écris le code suivant (simplifié): [CommandMethod("ABU", CommandFlags.Session)]
public void AutomaticBackUp()
{
doc = Application.DocumentManager.MdiActiveDocument;
ed = doc.Editor;
currentDb = doc.Database;
if (!doc.IsReadOnly)
{
// Initialize the timer
timer = new Timer();
timer.Interval = 10000;
timer.AutoReset = true;
timer.Elapsed += new ElapsedEventHandler(OnTimedEvent);
timer.Start();
}
}
private void OnTimedEvent(object sender, ElapsedEventArgs e)
{
backUp();
}
private void backUp()
{
string pathFile = folderToBackup + "\\" + currentNbBackup.ToString() + "_" + formatDocName();
using (DocumentLock docLock = doc.LockDocument())
{
// Check the value of DBMOD, if 0 then the drawing has no unsaved changes
if (System.Convert.ToInt16(Application.GetSystemVariable("DBMOD")) != 0)
{
using (Database dbBackup = currentDb.Wblock();)
{
if (File.Exists(pathFile)) File.Delete(pathFile);
dbBackup.SaveAs(pathFile, DwgVersion.Current);
if (currentNbBackup < nbBackup) currentNbBackup++;
else currentNbBackup = 1;
}
}
}
} Ce code fonctionne pour les fichiers sans XREF, mais pour ceux qui en ont, le message d'erreur suivant apparaît: "Tentative de lecture ou d'écriture de mémoire protégée". Je me tourne donc vers vous après avoir essayé plusieurs technique, dont celle du PromptSelectionResult psr = ed.SelectAll();
if (psr.Status == PromptStatus.OK)
{
SelectionSet ss = psr.Value;
ObjectIdCollection oIdColl = new ObjectIdCollection(ss.GetObjectIds());
}
Database dbBackup = doc.Database.Wblock(oIdColl, doc.Database.Insbase) Qui ne fonctionne pas non plus. Par avance, merci à tous !