.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

autocad overwrite raster image file while host drawing is open

6 REPLIES 6
Reply
Message 1 of 7
mnav
772 Views, 6 Replies

autocad overwrite raster image file while host drawing is open

Hi

 i am trying to overwrite the raster image file to an updated version of same file. when i try to copy file it says file is in use by another process IOException.

i can change the path to new loaction and reload image but cant overwite the file at same location.

 

is there any way to overwite the raster image file while the host drawing is open.

 

i am using c# and autocad 2010

 

thanks

Nav

6 REPLIES 6
Message 2 of 7
Hallex
in reply to: mnav

Have a look at this article:

 

http://adndevblog.typepad.com/autocad/2012/07/getset-image-paths-in-drawing-using-net-api.html

 

~'J'~

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Message 3 of 7
mnav
in reply to: Hallex

thanks for your reply.

 

i can change the location of  image file without any problem. Error IoException comes if i try to overwite the image file which already in used in open drawing.

 

i am looking for a way to overwite image file like we can do in drawing Xrefs we can change the source file even though its open in drawing. Autocad just pop a message that an updated version of xref is avialable. but in raster image case its not allowing to update file.

 

thanks

Message 4 of 7
Hallex
in reply to: mnav

If you see new image as available, try add this code block

to know if it's non-unreferenced:

 

        RasterImage.EnableReactors(true);

 

        myraster.AssociateRasterDef(imageId);

 

       tr.commit();

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Message 5 of 7
mnav
in reply to: Hallex

thanks i will give it a go. but problem comes before setting any flags when overwiting file.

Message 6 of 7
mnav
in reply to: mnav

 

for eample if Rasterimage location is C:\MyFiles\image1.bmp and if i download the image1.bmp again on same location i got IOException saying file is already in use. file access error.

 

i am downloading the file programatically on update image button.

if file dont exist already my code works fine download the file and load it into the drawing. problem comes if file alredy exist and refrenced into drawing.

 

hope this will explain little bit more.

Message 7 of 7
Hallex
in reply to: mnav

See if this code is working for you, tested on A2010 especially

 

       //  original code:
        //  http://adndevblog.typepad.com/autocad/2012/07/getset-image-paths-in-drawing-using-net-api.html
        [CommandMethod("imagePath")]

        public void EditImagePath()
        {
            Database db = HostApplicationServices.WorkingDatabase;

            Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;

            PromptEntityOptions peo = new PromptEntityOptions("\nSelect an Image");

            peo.SetRejectMessage("\nSelected entity must be an image.");

            peo.AddAllowedClass(typeof(RasterImage), false);

            PromptEntityResult per = ed.GetEntity(peo);

            if (per.Status != PromptStatus.OK)

                return;

            ObjectId imageId = per.ObjectId;

            try
            {

                using (Transaction trans = db.TransactionManager.StartTransaction())
                {

                    RasterImage myImage = trans.GetObject(imageId, OpenMode.ForRead) as RasterImage;

                    RasterImageDef imageDef = trans.GetObject(myImage.ImageDefId, OpenMode.ForWrite) as RasterImageDef;

                    ed.WriteMessage(imageDef.ActiveFileName);

                    imageDef.SourceFileName = @"C:\Test\jela.bmp";

                    imageDef.ActiveFileName = @"C:\Test\jela.bmp";
                   
                    myImage.UpgradeOpen();
                   
                    myImage.Name = "jela";
                    
                    //imageDef.LocateActivePath();// optional, has no affect in this context

                    imageDef.Load();

                    RasterImage.EnableReactors(true);

                    myImage.AssociateRasterDef(imageDef);
                   
                    trans.Commit();
                   
                }

            }

            catch (System.Exception ex)
            {

                ed.WriteMessage(ex.Message);

            }

        }

 

~'J'~

_____________________________________
C6309D9E0751D165D0934D0621DFF27919

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost