using Autodesk.AutoCAD.Windows.Data;
public static Bitmap BlockPreview(string blockName)
{
Bitmap result
= new Bitmap
(1,
1); if (Active.Document == null) return result;
using (Transaction acTr = Active.TransactionManager.StartTransaction())
{
BlockTable bt = (BlockTable)acTr.GetObject(Active.Database.BlockTableId, OpenMode.ForRead);
if (!bt.Has(blockName)) return result;
BlockTableRecord btr = acTr.GetObject(bt[blockName], OpenMode.ForRead) as BlockTableRecord;
if (btr == null) return result;
if (btr.HasPreviewIcon)
{
result = btr.PreviewIcon;
}
else
{
// generate the preview icon
result
= new Bitmap
(ImageSourceToGDI
(CMLContentSearchPreviews
.GetBlockTRThumbnail(btr
) as BitmapSource
)); }
acTr.Commit();
}
return result;
}