All, I have struck some seemingly contradictory information and would appreciate a comment on the correct method to access a side database (dwg), edit, and save to the same name. I have been doing this for ages but now wonder if correctly:
// Fenton version
public static void DoSomeWorkExt01(string DwgToProcess)
{
using (Database db = new Database(false, true))
{
db.ReadDwgFile(DwgToProcess, FileOpenMode.OpenForReadAndReadShare, false, "");
// closing the input makes sure the whole dwg is read from disk
// it also closes the file so you can SaveAs the same name
db.CloseInput(true);
// store the current working database, to reset
Database currDb = HostApplicationServices.WorkingDatabase;
// set working database
HostApplicationServices.WorkingDatabase = db;
{Do Some Work}
db.SaveAs(DwgToProcess, DwgVersion.Current);
// reset the working database
HostApplicationServices.WorkingDatabase = currDb;
}
}
// my code currently
public static void DoSomeWorkExt02(string DwgToProcess)
{
using (Database db = new Database(false, false))
{
db.ReadDwgFile(DwgToProcess, FileOpenMode.OpenForReadAndWriteNoShare, true, "");
{Do Some Work}
db.SaveAs(DwgToProcess, DwgVersion.Current);
}
}
Thanks, Dale.
Setting the HostApplicationServices.WorkingDatabase seems to be needed for some operations. From the docs:
Many areas of ObjectDBX code require a database to query for information. For example, if you make an Entity in memory, it may require default information from a database. It will take that information from the working database.
Can't find what you're looking for? Ask the community or share your knowledge.