.NET

.NET

Reply
Valued Contributor
88 Posts
0 Kudos
Registered: ‎02-28-2012
Post 1 of 6

How to retrieve the Status of attached Image file

584 Views, 5 Replies
08-30-2012 12:58 AM

Hi,

 

Please guide me on

 

How to retrieve the Status of attached Image file

 

Regards,

Raman

Mentor
166 Posts
9 Kudos
Registered: ‎06-16-2008
Post 2 of 6

Re: How to retrieve the Status of attached Image file

08-30-2012 06:41 PM in reply to: RamanSBV

A google search netted many results.

 

This may be more than what you need, but should be a good starting point.

 

http://through-the-interface.typepad.com/through_the_interface/2010/08/attaching-an-upright-raster-i...

Valued Contributor
88 Posts
0 Kudos
Registered: ‎02-28-2012
Post 3 of 6

Re: How to retrieve the Status of attached Image file

09-10-2012 11:45 PM in reply to: BrentBurgess1980

Hi,

 

Is any property to know the status(file is available / file not found ) of the file(dwg/dng/png/image) which is attached to dwg file.

 

Regards,

Raman

*Expert Elite*
1,569 Posts
171 Kudos
Registered: ‎10-08-2008
Post 4 of 6

Re: How to retrieve the Status of attached Image file

09-13-2012 04:32 AM in reply to: RamanSBV

Try this code

        [CommandMethod("imgp", CommandFlags.Modal)]
        public void SelectRasterImage()
        {
            Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            Editor ed = doc.Editor;

            Point3dCollection pts = new Point3dCollection();

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                ObjectId id = ed.GetEntity("\nSelect an image: ").ObjectId;
                DBObject obj = tr.GetObject(id, OpenMode.ForRead);

                if (obj.GetRXClass().DxfName == "IMAGE")
                {
                    RasterImage image = obj as RasterImage;
                    string imageName = image.Name;
                    Point3d pt = image.Position;

                    pts = image.GetVertices();

                    ObjectId imageDictId = RasterImageDef.GetImageDictionary(db);
                    DBDictionary imageDict = (DBDictionary)tr.GetObject(imageDictId, OpenMode.ForRead, false);
                    ObjectId imageDefId = imageDict.GetAt(imageName);
                    RasterImageDef imageDef = (RasterImageDef)tr.GetObject(imageDefId, OpenMode.ForRead, false);

                    try
                    {
                        StringBuilder sb = new StringBuilder();
                        sb.AppendLine("Image Name =" + imageName);
                        sb.AppendLine(string.Format("Position = {0:f3}", pt));
                        sb.AppendLine("Height = " + (Math.Abs(pts[0].Y - pts[1].Y)).ToString());
                        sb.AppendLine("Width = " + (Math.Abs(pts[0].X - pts[2].X)).ToString());
                        string filename = imageDef.ActiveFileName;
                        sb.AppendLine("ActiveFileName =" + filename);
                        string sourcename = imageDef.SourceFileName;
                        sb.AppendLine("SourceFileName =" + sourcename);
                        Vector2d vec = imageDef.Size;
                        sb.AppendLine("Size =" + vec.ToString());
                        Autodesk.AutoCAD.GraphicsInterface.ImageSource imageSource = (Autodesk.AutoCAD.GraphicsInterface.ImageSource)imageDef.Organization;
                        bool embedded = imageDef.IsEmbedded;
                        sb.AppendLine("Embedded =" + embedded.ToString());
                        bool loaded = imageDef.IsLoaded;
                        sb.AppendLine("Loaded =" + loaded.ToString());
                        string ftype = imageDef.FileType;
                        sb.AppendLine("FileType =" + ftype);
                        bool autodel = imageDef.AutoDelete;
                        sb.AppendLine("AutoDelete =" + autodel.ToString());
                        AnnotativeStates anno = imageDef.Annotative;
                        string annostr = anno.ToString();
                        sb.AppendLine("Annotative =" + annostr);
                        MessageBox.Show(sb.ToString());
                    }
                    catch (Autodesk.AutoCAD.Runtime.Exception ex)
                    {
                        MessageBox.Show(ex.Message + "\n" + ex.StackTrace);
                    }
                    finally
                    {

                    }
                }

            }
        }

 

~'J'~

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Valued Contributor
88 Posts
0 Kudos
Registered: ‎02-28-2012
Post 5 of 6

Re: How to retrieve the Status of attached Image file

09-13-2012 10:14 PM in reply to: Hallex

Hi,

 

Thanks for your post.

 

I am able to get status of the image file with bellow line of code

 

bool loaded = imageDef.IsLoaded;

 

Now i am googling for DWF/DGN/PDF files

 

Regards,

Raman

*Expert Elite*
1,569 Posts
171 Kudos
Registered: ‎10-08-2008
Post 6 of 6

Re: How to retrieve the Status of attached Image file

09-14-2012 12:28 AM in reply to: RamanSBV

Good for you

Cheers :smileyhappy:

 

~'J'~

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are you interested in helping shape the future of the Autodesk Community? To participate in this brief usability study, please click here. Your time and input is greatly appreciated!