Python maya.cmds.playblast() Examples

The following are 16 code examples of maya.cmds.playblast(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module maya.cmds , or try the search function .
Example #1
Source File: maya_warpper.py    From pipeline with MIT License 8 votes vote down vote up
def playblast_snapshot(path = None,format = None, compression = None, hud = None, offscreen = None, range=None, scale = None):
    current_image_format = cmds.getAttr("defaultRenderGlobals.imageFormat")
    cmds.setAttr("defaultRenderGlobals.imageFormat", 32) # *.png

    if range is None:
        
        range = playback_selection_range()
        print range
        if range is None:
        
            start = cmds.playbackOptions( q=True,min=True )
            end  = cmds.playbackOptions( q=True,max=True )
            range = [start, end]
 	
    cmds.playblast(frame =int((range[0] + range[1])/2), cf = path, fmt="image",  orn=hud, os=offscreen, wh = scene_resolution(), p=scale, v=False) 
    
    cmds.setAttr("defaultRenderGlobals.imageFormat", current_image_format) 
Example #2
Source File: playblast.py    From dpa-pipe with MIT License 6 votes vote down vote up
def runPB(quality, sequence, autoReview):
  #Get the file unix path of the maya file
  filePath = cmds.file(q=True, sceneName=True)
  #Parse the unix path and convert it into a dpa fspattern

  if quality < 50:
    print "Lower than 50 percent quality may result in very poor imaging..."
    cmds.deleteUI("PBQuality")
    return

  print "Percentage chosen: " + str(quality)
  print "From Sequence: " + str(sequence)
  print "AutoSubmit: " + str(autoReview)

  #Attempts to create a playblast of the current maya scene
  success = playblaster(quality, sequence, autoReview)

  if success:
    print "Successfully generated playblast :)"
  else:
    print "Failed to generate playblast :(" 
Example #3
Source File: controllerLibrary.py    From PythonForMayaSamples with GNU General Public License v3.0 6 votes vote down vote up
def saveScreenshot(self, name, directory=DIRECTORY):
        path = os.path.join(directory, '%s.jpg' % name)

        # We'll fit the view to the objects in our scene or our selection
        cmds.viewFit()

        # We'll change our render format to jpg
        cmds.setAttr("defaultRenderGlobals.imageFormat", 8) # This is the value for jpeg

        # Finally we'll save out our image using the playblast module
        # There are a lot of arguments here so it's good to use the documentation to know what's going on
        cmds.playblast(completeFilename=path, forceOverwrite=True, format='image', width=200, height=200,
                       showOrnaments=False, startTime=1, endTime=1, viewer=False)

        # Return the path of the file we saved
        return path


# This will be our first Qt UI!
# We'll be creating a dialog, so lets start by inheriting from Qt's QDialog 
Example #4
Source File: playblast.py    From dpa-pipe with MIT License 5 votes vote down vote up
def playblast_dialog():
  # Creates a dialog prompt to determine if the user wishes to create a playblast
  #response = cmds.confirmDialog( title='Playblast', message='Are you SURE you want to create a new playblast?', button=['Yes','No'], defaultButton='No', cancelButton='No', dismissString='No' )
  #if response == 'Yes':
  floatUI() 
Example #5
Source File: maya_warpper.py    From pipeline with MIT License 5 votes vote down vote up
def snapshot(path = None, width = 96, height = 96):
    current_image_format = cmds.getAttr("defaultRenderGlobals.imageFormat")
    cmds.setAttr("defaultRenderGlobals.imageFormat", 32) # *.png
    #path = "/Users/liorbenhorin/Library/Preferences/Autodesk/maya/2015-x64/scripts/pipeline/thumb.png"
    cmds.playblast(cf = path, fmt="image", frame = cmds.currentTime( query=True ), orn=False, wh = [width,height], p=100, v=False)
    cmds.setAttr("defaultRenderGlobals.imageFormat", current_image_format)
    
    if os.path.isfile(path):
        return path
    else:
        return False 
Example #6
Source File: maya_warpper.py    From pipeline with MIT License 5 votes vote down vote up
def playblast(path = None,format = None, compression = None, hud = None, offscreen = None, range=None, scale = None):
    if range is None:
        
        range = playback_selection_range()
        print range
        if range is None:
        
            start = cmds.playbackOptions( q=True,min=True )
            end  = cmds.playbackOptions( q=True,max=True )
            range = [start, end]
 	
    cmds.playblast(startTime =range[0] ,endTime =range[1], f = path, fmt=format,  orn=hud, os=offscreen, wh = scene_resolution(), p=scale, qlt=90,c=compression, v=True, s = qeury_active_sound_node()) 
Example #7
Source File: maya_warpper.py    From pipeline with MIT License 5 votes vote down vote up
def getPlayblastOptions():
    options = {}
    options["format"] = cmds.playblast(q=True,fmt=True)
    options["compression"] = cmds.playblast(q=True,c=True)
    return options 
Example #8
Source File: lib.py    From pyblish-maya with GNU Lesser General Public License v3.0 5 votes vote down vote up
def maintained_time():
    """Maintain current time during context

    Example:
        >>> with maintained_time():
        ...    cmds.playblast()
        >>> # Time restored

    """

    ct = cmds.currentTime(query=True)
    try:
        yield
    finally:
        cmds.currentTime(ct, edit=True) 
Example #9
Source File: lib.py    From maya-capture-gui with MIT License 5 votes vote down vote up
def get_active_editor():
    """Return the active editor panel to playblast with"""
    # fixes `cmds.playblast` undo bug
    cmds.currentTime(cmds.currentTime(query=True))
    panel = cmds.playblast(activeEditor=True)
    return panel.split("|")[-1] 
Example #10
Source File: lib.py    From maya-capture-gui with MIT License 5 votes vote down vote up
def _fix_playblast_output_path(filepath):
    """Workaround a bug in maya.cmds.playblast to return correct filepath.

    When the `viewer` argument is set to False and maya.cmds.playblast does not
    automatically open the playblasted file the returned filepath does not have
    the file's extension added correctly.

    To workaround this we just glob.glob() for any file extensions and assume
    the latest modified file is the correct file and return it.

    """
    # Catch cancelled playblast
    if filepath is None:
        log.warning("Playblast did not result in output path. "
                    "Playblast is probably interrupted.")
        return

    # Fix: playblast not returning correct filename (with extension)
    # Lets assume the most recently modified file is the correct one.
    if not os.path.exists(filepath):
        directory = os.path.dirname(filepath)
        filename = os.path.basename(filepath)
        # check if the filepath is has frame based filename
        # example : capture.####.png
        parts = filename.split(".")
        if len(parts) == 3:
            query = os.path.join(directory, "{}.*.{}".format(parts[0],
                                                             parts[-1]))
            files = glob.glob(query)
        else:
            files = glob.glob("{}.*".format(filepath))

        if not files:
            raise RuntimeError("Couldn't find playblast from: "
                               "{0}".format(filepath))
        filepath = max(files, key=os.path.getmtime)

    return filepath 
Example #11
Source File: lib.py    From maya-capture-gui with MIT License 5 votes vote down vote up
def capture_scene(options):
    """Capture using scene settings.

    Uses the view settings from "panel".

    This ensures playblast is done as quicktime H.264 100% quality.
    It forces showOrnaments to be off and does not render off screen.

    :param options: a collection of output options
    :type options: dict

    :returns: Full path to playblast file.
    :rtype: str 

    """

    filename = options.get("filename", "%TEMP%")
    log.info("Capturing to: {0}".format(filename))

    options = options.copy()

    # Force viewer to False in call to capture because we have our own
    # viewer opening call to allow a signal to trigger between playblast
    # and viewer
    options['viewer'] = False

    # Remove panel key since it's internal value to capture_gui
    options.pop("panel", None)

    path = capture.capture(**options)
    path = _fix_playblast_output_path(path)

    return path 
Example #12
Source File: lib.py    From maya-capture-gui with MIT License 5 votes vote down vote up
def browse(path=None):
    """Open a pop-up browser for the user"""

    # Acquire path from user input if none defined
    if path is None:

        scene_path = cmds.file(query=True, sceneName=True)

        # use scene file name as default name
        default_filename = os.path.splitext(os.path.basename(scene_path))[0]
        if not default_filename:
            # Scene wasn't saved yet so found no valid name for playblast.
            default_filename = "playblast"

        # Default to images rule
        default_root = os.path.normpath(get_project_rule("images"))
        default_path = os.path.join(default_root, default_filename)
        path = cmds.fileDialog2(fileMode=0,
                                dialogStyle=2,
                                startingDirectory=default_path)

    if not path:
        return

    if isinstance(path, (tuple, list)):
        path = path[0]

    if path.endswith(".*"):
        path = path[:-2]

    # Bug-Fix/Workaround:
    # Fix for playblasts that result in nesting of the
    # extension (eg. '.mov.mov.mov') which happens if the format
    # is defined in the filename used for saving.
    extension = os.path.splitext(path)[-1]
    if extension:
        path = path[:-len(extension)]

    return path 
Example #13
Source File: lib.py    From maya-capture-gui with MIT License 5 votes vote down vote up
def default_output():
    """Return filename based on current scene name.
    
    :returns: A relative filename
    :rtype: str
    """

    scene = get_current_scenename() or "playblast"

    # get current datetime
    timestamp = datetime.datetime.today()
    str_timestamp = timestamp.strftime("%Y-%m-%d_%H-%M-%S")
    filename = "{}_{}".format(scene, str_timestamp)

    return filename 
Example #14
Source File: lib.py    From maya-capture-gui with MIT License 5 votes vote down vote up
def list_compressions(format='avi'):
    # Workaround for Maya playblast bug where undo would
    # move the currentTime to frame one.
    cmds.currentTime(cmds.currentTime(query=True))

    cmd = 'playblast -format "{0}" -query -compression'.format(format)
    return mel.eval(cmd) 
Example #15
Source File: capture.py    From pyblish-bumpybox with GNU Lesser General Public License v3.0 4 votes vote down vote up
def snap(*args, **kwargs):
    """Single frame playblast in an independent panel.

    The arguments of `capture` are all valid here as well, except for
    `start_frame` and `end_frame`.

    Arguments:
        frame (float, optional): The frame to snap. If not provided current
            frame is used.
        clipboard (bool, optional): Whether to add the output image to the
            global clipboard. This allows to easily paste the snapped image
            into another application, eg. into Photoshop.

    Keywords:
        See `capture`.

    """

    # capture single frame
    frame = kwargs.pop('frame', cmds.currentTime(q=1))
    kwargs['start_frame'] = frame
    kwargs['end_frame'] = frame
    kwargs['frame'] = frame

    if not isinstance(frame, (int, float)):
        raise TypeError("frame must be a single frame (integer or float). "
                        "Use `capture()` for sequences.")

    # override capture defaults
    format = kwargs.pop('format', "image")
    compression = kwargs.pop('compression', "png")
    viewer = kwargs.pop('viewer', False)
    raw_frame_numbers = kwargs.pop('raw_frame_numbers', True)
    kwargs['compression'] = compression
    kwargs['format'] = format
    kwargs['viewer'] = viewer
    kwargs['raw_frame_numbers'] = raw_frame_numbers

    # pop snap only keyword arguments
    clipboard = kwargs.pop('clipboard', False)

    # perform capture
    output = capture(*args, **kwargs)

    def replace(m):
        """Substitute # with frame number"""
        return str(int(frame)).zfill(len(m.group()))

    output = re.sub("#+", replace, output)

    # add image to clipboard
    if clipboard:
        _image_to_clipboard(output)

    return output 
Example #16
Source File: capture.py    From maya-capture with MIT License 4 votes vote down vote up
def snap(*args, **kwargs):
    """Single frame playblast in an independent panel.

    The arguments of `capture` are all valid here as well, except for
    `start_frame` and `end_frame`.

    Arguments:
        frame (float, optional): The frame to snap. If not provided current
            frame is used.
        clipboard (bool, optional): Whether to add the output image to the
            global clipboard. This allows to easily paste the snapped image
            into another application, eg. into Photoshop.

    Keywords:
        See `capture`.

    """

    # capture single frame
    frame = kwargs.pop('frame', cmds.currentTime(q=1))
    kwargs['start_frame'] = frame
    kwargs['end_frame'] = frame
    kwargs['frame'] = frame

    if not isinstance(frame, (int, float)):
        raise TypeError("frame must be a single frame (integer or float). "
                        "Use `capture()` for sequences.")

    # override capture defaults
    format = kwargs.pop('format', "image")
    compression = kwargs.pop('compression', "png")
    viewer = kwargs.pop('viewer', False)
    raw_frame_numbers = kwargs.pop('raw_frame_numbers', True)
    kwargs['compression'] = compression
    kwargs['format'] = format
    kwargs['viewer'] = viewer
    kwargs['raw_frame_numbers'] = raw_frame_numbers

    # pop snap only keyword arguments
    clipboard = kwargs.pop('clipboard', False)

    # perform capture
    output = capture(*args, **kwargs)

    def replace(m):
        """Substitute # with frame number"""
        return str(int(frame)).zfill(len(m.group()))

    output = re.sub("#+", replace, output)

    # add image to clipboard
    if clipboard:
        _image_to_clipboard(output)

    return output