Acad 2012 VS 2010 Ex.
Just thought I'd share what I learned today.
I rewrote my lisp odbx program to net using ReadDwgFile.
If I put 2 lines of code before the SaveAs, the bitmap is saved with the drawing and appears at the next open dialog.
Why? I don't know.
Bitmap thumb = database.ThumbnailBitmap;
database.ThumbnailBitmap = thumb;
database.SaveAs(str, DwgVersion.Current);
Here's the whole routine, saved as a CommandMethod
public void FindTextInDrawing()
{
Document document = AcadApp.DocumentManager.MdiActiveDocument;
Editor editor = document.Editor;
string filename = filePath + loginname + "lundfl.txt"; //list of filenames.
string OldNums = "G:\\AutoCAD2012Support\\LispText\\OldParts.txt";
string NewNums = "G:\\AutoCAD2012Support\\LispText\\NewParts.txt";
if (File.Exists(filename) && File.Exists(OldNums) && File.Exists(NewNums))
{
editor.WriteMessage("Please wait while files are being searched.");
using (document.LockDocument())
{
try
{
string[] lines = File.ReadAllLines(filename); //array of filename strings.
string[] OldParts = File.ReadAllLines(OldNums);
string[] NewParts = File.ReadAllLines(NewNums);
using (Transaction transaction = document.TransactionManager.StartTransaction())
{
foreach (string str in lines)
{
editor.WriteMessage("\nFileName: " + str);
Database database = new Database(false, false);
database.ReadDwgFile(str, System.IO.FileShare.ReadWrite, false, "");
BlockTable table = (BlockTable)transaction.GetObject(database.BlockTableId, OpenMode.ForWrite);
BlockTableRecord btr = (BlockTableRecord)transaction.GetObject(table[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
foreach (ObjectId oid in btr)
{
if (oid.ObjectClass.DxfName == "TEXT")
{
string op = "";
string np = "";
DBText dbt = (DBText)transaction.GetObject(oid, OpenMode.ForWrite);
for (int i = 0; i < OldParts.Length; i++)
{
op = OldParts[i];
np = NewParts[i];
if (dbt.TextString.Contains(op))
{
string val = dbt.TextString;
val = val.Replace(op, np);
dbt.TextString = val;
editor.WriteMessage("\nReplaced: " + op + " with " + np);
}
}
}
}
Bitmap thumb = database.ThumbnailBitmap;
database.ThumbnailBitmap = thumb;
database.SaveAs(str, DwgVersion.Current);
database.Dispose();
}
transaction.Commit();
}
} //try block
catch (System.Exception exception)
{
editor.WriteMessage("\nError: " + exception);
}
finally
{
if (MessageBox.Show("Close the AutoCAD Application?", "Replace Text", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
AcadApp.Quit();
}
}
} //doc lock.
} //if string input ok.
else
{
editor.WriteMessage("\nCheck that all files exist.\n");
}
}