Reg: How to get the unreferenced image in dwg.

Reg: How to get the unreferenced image in dwg.

Anonymous
Not applicable
968 Views
1 Reply
Message 1 of 2

Reg: How to get the unreferenced image in dwg.

Anonymous
Not applicable

How to get the unreferenced image in dwg?using DB.ReadDWGFile Method .Do any one have sample ?? Smiley Indifferent

0 Likes
969 Views
1 Reply
Reply (1)
Message 2 of 2

_gile
Consultant
Consultant

Hi,

 

You can get the Raster definitions from the ACAD_IMAGE_DICT dictionary and use the Database.Purge() method to get the unreferenced ones.

 

Here's a little sample:

 

        [CommandMethod("Test")]
        public void Test()
        {
            Document doc = AcAp.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            Editor ed = doc.Editor;

            using (Database sideDb = new Database())
            {
                sideDb.ReadDwgFile(@"C:\Temp\ImagesTest.dwg", System.IO.FileShare.ReadWrite, false, "");
                using (Transaction tr = sideDb.TransactionManager.StartTransaction())
                {
                    DBDictionary NOD =
                        (DBDictionary)tr.GetObject(sideDb.NamedObjectsDictionaryId, OpenMode.ForRead);
                    if (NOD.Contains("ACAD_IMAGE_DICT"))
                    {
                        DBDictionary imgDict =
                            (DBDictionary)tr.GetObject((ObjectId)NOD["ACAD_IMAGE_DICT"], OpenMode.ForRead);
                        ObjectIdCollection ids = new ObjectIdCollection();
                        foreach (DBDictionaryEntry entry in imgDict)
                        {
                            ids.Add(entry.Value);
                        }
                        sideDb.Purge(ids);
                        foreach (DBDictionaryEntry entry in imgDict)
                        {
                            if (ids.Contains(entry.Value))
                                ed.WriteMessage("\n" + entry.Key);
                        }
                    }
                    tr.Commit();
                }
            }
        }

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub