By Wayne Brill
A drawing that was edited offline has to be re-inserted (merged) into the project. Plant drawings contain subset of project database (BLOB as SQL database). Plant also a knows whether the drawing was saved in the current project or not. If drawing was not saved in the current project, the BLOB has to be merged into the project.
There are several API to handle this situation:
Project.IsDrawingOutOfSync(string dwgname, Database db) – tells whether AcDbDatabase is in sync with project database
Project.UpdatePnPDrawing(Database db, string dwgname, ref PnPSyncConflicts conflicts) – merge blob into project database.
C# example:
[CommandMethod("testOpen", CommandFlags.Session)]
public void testOpen()
{
string strDwgPath;
Database db = new Database(false, true);
Project currentProject =
PlantApp.CurrentProject.ProjectParts["PnId"];
DataLinksManager dlm =
currentProject.DataLinksManager;
// get project drawing
PnPProjectDrawing pnp_dwg =
currentProject.GetDwgFileByName
("C:\\MyProject\\PID DWG\\PumpAnlage.dwg");
// use resolved path
strDwgPath = pnp_dwg.ResolvedFilePath;
db.ReadDwgFile(strDwgPath,
FileShare.ReadWrite, false, null);
// tell DLM to manage drawing database.
//(Documents are automatically enlisted
//when they are opened in editor)
dlm.EnlistDrawing(db);
// dispose will unelist it
if (currentProject.IsDrawingOutOfSync
(strDwgPath, db))
{
PnPSyncConflicts conflicts = null;
currentProject.UpdatePnPDrawing
(db, strDwgPath, ref conflicts);
// tell DLM that drawing related data has to
// be saved in the project database.
// otherwise, DLM will not save drawing sync
// timestamp causing out-of-sync
// situation on drawing open
DataLinksManager.DatabaseToForceSaveComplete
= db;
try
{
db.SaveAs(strDwgPath, DwgVersion.Current);
}
catch (System.Exception ex)
{
}
finally
{
DataLinksManager.DatabaseToForceSaveComplete
= null;
}
}
db.CloseInput(true);
db.Dispose();
DocumentCollection acDocMgr =
Application.DocumentManager;
Document acDoc = acDocMgr.Open(strDwgPath, false);
AcadDocument anAcadDoc =
(AcadDocument)acDoc.GetAcadDocument();
// if(!anAcadDoc.Saved)
anAcadDoc.Save();
}