.NET

.NET

Reply
Distinguished Contributor
VB_Autocad_guy
Posts: 136
Registered: ‎07-24-2009
Message 1 of 5 (321 Views)
Accepted Solution

Iterate Through Raster Images/Image Dictionary

321 Views, 4 Replies
02-28-2012 11:44 AM

Here's the Code I have so far: 

 

I want to iterate through the Image Dictionary and Connect into the Raster ImageDef Properties. 

I want to be able to modify and fix missing Raster Images. 

 

Can someone help me get this code sorted out. 

 

For Each myObjID As ObjectId In myModelSpace
                Dim myEnt As Entity = myObjID.GetObject(OpenMode.ForRead)

 

If TypeOf myEnt Is Image Then
                        Dim myRasterImg As RasterImage
                        Dim myRasterImgDef As RasterImageDef

                        'Open The Dictionary 
                        Dim ImgDict As ObjectId = RasterImageDef.GetImageDictionary(DatabaseIn)

                        For Each dictEntry In ImgDict


                        Next



End If

 

assuming transaction "avctivetx" is started

For Each dicentry As DBDictionaryEntry In imageDict
            Dim rasterimgDef As RasterImageDef = CType(activetx.GetObject(CType(dicentry.Value, ObjectId), OpenMode.ForRead), RasterImageDef)
            msg = msg & rasterimgDef.ActiveFileName & vbCrLf
        Next 

Never mind... 

Found it 

 ElseIf TypeOf myEnt Is Image Then
'Database Image Attachment
Dim myExtImage As New extractRasterImage
Dim myRasterImage As RasterImage = CType(myTrans.GetObject(myEnt.ObjectId, OpenMode.ForRead), RasterImage)
Dim myRasterImageDef As RasterImageDef = CType(myTrans.GetObject(myRasterImage.ImageDefId, OpenMode.ForRead), RasterImageDef)
myExtImage.Path = myRasterImage.Path
myExtImage.ActiveFullFileName = myRasterImageDef.ActiveFileName
MsgBox(myRasterImage.Path & myRasterImageDef.ActiveFileName)
myExtractedDB.RasterImages.Add(myExtImage)

 

Valued Mentor
fieldguy
Posts: 382
Registered: ‎03-31-2005
Message 2 of 5 (316 Views)

Re: Iterate Through Raster Images/Image Dictionary

02-28-2012 12:21 PM in reply to: VB_Autocad_guy

assuming transaction "avctivetx" is started

For Each dicentry As DBDictionaryEntry In imageDict
            Dim rasterimgDef As RasterImageDef = CType(activetx.GetObject(CType(dicentry.Value, ObjectId), OpenMode.ForRead), RasterImageDef)
            msg = msg & rasterimgDef.ActiveFileName & vbCrLf
        Next 

Distinguished Contributor
VB_Autocad_guy
Posts: 136
Registered: ‎07-24-2009
Message 3 of 5 (306 Views)

Re: Iterate Through Raster Images/Image Dictionary

02-28-2012 01:31 PM in reply to: fieldguy

How would I get the RasterImageDef and it's attached properties? 

 

ElseIf TypeOf myEnt Is Image Then

                    Dim myExtImage As New extractRasterImage

                    Dim myRasterImage As RasterImage = CType(myTrans.GetObject(myEnt.ObjectId, OpenMode.ForRead), RasterImage)
                    MsgBox(myRasterImage.Path)

                    myExtImage.Path = myRasterImage.Path

                    myExtractedDB.RasterImages.Add(myExtImage)

 

Distinguished Contributor
VB_Autocad_guy
Posts: 136
Registered: ‎07-24-2009
Message 4 of 5 (302 Views)

Re: Iterate Through Raster Images/Image Dictionary

02-28-2012 01:36 PM in reply to: VB_Autocad_guy

If anyone's wondering this is how I got it to work. 

 

   'Start(Transaction)
        Using myTrans As Transaction = DatabaseIn.TransactionManager.StartTransaction

            'Take a Look at Attachments
            'Open The Dictionary 
            Dim nod As DBDictionary
            Dim imageDict As DBDictionary

            nod = CType(myTrans.GetObject(DatabaseIn.NamedObjectsDictionaryId, OpenMode.ForRead, False), DBDictionary)
            imageDict = CType(myTrans.GetObject(nod.GetAt("ACAD_IMAGE_DICT"), OpenMode.ForRead, False), DBDictionary)

            Dim msg As String = ""
            For Each dicentry As DBDictionaryEntry In imageDict
                Dim myRasterImgDef As RasterImageDef = CType(myTrans.GetObject(CType(dicentry.Value, ObjectId), OpenMode.ForRead), RasterImageDef)


                msg = (msg & myRasterImgDef.ActiveFileName & vbTab & myRasterImgDef.FileType & vbCr & _
                            vbTab & myRasterImgDef.SourceFileName & vbCrLf)
            Next
            MsgBox(msg)

 

Distinguished Contributor
VB_Autocad_guy
Posts: 136
Registered: ‎07-24-2009
Message 5 of 5 (300 Views)

Re: Iterate Through Raster Images/Image Dictionary

02-28-2012 01:46 PM in reply to: VB_Autocad_guy

Never mind... 

Found it 

  ElseIf TypeOf myEnt Is Image Then
                    'Database Image Attachment

                    Dim myExtImage As New extractRasterImage
                    Dim myRasterImage As RasterImage = CType(myTrans.GetObject(myEnt.ObjectId, OpenMode.ForRead), RasterImage)
                    Dim myRasterImageDef As RasterImageDef = CType(myTrans.GetObject(myRasterImage.ImageDefId, OpenMode.ForRead), RasterImageDef)

                 
                    myExtImage.Path = myRasterImage.Path
                    myExtImage.ActiveFullFileName = myRasterImageDef.ActiveFileName
                    MsgBox(myRasterImage.Path & myRasterImageDef.ActiveFileName)

                    myExtractedDB.RasterImages.Add(myExtImage)

 

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.