Author Topic: Pulling raster reference "states"  (Read 1720 times)

0 Members and 1 Guest are viewing this topic.

slappy

  • Guest
Pulling raster reference "states"
« on: October 24, 2013, 05:40:41 PM »
I'm developing a tool that will pull the state of all Xrefs in a batch utility for output to a text file.  DWG references are simple, but I'm having trouble getting raster reference information.  I'll need PATH, UNLOADED, and RESOLVED.

I've gotten as far as pulling the raster information from the RasterImageDef and my extension RasterImage but none of that provides the Xref status.  I know that information is in the BlockTable, however I can't identify the raster reference.

Thoughts?

MexicanCustard

  • Swamp Rat
  • Posts: 705
Re: Pulling raster reference "states"
« Reply #1 on: October 25, 2013, 07:42:05 AM »
Can you post an example?  It's better if we can see how your going about getting the xref data.
Revit 2019, AMEP 2019 64bit Win 10

slappy

  • Guest
Re: Pulling raster reference "states"
« Reply #2 on: October 25, 2013, 01:40:11 PM »
There is a lot more, but most of it is just me testing different approaches.  Some of it is from another post and I've yet to implement it in a usable way.  All of it dirty.

Code: [Select]
    Dim db As Database = HostApplicationServices.WorkingDatabase
    Dim imageDicId As ObjectId = RasterImageDef.GetImageDictionary(db)
    If IsDBNull(imageDicId) = False Then
        Dim imagedic As DBDictionary = TryCast(tr.GetObject(imageDicId, OpenMode.ForRead), DBDictionary)
        Dim imageDicIDColl As New ObjectIdCollection
        imageDicIDColl = CType(GetDatabaseID(imagedic, imageDicIDColl), ObjectIdCollection)
        Dim btab As BlockTable = DirectCast(tr.GetObject(db.BlockTableId, OpenMode.ForRead), BlockTable)
        For Each btid As ObjectId In btab
            Dim btrec As BlockTableRecord = TryCast(tr.GetObject(btid, OpenMode.ForRead), BlockTableRecord)
        Next
        For Each id As ObjectId In imageDicIDColl
            Dim imageDef As RasterImageDef = TryCast(id.GetObject(OpenMode.ForRead), RasterImageDef)
            If imageDef Is Nothing Then
                Continue For
            End If
            Dim imageRecID As ObjectIdCollection = imageDef.GetPersistentReactorIds()
            For Each imageID As ObjectId In imageRecID
            Dim r As DBObject = TryCast(tr.GetObject(imageID, OpenMode.ForRead), DBObject)
            If r Is Nothing Then
                Continue For
            End If
            Dim ri As RasterImage = TryCast(tr.GetObject(r.OwnerId, OpenMode.ForWrite), RasterImage)
            If ri Is Nothing Then
                Continue For
            End If
        Next
     End if
GetDatabaseID function, originally used for a purging.
Code: [Select]
Public Shared Function GetDatabaseID(ByVal DBtable As Object, ByVal idsToPurge As ObjectIdCollection)
    Dim dicID As DBDictionaryEntry
    'process Database dictionarys only
    If TypeOf DBtable Is DBDictionary Then
        Dim DBdic As DBDictionary = TryCast(DBtable, DBDictionary)
        For Each dicID In DBdic
            Dim key As String = dicID.Key
           'Weed out keys that may cause trouble
            If (key <> "ByBlock") AndAlso (key <> "ByLayer") AndAlso (key <> "Global") Then
                If dicID.Value.IsValid Then
                'add to master list of items to purge
                    idsToPurge.Add(dicID.Value)
                End If
            End If
        Next
    Else
        'Process non-dictionary databases
        For Each OId As ObjectId In DBtable
           If OId.IsValid Then
           'add to master list of items to purge
                idsToPurge.Add(OId)
            End If
        Next
    End If
    Return idsToPurge
End Function

MexicanCustard

  • Swamp Rat
  • Posts: 705
Re: Pulling raster reference "states"
« Reply #3 on: October 28, 2013, 08:19:01 AM »
PATH = imageDef.SourceFileName

UNLOADED = imageDef.IsLoaded

RESOLVED = This one I'm not sure about. IsResolved is a property of the BlockTableRecord of a Xref without some experimenting I don't think Images have a BlockTableRecord. I thought that was what the RasterImageDef was used for.  I haven't tried it but could you use RasterImageDef.SearchForActivePath?  If it returns null then you're iamge is unresolved.

Revit 2019, AMEP 2019 64bit Win 10

kaefer

  • Guest
Re: Pulling raster reference "states"
« Reply #4 on: October 28, 2013, 08:36:50 AM »
PATH = imageDef.SourceFileName

UNLOADED = imageDef.IsLoaded

RESOLVED = This one I'm not sure about. IsResolved is a property of the BlockTableRecord of a Xref without some experimenting I don't think Images have a BlockTableRecord. I thought that was what the RasterImageDef was used for.  I haven't tried it but could you use RasterImageDef.SearchForActivePath?  If it returns null then you're iamge is unresolved.

Here's one such approach from yesteryear, which tries to locate the image in the search path. That may need to honour the IsEmbedded property.

slappy

  • Guest
Re: Pulling raster reference "states"
« Reply #5 on: October 28, 2013, 01:15:26 PM »
Excellent!

ImageDef.IsLoaded works in combination with .SourceFileName and .ActiveFileName, in place of IsResolved...  Don't know why I didn't see that before.

It's weird because I can't inspect RasterImageDef without crashing AutoCAD.  I found similar mention of this issue by others, so I'm glad it's not just me.

Thanks everyone for all the help!