.NET

Reply
Valued Contributor
RamanSBV
Posts: 88
Registered: ‎02-28-2012
Message 1 of 3 (166 Views)
Accepted Solution

Getting the Attach Images file details

166 Views, 2 Replies
08-27-2012 03:12 AM

Hi,

 

 

Please guide me

 

For retrieving information about attach DWG file there is a API call "db.GetHostDwgXrefGraph(true)"

 

Similarly is there any API call for Attach Image files

 

Regards,

Raman

 

 

 

Here is a code I've found in my code library,

change it to your needs:

 

 [CommandMethod("ImageName")]
public void GetImageFileName()
{
Document doc=Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed= doc.Editor;
ErrorStatus es = new ErrorStatus();
try
{
using (Transaction tr = db.TransactionManager.StartTransaction())
{
ObjectId imageDictId = RasterImageDef.GetImageDictionary(db);
DBDictionary imageDict = tr.GetObject(imageDictId, OpenMode.ForRead) as DBDictionary;
ObjectId rasterId = ed.GetEntity("\nSelect an image: ").ObjectId;
RasterImage image = tr.GetObject(rasterId, OpenMode.ForRead) as RasterImage;
ObjectId imageDefId = imageDict.GetAt(image.Name);
RasterImageDef imageDef = tr.GetObject(imageDefId, OpenMode.ForWrite) as RasterImageDef;
string filename = imageDef.ActiveFileName;
Application.ShowAlertDialog(filename);
tr.Commit();
}
}
catch (Autodesk.AutoCAD.Runtime.Exception ex)
{
Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage
(ex.Message + "\n" + ex.StackTrace);
}
finally
{
ed.WriteMessage("\n{0}", es.ToString());
}
}

 

~'J'~

ADN Support Specialist
philippe.leefsma
Posts: 658
Registered: ‎06-02-2009
Message 2 of 3 (145 Views)

Re: Getting the Attach Images file details

08-28-2012 01:33 AM in reply to: RamanSBV

Hi There,

 

You can use the static API "RasterImageDef.GetImageDictionary".

 

This will return the id of the RasterImage dictionary. Iterating through its record will give you access to the "RasterImageDef" objects.

 

Regards,

Philippe.



Philippe Leefsma
Developer Technical Services
Autodesk Developer Network

*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 3 of 3 (139 Views)

Re: Getting the Attach Images file details

08-28-2012 04:58 AM in reply to: RamanSBV

Here is a code I've found in my code library,

change it to your needs:

 

        [CommandMethod("ImageName")]

        public void GetImageFileName()
        {
            Document doc=Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            Editor ed= doc.Editor;
            ErrorStatus es = new ErrorStatus();
              try
                {
                    using (Transaction tr = db.TransactionManager.StartTransaction())
                    {

                        ObjectId imageDictId = RasterImageDef.GetImageDictionary(db);
                        DBDictionary imageDict = tr.GetObject(imageDictId, OpenMode.ForRead) as DBDictionary;
                        ObjectId rasterId = ed.GetEntity("\nSelect an image: ").ObjectId;
                        RasterImage image = tr.GetObject(rasterId, OpenMode.ForRead) as RasterImage;
                        ObjectId imageDefId = imageDict.GetAt(image.Name);
                        RasterImageDef imageDef = tr.GetObject(imageDefId, OpenMode.ForWrite) as RasterImageDef;
                        string filename = imageDef.ActiveFileName;
                        Application.ShowAlertDialog(filename);

                        tr.Commit();

                    }
               }
            
            catch (Autodesk.AutoCAD.Runtime.Exception ex)
            {
                Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage
                    (ex.Message + "\n" + ex.StackTrace);
            }
            finally
            {
                ed.WriteMessage("\n{0}", es.ToString());
            }
        }

 

~'J'~

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are You Going To Be @ AU 2014? Feel free to drop by our AU topic post and share your plans, plug a class that you're teaching, or simply check out who else from the community might be in attendance. Ohh and don't forgot to stop by the Autodesk Help | Learn | Collaborate booths in the Exhibit Hall and meet our community team if you get a chance!