What is baffleing me is in Kean's post (below) he added some "wrapper" code, which I didn't, yet mine worked. Anyone able to shed some light on this?
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.EditorInput
Namespace ImageTest
Public Class ImageCmds
' Must have UsePickSet specified
'"TEST")> _
Public Sub LoadImageProperties()
Dim db As New Database(False, True)
'This DWG file contains images attached from C:\My Documents
db.ReadDwgFile("c:\temp\testimage.dwg", IO.FileShare.ReadWrite, False, Nothing)
Dim tm As Autodesk.AutoCAD.DatabaseServices.TransactionManager = db.TransactionManager
Dim ta As Transaction = tm.StartTransaction
Dim rasterImageDef As RasterImageDef
Dim dictEntry As System.Collections.DictionaryEntry
Dim nod As DBDictionary
Dim imageDict As DBDictionary
nod = CType(tm.GetObject(db.NamedObjectsDictionaryId, OpenMode.ForRead, False), DBDictionary)
imageDict = CType(tm.GetObject(nod.GetAt("ACAD_IMAGE_DICT"), OpenMode.ForRead, False), DBDictionary)
Dim imagePath As String
For Each dictEntry In imageDict
Dim obj As DBObject
obj = tm.GetObject(CType(dictEntry.Value(), ObjectId), OpenMode.ForRead, False)
'the next is needed to get the raster image path
[color=red] If obj.GetRXClass.IsDerivedFrom(Autodesk.AutoCAD.Runtime.RXClass.GetClass(GetType(RasterImageDef))) Then
'create a RasterImageDef wrapper[/color]
rasterImageDef = CType(Autodesk.AutoCAD.Runtime.DisposableWrapper.Create(GetType(RasterImageDef), obj.UnmanagedObject, False), RasterImageDef)
imagePath = rasterImageDef.SourceFileName
MsgBox(imagePath)
'Strip off the filename, looking for the lask backslash, repath it to the temp folder
imagePath = "C:\temp\" + imagePath.Substring(imagePath.LastIndexOf(Chr(92)) + 1)
'Make sure the def object is open for write, then set the filename to the new location
rasterImageDef.UpgradeOpen()
rasterImageDef.SourceFileName = imagePath
imagePath = rasterImageDef.SourceFileName
'Just to double-check, let's get the filename and show it
MsgBox(imagePath)
End If
Next
ta.Commit()
ta.Dispose()
db.Dispose()
End Sub
End Class
End Namespace