.NET

.NET

Reply
Active Contributor
varadan01
Posts: 47
Registered: ‎03-16-2012
Message 1 of 2 (191 Views)

Reg: How to get the unreferenced image in dwg.

191 Views, 1 Replies
01-08-2013 07:06 AM

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

With Regards,
GVaradarajan
*Expert Elite*
_gile
Posts: 2,125
Registered: ‎04-29-2006
Message 2 of 2 (166 Views)

Re : Reg: How to get the unreferenced image in dwg.

01-08-2013 09:54 AM in reply to: varadan01

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
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.