Beispiel #1
0
 def _callback__remove(self):
     _to_remove = self.ui.list.selected_data()
     for _rig in qt.ProgressBar(
             _to_remove, "Removing {:d} rig{}", col='IndianRed'):
         _rig.remove(force=True)
     cmds.refresh()
     self.close()
Beispiel #2
0
    def _read_cache_data(self, shots, progress=True, force=False, dialog=None):
        """Read all cache data.

        Args:
            shots (TTShotRoot list): shots to check
            progress (bool): show progress bar
            force (bool): force reread data from shotgun
            dialog (QDialog): parent dialog
        """
        print 'READING CACHE DATA', force
        _pos = dialog.get_c() if dialog else None
        for _shot in qt.ProgressBar(
                shots, 'Reading {:d} shot{}', col='SeaGreen',
                show=progress, pos=_pos, parent=dialog):
            _shot.read_cache_data(force=force)
            self.cached_shots.add(_shot)
Beispiel #3
0
    def read_assets(
            self, shots, steps, tasks, force=False, dialog=None,
            verbose=0):
        """Get a list of relevant assets.

        Args:
            shots (TTRoot list): shots to check
            steps (str list): apply steps filter
            tasks (str list): apply tasks filter
            force (bool): force replace current scene with no confirmation
            dialog (QDialog): parent dialog
            verbose (int): print process data

        Returns:
            (CTTAssetOutputVersion list): matching assets
        """
        _work_files = self.find_work_files(
            shots=shots, steps=steps, tasks=tasks, cached=False)
        lprint(
            "READING {:d} WORK FILES".format(len(_work_files)),
            verbose=verbose)

        # Read work file dependencies
        _force = force
        _progress = qt.ProgressBar(
            _work_files, 'Reading {:d} work file{}', col=_COL, parent=dialog)
        for _work_file in _progress:

            check_heart()

            # Read deps
            try:
                _deps, _replaced_scene = _work_file.read_dependencies(
                    confirm=not _force)
            except qt.DialogCancelled:
                _progress.close()
                return None
            if _replaced_scene:
                _force = True
            lprint('   -', _work_file.basename, _deps, verbose=verbose)
            _assets = _work_file.get_cacheable_assets()

            self._cached_work_files.add(_work_file)

        return _work_files
Beispiel #4
0
    def read_tasks(
            self, shots, force=False, dialog=None, progress=False):
        """Read all data required to populate interface.

        Args:
            shots (TTRoot list): shots to check
            force (bool): force reread data
            dialog (QDialog): parent dialog
            progress (bool): show progress bar

        Returns:
            (str list): matching tasks
        """
        for _shot in qt.ProgressBar(
                shots, 'Reading {:d} shot{}', show=progress,
                parent=dialog, col=_COL):
            _shot.read_work_files(force=force)
            self.cached_shots.add(_shot)
Beispiel #5
0
def cache_work_files(data, farm=True, parent=None):
    """Recache the given list of work files.

    Args:
        data (list): work files and namespaces to recache
        farm (bool): submit recaches to farm
        parent (QDialog): parent interface (for dialog positioning)
    """
    _pos = parent.get_c() if parent else None
    qt.ok_cancel('Cache {:d} work file{}?'.format(len(data), get_plural(data)),
                 pos=_pos,
                 parent=parent,
                 title='Confirm cache')

    for _work_file, _namespaces in qt.ProgressBar(data,
                                                  "Caching {:d} work file{}",
                                                  col="DeepSkyBlue",
                                                  pos=_pos,
                                                  parent=parent):
        print 'CACHE', _work_file.path
        print _namespaces
        print
        cache_work_file(work_file=_work_file,
                        namespaces=sorted(_namespaces),
                        farm=farm,
                        parent=parent)

    # Completed notification
    if farm:
        _msg = 'Submitted {:d} work file{} to farm'
    else:
        _msg = 'Cached {:d} work file{} locally'
    qt.notify(_msg.format(len(data), get_plural(data)),
              pos=_pos,
              title='Complete',
              parent=parent)
Beispiel #6
0
def cache_work_file(work_file,
                    namespaces,
                    confirm=False,
                    new_scene=False,
                    farm=True,
                    parent=None):
    """Recache the given work file.

    The work file is opened, versioned up and the recached.


    Args:
        work_file (TTWorkFileBase): work file to recache
        namespaces (str list): list of assets to recache
        confirm (bool): confirm before execute
        new_scene (bool): new scene after recache
        farm (bool): submit recache to farm
        parent (QDialog): parent interface (for dialog positioning)
    """
    dprint('RECACHING', work_file.path)

    _engine = tank.platform.current_engine()
    _fileops = _engine.apps['psy-multi-fileops']

    # Load the scene
    work_file.load()
    maya.utils.processIdleEvents()
    _fileops.init_app()

    # Update assets
    _updated = []
    for _ns in qt.ProgressBar(namespaces,
                              'Updating {:d} asset{}',
                              col='LightSteelBlue',
                              parent=parent):
        _ref = ref.find_ref(_ns)
        if not _ref.is_loaded():
            _ref.load()
        _cur_asset = tk.TTAssetOutputFile(_ref.path)
        _latest_asset = _cur_asset.find_latest()
        lprint(' - UPDATING {} v{:03d} -> v{:03d}'.format(
            _ref.namespace, _cur_asset.version, _latest_asset.version))
        if _cur_asset.is_latest():
            lprint('   - NO UPDATE REQUIRED')
            continue
        _ref.swap_to(_latest_asset.path)
        _updated.append(_ref.namespace)

    # Version up
    _fileops.init_app()
    maya.utils.processIdleEvents()
    _engine = tank.platform.current_engine()
    _fileops = _engine.apps['psy-multi-fileops']
    _fileops.version_up_workfile()
    maya.utils.processIdleEvents()
    _cur_work = tk.cur_work(class_=CTTMayaShotWork)
    _cur_work.set_comment('Versioned up by batch cache tool')
    _cur_work.read_dependencies(new_scene=False)

    _exec_cache(namespaces=namespaces,
                new_scene=new_scene,
                confirm=confirm,
                farm=farm)
    cmds.file(new=True, force=True)
Beispiel #7
0
def _blast_and_find_rigs_outside_frustrum(cam,
                                          rigs,
                                          kwargs,
                                          sample_freq,
                                          verbose=1):
    """Execute blast, checking to find rigs outside frustrum.

    Args:
        cam (HFnCamera): camera being blasted through
        rigs (FileRef list): list of rigs to check
        kwargs (dict): playblast kwargs
        sample_freq (int): frame gap between frustrum tests - ie. a value
            of 5 means the frustrum is sampled every 5 frames
        verbose (int): print process data

    Returns:
        (FileRef list): list of rigs outside frustrum
    """
    _frames = kwargs.pop('frame')
    _check_frames = range(_frames[0], _frames[-1] + 1, sample_freq)

    # Blast scene and test rigs in camera
    _off_cam_rigs = copy.copy(rigs)
    _progress = qt.ProgressBar(_check_frames,
                               'Blasting {:d} frames'.format(len(_frames)),
                               col='orchid')
    _cancelled = False
    while _check_frames:

        _frame = _check_frames.pop(0)

        # Update progress bar
        if not _progress.isVisible():
            _cancelled = True
            raise StopIteration("Blast cancelled")
        _progress.next()
        print 'UPDATED PROGRESS', _progress

        lprint(' - CHECKING FRAME', _frame, verbose=verbose)
        cmds.currentTime(_frame)

        # Remove rigs in camera from list
        lprint(' - TESTING {:d} RIGS'.format(len(_off_cam_rigs)),
               _off_cam_rigs,
               verbose=verbose)
        for _rig in copy.copy(_off_cam_rigs):
            if _rig_in_cam(cam, _rig):
                lprint(' - RIG IN CAMERA:', _rig, verbose=verbose)
                _off_cam_rigs.remove(_rig)

        # Blast frames
        if not _off_cam_rigs:
            lprint(' - NO RIGS LEFT TO CHECK', verbose=verbose)
            _check_frames = []
            _blast_frames = range(_frame, _frames[-1] + 1)
            _progress.close()
        else:
            _blast_frames = range(_frame, _frame + sample_freq)
        lprint(' - BLASTING FRAMES',
               ints_to_str(_blast_frames),
               verbose=verbose)
        cmds.playblast(frame=_blast_frames, **kwargs)

    _progress.close()

    return _off_cam_rigs
Beispiel #8
0
    def _find_cache_data(
            self, shots, steps=None, tasks=None, assets=None,
            hide_omitted=None, stale_only=None, progress=False, force=False,
            dialog=None, verbose=0):
        """Search cache data.

        Args:
            shots (TTShotRoot list): shots to check
            steps (str list): return only data with these steps
            tasks (str list): return only data with these tasks
            assets (TTAssetOutputName list): return only data with these
                asset names
            hide_omitted (bool): ignore omitted caches
            stale_only (bool): ignore caches that used the latest rig/asset
            progress (bool): show progress on read shots
            force (bool): force reread data from shotgun
            dialog (QDialog): parent dialog (for progress bars)
            verbose (int): print process data

        Returns:
            (dict list): filtered cache data
        """
        assert not verbose
        _hide_omitted = (
            self.hide_omitted if hide_omitted is None else hide_omitted)
        _stale_only = (
            self.stale_only if stale_only is None else stale_only)

        if verbose:
            print 'READING CACHE DATA'
            print 'TASKS', tasks
            print 'ASSETS', assets
            print 'STALE ONLY', _stale_only
            print 'HIDE OMITTED', _hide_omitted

        _cache_data = []
        _pos = dialog.ui.get_c() if dialog else None
        for _shot in qt.ProgressBar(
                shots, 'Reading {:d} shots', col='SeaGreen',
                show=progress, pos=_pos):
            if shots and _shot not in shots:
                continue
            for _data in _shot.read_cache_data(force=force):
                _cache = _data['cache']
                _asset_ver = _data['asset_ver']
                _asset = _asset_ver.get_name()
                if _hide_omitted and _data['sg_status_list'] == 'omt':
                    lprint(' - OMITTED REJECT', _cache, verbose=verbose)
                    continue
                if tasks is not None and _cache.task not in tasks:
                    lprint(' - TASK REJECT', _cache, verbose=verbose)
                    continue
                if steps is not None and _cache.step not in steps:
                    lprint(' - STEP REJECT', _cache, verbose=verbose)
                    continue
                if assets is not None and _asset not in assets:
                    lprint(' - ASSET REJECT', _cache, verbose=verbose)
                    continue
                if _stale_only and _asset_ver.is_latest():
                    lprint(' - NOT STALE REJECT', _cache, verbose=verbose)
                    continue
                lprint(
                    ' - ACCEPTED', _cache, _data['origin_scene'],
                    verbose=verbose)
                _cache_data.append(_data)

        return _cache_data