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
Have a look at this article:
http://adndevblog.typepad.com/autocad/2012/07/getset-image-paths-in-drawing-using-net-api.html
~'J'~
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
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();
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.
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'~
Can't find what you're looking for? Ask the community or share your knowledge.