Author Topic: Images, and correct information  (Read 5493 times)

0 Members and 1 Guest are viewing this topic.

T.Willey

  • Needs a day job
  • Posts: 5251
Images, and correct information
« on: June 20, 2007, 06:05:05 PM »
Using '06 .Net 1.1

Does anyone know how to get the correct information of an image that is attached?  I have some code that doesn't work correctly.  Sometimes it will and sometimes it won't.  Sometimes it won't return a path, and it puts the path as the image name.  When I open up the file in Acad it shows correctly in the image dialog.

Here is the code I'm using.  Any help is appreciated.  Thanks.
MyImageInformation is a class I wrote the hold the information in one place.
Code: [Select]
private MyImageInformation[] FindImages (Database db) {
using (Transaction Trans = db.TransactionManager.StartTransaction()) {
ObjectId ImgDictId = RasterImageDef.GetImageDictionary(db);
if (ImgDictId == ObjectId.Null) return null;
DBDictionary ImgDict = (DBDictionary)Trans.GetObject(ImgDictId, OpenMode.ForRead);
if (ImgDict.Count.Equals(0)) return null;
MyImageInformation[] ImInfoArray = new MyImageInformation[ImgDict.Count];
string[] ImNames = new string[ImgDict.Count];
int i = 0;
foreach (DictionaryEntry de in ImgDict) {
string deName = de.Key as string;
ObjectId ObjId = ImgDict.GetAt(deName);
RasterImageDef rid = Trans.GetObject(ObjId, OpenMode.ForRead) as RasterImageDef;
if (rid == null) break;
MyImageInformation ImInfo = new MyImageInformation();
ImInfo.IsEmbedded = rid.IsEmbedded;
ImInfo.ImageName = rid.SourceFileName;
ImInfo.ImagePath = rid.ActiveFileName;
ImInfo.IsLoaded = rid.IsLoaded;
ImInfoArray[i] = ImInfo;
++i;
}
return ImInfoArray;
}
}
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

TonyT

  • Guest
Re: Images, and correct information
« Reply #1 on: June 22, 2007, 05:33:25 PM »
Tim - I think it depends on whether you ask it to save the path
when you attach the image. If you don't, then it just stores the
filename and looks for the file on the AutoCAD library path.

Oh, and watch out for the SearchForActivePath property. I once
read it, and AutoCAD went belly-up.


Using '06 .Net 1.1

Does anyone know how to get the correct information of an image that is attached?  I have some code that doesn't work correctly.  Sometimes it will and sometimes it won't.  Sometimes it won't return a path, and it puts the path as the image name.  When I open up the file in Acad it shows correctly in the image dialog.

Here is the code I'm using.  Any help is appreciated.  Thanks.
MyImageInformation is a class I wrote the hold the information in one place.
Code: [Select]
private MyImageInformation[] FindImages (Database db) {
using (Transaction Trans = db.TransactionManager.StartTransaction()) {
ObjectId ImgDictId = RasterImageDef.GetImageDictionary(db);
if (ImgDictId == ObjectId.Null) return null;
DBDictionary ImgDict = (DBDictionary)Trans.GetObject(ImgDictId, OpenMode.ForRead);
if (ImgDict.Count.Equals(0)) return null;
MyImageInformation[] ImInfoArray = new MyImageInformation[ImgDict.Count];
string[] ImNames = new string[ImgDict.Count];
int i = 0;
foreach (DictionaryEntry de in ImgDict) {
string deName = de.Key as string;
ObjectId ObjId = ImgDict.GetAt(deName);
RasterImageDef rid = Trans.GetObject(ObjId, OpenMode.ForRead) as RasterImageDef;
if (rid == null) break;
MyImageInformation ImInfo = new MyImageInformation();
ImInfo.IsEmbedded = rid.IsEmbedded;
ImInfo.ImageName = rid.SourceFileName;
ImInfo.ImagePath = rid.ActiveFileName;
ImInfo.IsLoaded = rid.IsLoaded;
ImInfoArray[i] = ImInfo;
++i;
}
return ImInfoArray;
}
}

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Images, and correct information
« Reply #2 on: June 22, 2007, 06:08:19 PM »
Tony,

Thanks for the heads up.  I was looking at that thinking it might be helpful, but then I wrote a special find file for the xrefs in the program, so I would have used that one.

I don't know how the image files were saved when attached.  These are consultants drawings, and the images shouldn't be there, but this is just a checking routine to see if xrefs and images will load properly when the drawing is opened.  I can't even find out how to get the name of the image (the one shown in the image manager dialog).  Pretty frustrating to say the least.

Tim - I think it depends on whether you ask it to save the path
when you attach the image. If you don't, then it just stores the
filename and looks for the file on the AutoCAD library path.

Oh, and watch out for the SearchForActivePath property. I once
read it, and AutoCAD went belly-up.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Seth007

  • Mosquito
  • Posts: 5
Re: Images, and correct information
« Reply #3 on: December 01, 2010, 05:22:48 PM »
Have you had any luck on this already?  :?

Tony,

Thanks for the heads up.  I was looking at that thinking it might be helpful, but then I wrote a special find file for the xrefs in the program, so I would have used that one.

I don't know how the image files were saved when attached.  These are consultants drawings, and the images shouldn't be there, but this is just a checking routine to see if xrefs and images will load properly when the drawing is opened.  I can't even find out how to get the name of the image (the one shown in the image manager dialog).  Pretty frustrating to say the least.

Tim - I think it depends on whether you ask it to save the path
when you attach the image. If you don't, then it just stores the
filename and looks for the file on the AutoCAD library path.

Oh, and watch out for the SearchForActivePath property. I once
read it, and AutoCAD went belly-up.

Jeff H

  • Needs a day job
  • Posts: 6150
Re: Images, and correct information
« Reply #4 on: December 02, 2010, 02:25:06 AM »
See if pics help


Seth007

  • Mosquito
  • Posts: 5
Re: Images, and correct information
« Reply #5 on: December 02, 2010, 04:10:50 AM »
See if pics help

Thanks m8, it helps :)

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Images, and correct information
« Reply #6 on: December 02, 2010, 11:31:34 AM »
Here is the code I used for '09.  If you are working in an earlier version, then it will have to change, as they methods used were not accessible yet.  If anything is missing, let me know, and I'll post it back.

Code: [Select]
private MyImageInformation[] FindImages (Database db) {
    using (Transaction Trans = db.TransactionManager.StartTransaction()) {
        DBDictionary LoDict = (DBDictionary)Trans.GetObject(db.LayoutDictionaryId, OpenMode.ForRead);
        ObjectId ImgDictId = RasterImageDef.GetImageDictionary(db);
        if (ImgDictId == ObjectId.Null) return null;
        DBDictionary ImgDict = (DBDictionary)Trans.GetObject(ImgDictId, OpenMode.ForRead);
        if (ImgDict.Count.Equals(0)) return null;
        MyImageInformation[] ImInfoArray = new MyImageInformation[ImgDict.Count];
        int i = 0;
        foreach (DictionaryEntry de in ImgDict) {
            string ImName = de.Key as string;
            ObjectId ObjId = (ObjectId)de.Value;
            RasterImageDef rid = Trans.GetObject(ObjId, OpenMode.ForRead) as RasterImageDef;
            if (rid == null) continue;
           
            MyImageInformation ImInfo = new MyImageInformation();
            ImInfo.ImageName = ImName;
            ImInfo.IsEmbedded = rid.IsEmbedded;
            ImInfo.ImagePath = rid.SourceFileName;
            if (string.Compare(ImInfo.ImagePath, string.Empty).Equals(0))
                ImInfo.ImagePath = rid.ActiveFileName;
            ImInfo.IsLoaded = rid.IsLoaded;
            bool LockedLayers;
            int ImCnt = rid.GetEntityCount(out LockedLayers);
            if (ImCnt.Equals(0)) ImInfo.IsReferenced = false;
            else {
                string FoundAt = MyUtility.WillLoad(ImInfo.ImagePath, db);
                if (!string.Compare(FoundAt, string.Empty).Equals(0))
                    ImInfo.ImageFoundAtPath = FoundAt;
                ImInfo.IsReferenced = true;
            }
            ObjectIdCollection ImLocIdCol = rid.GetPersistentReactorIds();
            string[] ImLocArray = new string[ ImLocIdCol.Count - 1 ];
            int j = 0;
            foreach ( ObjectId id in ImLocIdCol ) {
                DBObject dbo = Trans.GetObject( id, OpenMode.ForRead ) as DBObject;
                if ( dbo.GetRXClass().DxfName != "IMAGEDEF_REACTOR" ) continue;
                RasterImage Im = Trans.GetObject( dbo.OwnerId, OpenMode.ForRead ) as RasterImage;
                BlockTableRecord tempBtr = Trans.GetObject( Im.OwnerId, OpenMode.ForRead ) as BlockTableRecord;
                if ( tempBtr.IsLayout ) {
                    Layout tempLo = Trans.GetObject( tempBtr.LayoutId, OpenMode.ForRead ) as Layout;
                    ImLocArray[j] = "Layout: " + tempLo.LayoutName;
                }
                else ImLocArray[j] = "Block: " + tempBtr.Name;
                j++;
            }
            ImInfo.InsertedWhere = ImLocArray;
            ImInfoArray[i] = ImInfo;
            ++i;
        }
        return ImInfoArray;
    }
}
Code: [Select]
public class MyImageInformation {
    private string ImName;
    private string ImPath;
    private string ImFoundAt = string.Empty;
    private bool Loaded;
    private bool Embedded;
    private bool IsRefed;
    private string[] ImLoc;
   
    public MyImageInformation() {}
    public MyImageInformation (string ImName, string ImPath, bool Loaded) {}
    public string ImageName {
        get { return ImName; }
        set { ImName = value; }
    }
    public string ImagePath {
        get { return ImPath; }
        set { ImPath = value; }
    }
    public string ImageFoundAtPath {
        get { return ImFoundAt; }
        set { ImFoundAt = value;}
    }
    public bool IsLoaded {
        get { return Loaded; }
        set { Loaded = value; }
    }
    public bool IsEmbedded {
        get { return Embedded; }
        set { Embedded = value; }
    }
    public bool IsReferenced {
        get { return IsRefed; }
        set { IsRefed = value; }
    }
    public string[] InsertedWhere {
        get { return ImLoc; }
        set { ImLoc = value; }
    }
}
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Seth007

  • Mosquito
  • Posts: 5
Re: Images, and correct information
« Reply #7 on: December 03, 2010, 04:36:55 AM »
thanks m8, this really helped, those images are a hard nut to crack!  ;-)