[Python/Api] Setting the active viewport

Hey All,

I’m working on a Playblasting tool, but am encountering an issue when running the playblast command itself,

What I’m doing:

Cloning the active viewport-

self.tempViewport = pm.modelPanel(tearOffCopy=self.activeView)

Setting the focus to the new script generated viewport

pm.setFocus(self.tempViewport)

Executing the playblast (Playblast command dosent let you name the viewport to Playblast from - it just takes the “active” view … which i assumed was the one with focus, apparently not! )

Any ideas on how to set the active view, via API or another method?

Cheers!

~ Joe :slight_smile:

It is the ‘model editor’ inside the model panel that need to be activated, using the modelEditor command.

It is probably should be something like:

pm.modelEditor( self.tempViewport, e = True, activeView = True )

Sadly just been trying that again - Excuse Psuedocode

self.tempViewport = pm.modelPanel(tearOffCopy=self.activeView)
pm.evalDeferred(self.setFocus())

def setFocus(self):
      self.tempModelEditor = self.tempViewport.getModelEditor()

      print pm.modelEditor(self.tempModelEditor, query=True, activeView=True)
      [ This yeilds False ]

      pm.modelEditor(self.tempModelEditor, edit=True, activeView=True)

      print pm.modelEditor(self.tempModelEditor, query=True, activeView=True)
      [ This yeilds True ]

      pm.evalDeferred(self.createPlayBlast(),lowestPriority=True)

But Maya still gets the # RuntimeError: no active view for playblast # when running through… :frowning:

This code snippet seems to work for me. It appears that playblast() is intelligent enough to work on the active panel (not the model editor):


import maya.cmds as pm
 
 
print "Current panel to get playblasted is: " + pm.getPanel(withFocus=True)
 
tempPanel = pm.modelPanel(tearOff=True)
print "Tear off panel is: "+ tempPanel
 
print "Playblast currently focused on panel: "+ pm.playblast(activeEditor=True)
 
pm.setFocus(tempPanel)
 
print "Now playblast focused on panel: " +pm.playblast(activeEditor=True)
 
pm.evalDeferred("pm.playblast()")

Phil

Hey Phil!

It appears the difference to what ive tried and your sample is you’re doing

pm.evalDeferred(“pm.playblast()”)

I was evalDeferring the function that contained the PlayBlast command, rather than the playblast command itself.

After making a monster string containing all the flag arguments to pass into the PlayBlast command ive got it working as above as well :slight_smile:

Cheers!

~ Joe