.NET
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
autocad overwrite raster image file while host drawing is open
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
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
Re: autocad overwrite raster image file while host drawing is open
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Have a look at this article:
http://adndevblog.typepad.com/autocad/2012/07/gets
~'J'~
C6309D9E0751D165D0934D0621DFF27919
Re: autocad overwrite raster image file while host drawing is open
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
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
Re: autocad overwrite raster image file while host drawing is open
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
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
Re: autocad overwrite raster image file while host drawing is open
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
thanks i will give it a go. but problem comes before setting any flags when overwiting file.
Re: autocad overwrite raster image file while host drawing is open
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
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.
Re: autocad overwrite raster image file while host drawing is open
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
See if this code is working for you, tested on A2010 especially
// original code:
// http://adndevblog.typepad.com/autocad/2012/07/gets et-image-paths-in-drawing-using-net-api.html
[CommandMethod("imagePath")]
public void EditImagePath()
{
Database db = HostApplicationServices.WorkingDatabase;
Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.D ocumentManager.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

