Database.ThumbnailBitmap returns Nothing when called for a side database

By Virupaksha Aithal

The following code does not correctly ready the ThumbnailBitmap property:

using (Database OpenDb = new Database(false, false))
    {
        OpenDb.ReadDwgFile("c:\temp\test.dwg",
            FileOpenMode.OpenForReadAndWriteNoShare, true, "");
 
        Bitmap thumbNail = OpenDb.ThumbnailBitmap;
 
        if (thumbNail == null)
        {
           //
        }
        else
        {
            //
        }
    }

This is because the DWG file has been opened without share permission, and so the ThumbnailBitmap property is unable to query the DWG file for the bitmap. (For performance reasons, the bitmap is read on demand from the DWG file).

The solution is to open the DWG with share permission, for example:

using (Database OpenDb = new Database(false, false))
{
    OpenDb.ReadDwgFile("c:\temp\test.dwg",
        FileOpenMode.OpenForReadAndReadShare, true, "");
 
    Bitmap thumbNail = OpenDb.ThumbnailBitmap;
 
    if (thumbNail == null)
    {
       //
    }
    else
    {
        //
    }
}

Comments

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading