예제 #1
0
def save_next_workfile(ctx, publish_items):
    '''Save the next workfile.'''

    host = get_host()
    scene = publish_items['scene']

    # Get the next version number for the original scene name
    if ctx.workspace:
        next_version = ctx.workspace.get_next_version(
            scene['scene_data']['name'],
            scene['scene_data']['ext'],
        )
    else:
        next_version = int(scene['scene_data']['version']) + 1

    # Construct the next scene_file path
    next_scene_name = scene['scene_file'].replace(
        scene['scene_data']['version'],
        '{:0>3d}'.format(next_version),
    )
    next_scene_file = utils.unipath(scene['scene_root'], next_scene_name)

    # If the path already exists Abort...
    if os.path.isfile(next_scene_file):
        raise Abort('Next scene file already exists. Reopening workfile.')

    # Copy the original scene file to the next version
    shutil.copy2(scene['scene_file'], next_scene_file)

    return next_scene_file
예제 #2
0
    def parameters(ctx):
        params = dict(asset_or_shot={
            'label': 'Asset or Shot',
            'required': True,
            'type': types.Entry,
            'help': 'Asset or Shot Entry'
        },
                      fps={
                          'label': 'Frame Rate',
                          'required': True,
                          'type': types.Number,
                          'help': 'Frames per second'
                      })

        if not ctx:
            return params

        params['asset_or_shot']['default'] = ctx.asset or ctx.shot

        host = get_host()
        if host:
            frame_rate = host.get_frame_rate()

            if frame_rate is NotImplemented:
                return params

            params['fps']['default'] = float(frame_rate)

        return params
예제 #3
0
    def parameters(ctx):
        params = dict(
            asset_or_shot={
                'label': 'Asset or Shot',
                'required': True,
                'type': types.Entry,
                'help': 'Asset or Shot Entry'
            },
            min={
                'label': 'Min Frame',
                'required': True,
                'type': types.Number,
                'help': 'Min Frame'
            },
            start={
                'label': 'Start Frame',
                'required': False,
                'type': types.Number,
                'help': 'Animation Start Frame',
            },
            end={
                'label': 'End Frame',
                'required': False,
                'type': types.Number,
                'help': 'Animation End Frame',
            },
            max={
                'label': 'Max Frame',
                'required': True,
                'type': types.Number,
                'help': 'Max Frame'
            },
        )

        if not ctx:
            return params

        params['asset_or_shot']['default'] = ctx.asset or ctx.shot

        host = get_host()
        if host:
            frame_range = host.get_frame_range()

            if frame_range is NotImplemented:
                return params

            params['min']['default'] = float(frame_range[0])
            params['start']['default'] = float(frame_range[1])
            params['end']['default'] = float(frame_range[2])
            params['max']['default'] = float(frame_range[3])

        return params
예제 #4
0
def set_context_to_hou_scene():
    '''Sets the Context to the current houd scene, if it's in a workspace'''

    host = construct.get_host()
    path = host.get_filepath()

    new_ctx = construct.Context.from_path(path)
    new_ctx.file = path

    if new_ctx.workspace:
        _log.debug('Setting context to %s' % path)
        construct.set_context(new_ctx)
        new_ctx.to_env()
    else:
        _log.debug('Not setting context. '
                   'Scene is not in a construct workspace...')

    host.set_workspace(os.path.dirname(path))
예제 #5
0
def set_context_to_nuke_script():
    '''Sets the Context to the current nuke script, if it is in a workspace'''

    import nuke

    host = construct.get_host()
    path = host.get_filepath()

    new_ctx = construct.Context.from_path(path)
    new_ctx.file = path

    if new_ctx.workspace:
        _log.debug('Setting context to %s' % path)
        construct.set_context(new_ctx)
        host.set_workspace(new_ctx.workspace.path)
        new_ctx.to_env()
    else:
        _log.debug('Not setting context. '
                   'Script is not in a construct workspace...')
예제 #6
0
def form_for_action(action_or_identifier):

    if construct.action.is_action_type(action_or_identifier):
        action = action_or_identifier
    else:
        action = construct.actions.get(action_or_identifier)

    try:
        host = construct.get_host()
        parent = host.get_qt_parent()
    except AttributeError:
        host = None
        parent = None

    form_cls = construct.get_form(action.identifier)
    if form_cls:
        form = form_cls(action, construct.get_context(), parent)
        form.setStyleSheet(resources.style(':/styles/dark'))
        return form

    return None
예제 #7
0
def error(header, body, title='Error'):
    '''Popup a dialog asking a question.

    Arguments:
        header (str): The header text
        body (str): The body text
        title (str): Custom window title

    Returns:
        True when dialog is accepted
    '''

    try:
        host = construct.get_host()
        parent = host.get_qt_parent()
    except AttributeError:
        parent = None

    dialog = Notice(header, body, title, parent)
    dialog.setStyleSheet(resources.style(construct.config['STYLE']))

    return bool(dialog.exec_())
예제 #8
0
def ask(question, more=None, title=None):
    '''Popup a dialog asking a question.

    Arguments:
        question (str): The question to ask.
        more (str): Optional second line of text.
        title (str): Optional window title.

    Returns:
        True if dialog is accepted.
    '''

    try:
        host = construct.get_host()
        parent = host.get_qt_parent()
    except AttributeError:
        parent = None

    dialog = Question(question, more, title, parent)
    dialog.setStyleSheet(resources.style(construct.config['STYLE']))

    return bool(dialog.exec_())
예제 #9
0
def set_context_to_maya_scene():
    '''Sets context to the currently open Maya scene.'''

    host = construct.get_host()
    path = host.get_filepath()

    new_ctx = construct.Context.from_path(path)
    new_ctx.file = path

    if new_ctx.workspace:
        _log.debug('Setting context to %s' % path)
        construct.set_context(new_ctx)
        new_ctx.to_env()
    else:
        _log.debug('Not setting context. '
                   'Maya file is not in a construct workspace...')

    # Look for a workspace.mel
    for _ in range(5):
        if os.path.isfile(path + '/workspace.mel'):
            _log.debug('Setting Maya workspace %s' % path)
            host.set_workspace(path)
            break
        path = os.path.dirname(path)
예제 #10
0
def setup():
    _log.debug('Configuring Construct for Maya!')
    construct.init()
    resources.init()

    ctx = construct.get_context()
    host = construct.get_host()
    if ctx.workspace:
        _log.debug('Setting workspace to ' + ctx.workspace.path)
        host.set_workspace(ctx.workspace.path)

    _log.debug('Registering callbacks...')
    callbacks.register()

    _log.debug('Creating Construct menu...')
    menus.ConstructMenu.setup()

    if ctx.workspace and not host.get_filename():
        if ctx.workspace.get_work_files():
            action_identifier = 'file.open'
        else:
            action_identifier = 'file.save'

        construct.show_form(action_identifier)
예제 #11
0
def save_file(file):
    '''Save file in Host application'''

    host = get_host()
    host.save_file(file)
예제 #12
0
# -*- coding: utf-8 -*-
from __future__ import absolute_import
import logging

import construct
from construct_hou import callbacks, utils
from construct_ui import resources

_log = logging.getLogger('construct.hou.pythonrc')
construct.init()
resources.init()
ctx = construct.get_context()
host = construct.get_host()

_log.debug('Setting workspace: %s' % ctx.workspace.path)
host.set_workspace(ctx.workspace.path)

_log.debug('Registering callbacks')
callbacks.register()

_log.debug('Creating Construct menu...')
# TODO

if utils.show_file_open_at_startup():
    # TODO: Add abstraction around creating ActionForms
    if ctx.workspace and not host.get_filename():
        action = construct.actions.get('file.open')
        parent = host.get_qt_parent()
        form_cls = construct.show_form(action.identifier)
예제 #13
0
def apply_frame_rate(fps):
    '''Applies the frame rate to your current scene'''

    host = get_host()
    host.set_frame_rate(fps)
    return {'fps': fps}
예제 #14
0
def ensure_saved(publish_items):
    '''Make sure workfile is saved before publishing.'''

    scene = publish_items['scene']
    host = get_host()
    host.save_file(scene['scene_file'])
예제 #15
0
def publish_scene(ctx, publish_items):
    '''Publish the current scene file.'''

    scene = publish_items['scene']
    host = get_host()
    host.save_file(scene['publish_file'])
예제 #16
0
def apply_frame_range(frame_range):
    '''Applies the frame range to your current scene'''

    host = get_host()
    host.set_frame_range(*frame_range)
    return {'frame_range': frame_range}
예제 #17
0
def open_file(file):
    '''Open file in Host application'''

    host = get_host()
    host.open_file(file)
예제 #18
0
def open_next_workfile(next_scene_file):
    '''Open the next workfile.'''

    host = get_host()
    host.open_file(next_scene_file)