Esempio n. 1
0
    def test_get_output(self):

        # Test create output
        for _path in [
            ('/hvanderbeek_0001P/sequences/dev/dev0000/'
             'tracking/output/camcache/imagePlaneTest_renderCam/v045/'
             'alembic/dev0000_imagePlaneTest_renderCam_v045.abc'),
            ('/hvanderbeek_0001P/assets/3D/character/archer/'
             'rig/output/rig/rig_main/v016/assembly/'
             'archer_rig_main_v016.mb'),
        ]:
            assert tk.get_output(pipe.PROJECTS_ROOT + _path)

        # Test output objects
        for _path in [
                '/hvanderbeek_0001P/sequences/dev/dev9999/'
                'animation/output/animcache/test_archer/v004/alembic/'
                'dev9999_test_archer_v004.abc',
                '/hvanderbeek_0001P/sequences/dev/dev9999/'
                'animation/output/render/test_masterLayer/v004/jpg/'
                'dev9999_test_masterLayer_v004.%04d.jpg',
        ]:
            _path = pipe.PROJECTS_ROOT + _path
            print _path
            _out = tk.get_output(_path)
            _latest = _out.find_latest()
            print _out
            assert not _out.is_latest()
            assert not _out == _latest
            assert _out.version < _latest.version
            print _latest
            print _out.find_work_file(verbose=0)
            assert (_out.map_to(_out.output_name_type) == _latest.map_to(
                _out.output_name_type))
            print
Esempio n. 2
0
def update_nk(template, shot, diff=True, force=True):
    """Update nk template to new shot.

    Args:
        template (TTWorkFileBase): template work file
        shot (TTShotRoot): shot to update to
        diff (bool): show diffs
        force (bool): save with no confirmation
    """
    _new_work = template.map_to(Shot=shot.shot).find_next()
    _start, _end = shot.get_frame_range()

    _nk = _NkFile(template.path)
    _update_nk_reads(nk_file=_nk, shot=shot)

    # Update write nodes
    for _node in _nk.find_nodes(type_='Write'):
        for _attr in ['file', 'proxy']:
            _file = _node.read_attr(_attr)
            _orig_out = tk.get_output(_file)
            if not _orig_out:
                continue
            print 'ORIG OUT', _orig_out
            _new_out = _orig_out.map_to(Shot=shot.shot,
                                        version=_new_work.version)
            print 'NEW OUT', _orig_out
            _node.set_attr(_attr, _new_out.path)
        print

    # Update root
    _root = _nk.find_node(type_='Root')
    _root.set_attr('name', _new_work.path)
    _root.set_attr('first_frame', _start)
    _root.set_attr('last_frame', _end)

    # Update header
    _header = _nk.data[0]
    assert isinstance(_header, six.string_types)
    _tokens = [_token for _token in re.split('[ "]', _header) if _token]
    for _token in _tokens:
        _orig_out = tk.get_output(_token)
        if not _orig_out:
            continue
        _new_out = _orig_out.map_to(Shot=shot.shot, version=_new_work.version)
        assert _header.count(_token) == 1
        _header = _header.replace(_token, _new_out.path)
        _nk.data[0] = _header

    if diff:
        _tmp_nk = File(abs_path('{}/test.nk'.format(tempfile.gettempdir())))
        _nk.write(_tmp_nk.path, force=True)
        _tmp_nk.diff(template.path)

    # Write new work
    if not force:
        qt.ok_cancel('Write new work file?\n\n{}'.format(_new_work.path))
    _nk.write(_new_work.path, force=True)
    _new_work.set_comment(comment='Scene built by shot_builder')
    print 'WROTE NK:', _new_work.path
Esempio n. 3
0
    def test_write_image_plane(self):
        """Write image plane settings to output abc dir."""
        from maya_psyhive.tools import export_img_plane
        set_dev_mode(False)
        _img = (r"\\la1nas006\homedir\hvanderbeek\Desktop"
                r"\tumblr_p3gzfbykSP1rv4b7io1_1280.png")
        _abc_path = (_DEV_PROJ.path + '/sequences/dev/dev0000/tracking/'
                     'output/camcache/imagePlaneTest_renderCam/v047/alembic/'
                     'dev0000_imagePlaneTest_renderCam_v047.abc')
        _abc = tk.get_output(_abc_path).find_latest()
        _presets = [
            '{}/{}'.format(_abc.parent().path, _filename)
            for _filename in ['camera.preset', 'imagePlane.preset']
        ]

        for _preset in _presets:
            if os.path.exists(_preset):
                os.remove(_preset)

        _cam = hom.CMDS.camera()
        _img_plane = hom.CMDS.imagePlane(camera=_cam, fileName=_img)

        export_img_plane(camera=_cam.shp, abc=_abc.path)

        for _preset in _presets:
            assert os.path.exists(_preset)
Esempio n. 4
0
def _update_nk_reads(nk_file, shot):
    """Update Read node in nk file.

    Args:
        nk_file (_NkFile): nk file to update
        shot (TTShotRoot): shot to update to
    """
    _start, _end = shot.get_frame_range()

    # Update read nodes
    for _node in nk_file.find_nodes(type_='Read'):
        _file = _node.read_attr('file')
        _orig_out = tk.get_output(_file)
        if not _orig_out:
            continue
        print 'ORIG OUT', _orig_out
        _new_out = _orig_out.map_to(Shot=shot.shot).find_latest(catch=True)
        print 'NEW OUT', _orig_out
        if not _new_out:
            _node.set_attr('disable', True)
        else:
            _node.set_attr('file', _new_out.path)
            _node.set_attr('first', _start)
            _node.set_attr('last', _end)
            _node.set_attr('origfirst', _start)
            _node.set_attr('origlast', _end)
        print 'UPDATED', _node
        print
Esempio n. 5
0
def restore_img_plane(time_control, abc):
    """Restore image plane from preset data.

    Args:
        time_control (str): exocortex time control name
        abc (str): path to output abc
    """
    from psyhive import tk

    # Ignore non camera caches
    _abc = tk.get_output(abc)
    print 'ABC', _abc.path
    if _abc.output_type != 'camcache':
        print 'NOT A CAMERA CACHE'
        return

    # Make sure there are presets to apply
    _presets = []
    for _type in ['imagePlane', 'camera']:
        _preset = '{}/{}.preset'.format(_abc.dir, _type)
        if not os.path.exists(_preset):
            print 'MISSING PRESET', _preset
            return
        _presets.append(_preset)

    # Find camera node
    _time_ctrl = hom.HFnDependencyNode(time_control)
    _cam_shp = get_single(_time_ctrl.find_downstream(type_='camera',
                                                     filter_=_abc.output_name),
                          catch=True)
    if not _cam_shp:
        print 'NO CAM FOUND'
        return
    _cam = hom.HFnCamera(get_parent(_cam_shp))

    # Create image plane and apply presets
    _img_plane = hom.CMDS.imagePlane(camera=_cam)
    for _preset, _shp in safe_zip(_presets, [_img_plane.shp, _cam.shp]):
        _shp.load_preset(_preset)