Refreshing the UV editor during command execution

Say I want to implement a Python command which modifies UVs of the selected object and I would like to refresh the UV editor to show those modifications in the middle of command execution. Let’s assume the UV editor is already open.

I tried maya.cmds.refresh(force=True) but unfortunately it doesn’t work. I would be grateful for any hint of how one can do it.

[EDIT] Let’s assume the mesh construction history is off to simply things.

The usual method for updating panels, such as:

cmds.refresh(currentView = True, force = True)

will only update the panel canvas, but will not update changing UV components!
But you will need to use these commands to update the panel canvas when you open the UV Editor while the script is running.
The polyTexturePlacementPanel has its own refresh method, called through the textureWindow command flag of the same name.
Here’s a small demo:

import time
import maya.cmds as cmds
import maya.mel as mel

# create Poly Plane:
poly_plane = cmds.polyPlane(w = 5, h = 5, sx = 5, sy = 5, ax = (0, 1, 0), cuv =2, ch = 0)[0]

# open UV Editor:

# get UV Editor polyTexturePlacementPanel name:
uv_editor_panel_name = cmds.getPanel(scriptType = "polyTexturePlacementPanel")[0]

# Use usual method for updating panels canvas:
cmds.refresh(currentView = True, force = True)

# We will move all 36 UVs one by one (along the “V” axis), to a value = 0.025.
# After each move we will update the panel.
# For clarity of the demonstration, we will set a delay of 0.1 second after each iteration.
for i in range(36):
    cmds.polyMoveUV("{}.map[{}]".format(poly_plane, i), translateV = 0.025)
    cmds.textureWindow(uv_editor_panel_name, edit = True, refresh = True)

Command Help:
command (Python) textureWindow

command (Python) getPanel

1 Like

That works exactly as desired. Thank you so much!