Iterate all existing panels and update image planes

I have a couple of tear off panels in which my tool create an image plane towards some of the camera.

However, these image planes have the Display set to ‘looking through camera’.
While the specified camera is correct, in one or more of the tear off panels or the main viewport, the created image plane are not displayed with the image files in these panels unless I either hover my mouse cursor to do a zoom/pan, or if I re-tear off the panels or I set an active focus onto one of the panel and hit ‘F’ on the keyboard to frame all.

Even so, is there a command (cmds/ mel) that will allows me to iterate all panels/viewports and refresh them so that the created image plane (with images of course) will be displayed with image?

I tried the following:

viewports = cmds.getPanel( all = True)

for view in viewports:
    if 'modelPanel' in view:
        cmds.modelEditor( view, edit = True)
        mel.eval('fitAllPanels all')

But I keep getting an error - There is no active view

I might be oversimplifying this, but have you tried cmds.refresh() ?
Which according to the docs redraws all views.

Yes I did, even with the use of force argument, but it does not seems to do anything.

Hi @xenas,

Either set each camera for each model panel to fit all objects or use the mel command - don’t do both.

import maya.cmds as cmds

cameras = []

for pane in cmds.getPanel(type="modelPanel"):

    camera = cmds.modelPanel(pane, q=True, camera=True)
    #  Edit - only call fit on new cameras.

    if camera not in cameras:
         cmds.viewFit(camera, allObjects=True)


import maya.mel as mel

mel.eval('fitAllPanels all')