Identify Image status

By Virupaksha Aithal

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();
    }
}

Comments

2 responses to “Identify Image status”

  1. Hi,
    Part of my job involves electronically checking AutoCAD files designed and drafted by our consultants. One of my checking activities is checking xrefs. Somewhere in your toolbox of goodies, do you have a similar program in lisp or .net that reports on the status of an xref, i.e., attached, overlay, not found, unresolved, orphaned, unloaded, etc.?
    Thank You!

  2. Hi Randy,
    For starters, look up the methods/properties of the BlockTableRecord class in the ObjectARX Managed Reference Guide (part of the ObjectARX SDK – http://www.objectarx.com).
    Cheers,
    Stephen

Leave a Reply

Discover more from Autodesk Developer Blog

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

Continue reading