Using “RasterImageDef” API’s “IsLoaded”, “ActiveFileName” & “SourceFileName” you can identify the status of the image in the drawing.
Loaded : IsLoaded return True
Unloaded : IsLoaded is false and ActiveFileName has a valid file name
Not found : IsLoaded is false and ActiveFileName is empty
Below code goes throw all the images definition in the drawing and prints its status.
[CommandMethod("ImageStatus")]
public static void ImageStatus()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
ObjectId imageDict = RasterImageDef.GetImageDictionary(db);
if (imageDict == ObjectId.Null)
{
ed.WriteMessage("No images in the drawing.n");
return;
}
using (Transaction Tx = db.TransactionManager.StartTransaction())
{
DBDictionary ImageDic =
(DBDictionary)Tx.GetObject(imageDict, OpenMode.ForRead);
foreach (DBDictionaryEntry ImageDef in ImageDic)
{
RasterImageDef imageDef = (RasterImageDef)Tx.GetObject(
ImageDef.Value, OpenMode.ForRead);
if (imageDef.IsLoaded)
{
ed.WriteMessage(imageDef.ActiveFileName +
" : loaded" + "n");
}
else
{
//image may be not found or unloaded.
if (imageDef.ActiveFileName.Length == 0)
{
//no file name...
//ed.WriteMessage("file not foundn");
ed.WriteMessage(imageDef.SourceFileName +
" : not found" + "n");
}
else
{
ed.WriteMessage(imageDef.ActiveFileName +
" : unloaded" + "n");
}
}
}
Tx.Commit();
}
}

Leave a Reply