I've been coming up with issues writing changes to an external database (one that is lazy-loaded via Database.readDwgFile()).
While constructing this post I decided to do a couple more tests to make sure that my setup was not working.
What I found is that it was working!
Regardless, I would still like to add to the .NET forums by creating some documentation in case someone else needs it.
When working with an external database or side database that is NOT loaded into the AutoCAD editor, I needed to save changes that were made. Normally, I'd expect that after a transaction is commited, then the changes would reflect... this is NOT what happened.
So I've added this line of code in order to save the database after all changes were committed:
This method works as described in ObjectARX - Managed Class Reference documentation:
Runs the save process on the database and writes the drawing information out to fileName. The fileName argument is taken as is. If no file extension is present, .dwg is not appended.
If the database executing the SaveAs() function is not the current database in the AutoCAD editor, then the thumbnail preview image is not saved to fileName.
To specify security parameters, set security that conveys your preferences.If the security is not properly initialized, the method fails. See SecurityParameters for more information on initializing this struct.
If bBakAndRename is false, then no .bak file is created, a full save is always done, and if the Database being saved is the main database for a document in AutoCAD, then the document's filename will NOT change to the saved name.
Now, when I open the drawing manually, I notice the changes made by the .NET assembly.
I also want to put up here, since it is partially relevant, that I am NOT required to Commit the Transaction for changes to take effect. This appears to be the default behavior upon the closing of a transaction. However, if the transaction is aborted, then no changes are made.
Here is a C# sample that illustrates how to work with ReadDwgFile: it will prompt the user to select an entity in the current drawing, then load a side database and clone the object into it. I would recommend you follow that approach when working on a side database you want to modify.
static public void wblockclone()
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
PromptEntityOptions peo = new PromptEntityOptions("\nSelect entity to copy: ");
PromptEntityResult per = ed.GetEntity(peo);
if (per.Status != PromptStatus.OK)
using(DocumentLock doclock = doc.LockDocument())
ObjectIdCollection ObjectcIds = new ObjectIdCollection();
Database destDb = new Database(false, true);
destDb.ReadDwgFile("c:\\Temp\\DestDrawing.dwg", System.IO.FileShare.ReadWrite, true, "");
using (Transaction Tx = destDb.TransactionManager.StartTransaction())
BlockTable bt = Tx.GetObject(
OpenMode.ForRead) as BlockTable;
BlockTableRecord btr = Tx.GetObject(
OpenMode.ForWrite) as BlockTableRecord;
IdMapping oIdMap = new IdMapping();
Philippe Leefsma Developer Technical Services Autodesk Developer Network