Select to view content in your preferred language

How do you programatically refresh the Catalog Window in ArcMap

2331
6
Jump to solution
10-06-2013 09:58 AM
DuncanHornby
MVP Notable Contributor
All,

I'm stumpted on how one refreshes the Catalog window in ArcMap and I have been unsuccessful in finding any advice or examples in the ArcObjects API help. I am using 10.2 and currently trying to put this simple bit of code together in VBA but ultimately I intend do it in VB .net.

I am developing a tool that at some point blitzes a folder but I notice if the catalog window is open and docked in ArcMap this does not automatically get refreshed. So I'm simply trying to refresh the catalog tree in the catalog window which would hopefully show that a folder had been deleted.

Currently my VBA test code is:

Public Sub test()     Dim pDockableWindowManager As IDockableWindowManager     Set pDockableWindowManager = Application     Dim sUID As UID     Set sUID = New UID     sUID.Value = "{7F09BEFF-4F85-48A2-A3DC-39430262799E}" 'GxBrowserDockWindow     Dim pDockableWindow As IDockableWindow     Set pDockableWindow = pDockableWindowManager.GetDockableWindow(sUID)     Debug.Print pDockableWindow.Caption ' This returns "Catalog" so I know I have a handle on it     If pDockableWindow.IsVisible Then          ' ??? How to refresh it it?     End If End Sub
0 Kudos
1 Solution

Accepted Solutions
RichardFairhurst
MVP Alum
There is a coClass for the IDockableWindowDef called GxBrowserDockWindow which appears to be equivalent to the Desktop Catalog window (at least it is the closest thing I have found so far).  Perhaps once you can get a handle for that browser to one of the IGx interfaces you would manipulate that browser window like you would the ArcCatalog application.  Admittedly, there is nothing to make tracing this out easy, so it is all trial and (mostly) error as usual with ArcObjects less used functions.

View solution in original post

0 Kudos
6 Replies
RichardFairhurst
MVP Alum
You want to access the IContentsView.Refresh method.  It also has a shortcut through the IMxDocument.UpdateContents method, since most applications implement the IMxDocument interface as one of the first steps of drilling into the map.  Look at the Loading a Table example on this help page for one way to implement the refresh.  Same principle applies to removing a layer or table from the map.  You can examine the state of the current Table of Contents view through the IMxDocument.CurrentContentsView method.
0 Kudos
DuncanHornby
MVP Notable Contributor
Richard,

Many thanks for your help but I think we are talking about different things?

I'm talking about this window:

[ATTACH=CONFIG]28077[/ATTACH]

If run the following code:

Public Sub test()
    Dim pMXDoc As IMxDocument
    Set pMXDoc = ThisDocument
    Dim n As Integer
    n = pMXDoc.ContentsViewCount
    Dim pContentsView  As IContentsView
    For i = 0 To n - 1
        Set pContentsView = pMXDoc.ContentsView(i)
        Debug.Print pContentsView.Name
    Next i
End Sub


It displays only the following names (so no catalog window):

Display
Source
Visible
Selection
0 Kudos
RichardFairhurst
MVP Alum
Richard,

Many thanks for your help but I think we are talking about different things?

I'm talking about this window:

[ATTACH=CONFIG]28077[/ATTACH]

If run the following code:

Public Sub test()
    Dim pMXDoc As IMxDocument
    Set pMXDoc = ThisDocument
    Dim n As Integer
    n = pMXDoc.ContentsViewCount
    Dim pContentsView  As IContentsView
    For i = 0 To n - 1
        Set pContentsView = pMXDoc.ContentsView(i)
        Debug.Print pContentsView.Name
    Next i
End Sub


It displays only the following names (so no catalog window):

Display
Source
Visible
Selection


Source, Display, Visible or Selection are different current view states of the Table of Contents window.  This is the correct interface for what you want.  Refresh will refresh it after you modify the contents of the window.
0 Kudos
RichardFairhurst
MVP Alum
Richard,

Many thanks for your help but I think we are talking about different things?

I'm talking about this window:

[ATTACH=CONFIG]28077[/ATTACH]

If run the following code:

Public Sub test()
    Dim pMXDoc As IMxDocument
    Set pMXDoc = ThisDocument
    Dim n As Integer
    n = pMXDoc.ContentsViewCount
    Dim pContentsView  As IContentsView
    For i = 0 To n - 1
        Set pContentsView = pMXDoc.ContentsView(i)
        Debug.Print pContentsView.Name
    Next i
End Sub


It displays only the following names (so no catalog window):

Display
Source
Visible
Selection


OK.  It thought you meant the TOC.  I'll look for the Catalog Window Interface.

I would begin by trying the IGx interfaces.  They may perform the same actions in the Map Document Catalog tab as they do in the Catalog Application.
0 Kudos
RichardFairhurst
MVP Alum
There is a coClass for the IDockableWindowDef called GxBrowserDockWindow which appears to be equivalent to the Desktop Catalog window (at least it is the closest thing I have found so far).  Perhaps once you can get a handle for that browser to one of the IGx interfaces you would manipulate that browser window like you would the ArcCatalog application.  Admittedly, there is nothing to make tracing this out easy, so it is all trial and (mostly) error as usual with ArcObjects less used functions.
0 Kudos
DuncanHornby
MVP Notable Contributor
Richard,

You get the tick as you got me "bumbling" around the part of ArcObjects I needed to be looking at. If anyone from ESRI is reading this then you really need to add some guidance to the Help about what exactly is "UserData" on the IDockableWindow Interface. There is no indication of what this returns, a simple example of the types of objects returned would help us developers.

So... after several hours of banging my head against a brick wall I finally worked out what exactly is returned by "UserData". I was then able to hook into the catalog and refresh the docked window. I supply my VBA code below in the hope that this will save other developers from going crazy but ideally the Help page should be updated with some trivial scenarios to allow the developer to understand what Userdata is.

Public Sub test()
    Dim pDockableWindowManager As IDockableWindowManager
    Set pDockableWindowManager = Application
    
    Dim sUID As UID
    Set sUID = New UID
    sUID.Value = "{7F09BEFF-4F85-48A2-A3DC-39430262799E}" 'GxBrowserDockWindow
    
    Dim pDockableWindow As IDockableWindow
    Set pDockableWindow = pDockableWindowManager.GetDockableWindow(sUID)
    
    If pDockableWindow.IsVisible Then
        ' Get Browser
        Dim pGXBrowser As IGxBrowser
         Set pGXBrowser = pDockableWindow.UserData
        
        ' Get the Catalog
        Dim pGXCatalog As IGxCatalog
         Set pGXCatalog = pGXBrowser.InternalCatalog

        ' QI Catalog into GXObject
        Dim pGXObject As IGxObject
         Set pGXObject = pGXCatalog
         
         ' QI GxObject into GxObjectContainer
        Dim pGxObjectContainer As IGxObjectContainer
         Set pGxObjectContainer = pGXObject
         
         ' Get Gxobjects as an enumerate
        Dim pEnumGxObject As IEnumGxObject
         Set pEnumGxObject = pGxObjectContainer.Children
         
         ' Cycle through objects until we find the Folder Connections, then break out of loop
        Dim pGxObject2 As IGxObject
         Set pGxObject2 = pEnumGxObject.Next
         Do While Not pGxObject2 Is Nothing
            If TypeOf pGxObject2 Is IGxFolderConnections Then
               Exit Do
            End If
            Set pGxObject2 = pEnumGxObject.Next
         Loop
         
         ' Re-point GxObjectContainer to folder connection GxObject and refresh all children GxObjects
        Set pGxObjectContainer = pGxObject2
         Set pEnumGxObject = pGxObjectContainer.Children
         Set pGxObject2 = pEnumGxObject.Next
         Do While Not pGxObject2 Is Nothing
            pGxObject2.Refresh
            Set pGxObject2 = pEnumGxObject.Next
         Loop
    End If
End Sub
0 Kudos