RasterImageDef - Exception thrown on trying to update .SourceFileName

RasterImageDef - Exception thrown on trying to update .SourceFileName

dawsonb
Contributor Contributor
667 Views
2 Replies
Message 1 of 3

RasterImageDef - Exception thrown on trying to update .SourceFileName

dawsonb
Contributor
Contributor

I'm trying to update the .SourceFileName of the RasterImageDef object I have but when I try an exception is thrown by AutoCAD which is:

 

eFileAccessErr - 'Autodesk.AutoCAD.Runtime.Exception' occurred in AcdbMgd.dll but was not handled in user code

 

The code is below, any suggestions to stop the exception - Currently working with A2015 but installing A2017 to test as well.

 

using (Transaction transaction = database.TransactionManager.StartTransaction())
            {
                ObjectId imageDictionaryId = RasterImageDef.GetImageDictionary(database);
                if (!imageDictionaryId.IsNull)
                {
                    DBDictionary dBDictionary = transaction.GetObject(imageDictionaryId, OpenMode.ForRead) as DBDictionary;
                    foreach (DBDictionaryEntry entry in dBDictionary)
                    {
                        RasterImageDef rasterImageDef = transaction.GetObject(entry.Value, OpenMode.ForWrite) as RasterImageDef;
                        if (rasterImageDef != null)
                        {
                            // rasterImageDef.UpgradeOpen();
                            rasterImageDef.SourceFileName = "dawson.tif";
                        }
                    }
                    transaction.Commit();
                }
            }
0 Likes
Accepted solutions (2)
668 Views
2 Replies
Replies (2)
Message 2 of 3

norman.yuan
Mentor
Mentor
Accepted solution

Have you tried to specify the image file with fully pathed file name instead of file name without path?

 

I'd even go further to test if the image file's existence before setting "SourceFileName" property:

 

If (File.Exists(@"C:\....\TheImage.tif"))

{

  rasterDef.SourceFileName=@"C:\...\TheImage.tif";

}

else

{

   //Do something if necessary. such as prompting user, raising exception...

}

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 3 of 3

dawsonb
Contributor
Contributor
Accepted solution

 

Thanks, the image file does have to be present in the folder otherwise the exception is thrown.

 

 

0 Likes