Refresh the Shotgun Panel programmatically

Hi All,

After changing the task status programmatically on publish, we need to refresh the Shotgun Panel in Maya to display the correct status.

There is a drop-down menu item named “Refresh” which does the job. What is the best option to activate this action?

Maybe, find this QMenu and execute the QAction?

Any hints are welcome.

Thanks.

Regards,
Andriy

Here’s my working solution. Maybe there’s a more elegant way to do this?

from PySide2.QtWidgets import QApplication

def refresh_shotgunpanel():
    for widget in QApplication.allWidgets():
        if widget.objectName() != "panel_tk_multi_shotgunpanel_main":
            continue
        for child in widget.children():
            if "ActionManager" not in type(child).__name__:
                continue
            break
        else:
            print("ActionManager not found")
            break
        child.refresh_request.emit()
        print("Panel refreshed")
        return
    else:
        print("Panel not found")

refresh_shotgunpanel()

Cheers,
Andriy Babak

1 Like

Hi @ababak, thanks for sharing your solution.

I have a suggestion that might be easier. I tested it and it appears to work.

You need to get hold of the app object and call the navigate() method.

import sgtk
# get the current engine instance
engine = sgtk.platform.current_engine()

panel_app = engine.apps["tk-multi-shotgunpanel"]
# use the app's navigate method to trigger a refresh.
panel_app.navigate("Project", engine.context.project["id"], panel_app.PANEL)

In the example above, I’m in a project context, so I’m just refreshing the project. But if you are in a task context then you would pass "Task", engine.context.task["id"], ..., so that it navigates to the exact same context, but triggers a refresh.
Hope that helps?

2 Likes

Hi Philip,

Thanks for sharing. I am glad there is such a simple solution available. It works like a charm!

Cheers,
Andriy

1 Like

Is there an equivalent for other apps, like the multi-loader? It doesn’t have a navigate function

You can use python to inspect the loader and it’s exposed functions, something like this:

from pprint import pprint
import sgtk
# get the current engine instance
engine = sgtk.platform.current_engine()

app = engine.apps["tk-multi-loader2"]
pprint(dir(app))

This will print all the apps functions and properties

1 Like