To Get and set Image file name use the properties SourceFileName and ActiveFileName of RasterImageDef.
Here is a sample code that changes the image file path of a raster image.
To try the below code add a raster image from UI, load the .Net dll and
issue the command editImage.
Note:
Change the file name specified (for functions SourceFileName and ActiveFileName )in the below code
to some valid file name.
[CommandMethod("editImagePath")]
public void EditImagePath()
{
Database db = HostApplicationServices.WorkingDatabase;
Editor ed = 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:\Temp\Bruno.jpg";
imageDef.ActiveFileName = "C:\Temp\Bruno.jpg";
imageDef.Load();
trans.Commit();
}
}
catch (System.Exception ex)
{
ed.WriteMessage(ex.Message);
}
}

Leave a Reply