Esempio n. 1
0
def get_shot_from_name(keys=''):
    seq = keys.split(' ')[0]
    shot = keys.split(' ')[1]
    task = keys.split(' ')[3]

    current_scene = alc.scene_object()
    dict_ = {'company': current_scene.company,
             'context': 'source',
             'project': current_scene.project,
             'scope': 'assets',
             'seq': seq,
             'shot': shot,
             'task': task,
             'user': '******',
             'resolution': 'high'
             }

    path_object = alc.PathObject(dict_)
    path_object.set_attr(filename='%s_%s_%s.%s' % (path_object.seq,
                                                   path_object.shot,
                                                   path_object.task,
                                                   current_scene.ext
                                                   ))
    default_asset = path_object.latest_version()
    return (default_asset)
Esempio n. 2
0
def get_asset_from_name(keys=''):
    name = keys.split(' ')[0]
    type = keys.split(' ')[1]

    if type in ['char', 'veh']:
        task = 'rig'


    else:
        task = 'mdl'

    current_scene = alc.scene_object()
    dict_ = {'company': current_scene.company,
             'context': 'source',
             'project': current_scene.project,
             'scope': 'assets',
             'seq': type,
             'shot': name,
             'task': task,
             'user': '******',
             'resolution': 'high'
             }

    path_object = alc.PathObject(dict_)
    path_object.set_attr(filename='%s_%s_%s.%s' % (path_object.seq,
                                                   path_object.shot,
                                                   path_object.task,
                                                   current_scene.ext
                                                   ))
    default_asset = path_object.latest_version()
    return (default_asset)
Esempio n. 3
0
def unlink_asset(object):
    filepath = None

    try:
        libname = object.data.library
    except AttributeError:
        for lib in bpy.data.libraries:
            libname = object.instance_collection

    print('_________unlinking__________')
    print(object)

    if 'proxy' in object.name:
        name = object.name.split('_')[0]
    else:
        name = object.name

    obj = bpy.data.objects[name]

    if not libname:
        bpy.data.batch_remove(ids=([obj]))
    else:
        try:
            filepath = libname.library.filepath

        except AttributeError:
            pass
        if filepath and alc.PathObject(filepath).type == 'env':
            remove_linked_environment_dependencies(libname.library)

        bpy.data.batch_remove(ids=(libname, obj))
Esempio n. 4
0
def get_items(self, context):
    from cgl.plugins.blender import alchemy as alc
    import os

    scene = alc.scene_object()
    project = alc.PathObject(scene.split_after('project'))
    char = project.copy(scope='assets', seq='char')

    assets = ['char', 'prop', 'lib', 'veh', 'env']
    asset_dic = {}

    for asset in assets:
        asset_dic.update({asset: project.copy(scope='assets', seq=asset,branch = scene.branch,)})

    list_base = []
    list = []

    for type in assets:

        if os.path.isdir(asset_dic[type].path_root):
            for i in os.listdir(asset_dic[type].path_root):
                list_base.append('{} {}'.format(i, type))

    dictionary = {}

    for i in list_base:
        list.append(i.split(' ')[0])

    dictionary = dict(map(str, x.split(' ')) for x in list_base)

    value = [('{} {}'.format(list[i], dictionary[list[i]]),
              '{} {}'.format(dictionary[list[i]],
                             '{}'.format(list[i])), '') for i in range(len(list))]
    return (value)
Esempio n. 5
0
def get_asset_from_name(keys=''):
    name = keys.split(' ')[0]
    type = keys.split(' ')[1]
    user = keys.split(' ')[2]

    task = 'mdl'

    current_scene = alc.scene_object()
    dict_ = {
        'company': current_scene.company,
        'context': 'source',
        'project': current_scene.project,
        'scope': 'assets',
        'seq': type,
        'shot': name,
        'task': task,
        'user': user,
        'branch': current_scene.branch,
        'variant': 'default',
        'resolution': 'high'
    }

    path_object = alc.PathObject(dict_)
    path_object.set_attr(filename='%s_%s_%s.%s' %
                         (path_object.seq, path_object.shot, path_object.task,
                          current_scene.ext))
    default_asset = path_object.latest_version()
    return (default_asset)
Esempio n. 6
0
def get_task(self, context):
    scene = bpy.types.Scene.scene_enum

    path_object = alc.PathObject(get_asset_from_name(scene))
    tasks = reorder_list(path_object.glob_project_element('task'), arg='rig')
    value = [(tasks[i], tasks[i], '') for i in range(len(tasks))]

    return (value)
Esempio n. 7
0
def get_variant(self, context):
    scene = bpy.types.Scene.scene_enum
    path_object = alc.PathObject(get_asset_from_name(scene))

    versions = path_object.glob_project_element('variant')
    version = versions.reverse()
    value = [(versions[i], versions[i], '') for i in range(len(versions))]
    return (value)
Esempio n. 8
0
def get_users(self, context):
    scene = bpy.types.Scene.scene_enum
    path_object = alc.PathObject(get_asset_from_name(scene))

    user_list = path_object.glob_project_element('user')
    if not user_list:
        path_object = path_object.copy(task='rig')
        user_list = path_object.glob_project_element('user')
    users = reorder_list(user_list, arg='publish')

    value = [(users[i], users[i], '') for i in range(len(users))]

    return (value)
Esempio n. 9
0
def get_users(self, context):
    scene = bpy.types.Scene.scene_enum
    path_object = alc.PathObject(get_shot_from_name(scene))

    users = os.listdir(path_object.split_after('variant'))

    for i in users:

        if i == 'publish':
            users.remove(i)
            users.insert(0, "publish")

    value = [(users[i], users[i], '') for i in range(len(users))]

    return (value)
def get_default_lighting():
    current_scene = alc.scene_object()
    dict_ = {
        'company': current_scene.company,
        'context': 'source',
        'project': current_scene.project,
        'scope': 'shots',
        'seq': 'DEFAULT_LIGHT_SETUP',
        'shot': '0010',
        'task': 'light',
        'user': '******',
        'resolution': 'high'
    }

    path_object = alc.PathObject(dict_)
    path_object.copy(set_proper_filename=True)
Esempio n. 11
0
def get_default_camera():
    current_scene = alc.scene_object()
    dict_ = {
        'company': current_scene.company,
        'context': 'source',
        'project': current_scene.project,
        'scope': 'shots',
        'seq': 'DEFAULT_RIG_CHECK',
        'shot': '0010',
        'task': 'cam',
        'user': '******',
        'resolution': 'high'
    }

    path_object = alc.PathObject(dict_)
    path_object.set_attr(
        filename='%s_%s_%s.%s' %
        (path_object.seq, path_object.shot, path_object.task, 'blend'))
    default_camera = path_object.latest_version()
    print(default_camera.path_root)

    default_in_scene = False
    for group in bpy.data.node_groups:
        if path_object.filename in group.name:
            default_in_scene = True

    if not default_in_scene:
        alc.import_file(filepath=default_camera.path_root,
                        type='CAMERA',
                        linked=False,
                        collection_name=path_object.filename_base)
        bpy.context.scene.collection.objects.link(
            bpy.data.objects[path_object.filename_base])

    outFile = default_camera.copy(ext='json').path_root
    with open(outFile) as json_file:

        data = json.load(json_file)
        bpy.context.scene.frame_start = data['frame_start']
        bpy.context.scene.frame_end = data['frame_end']

    #

    return (default_camera)
Esempio n. 12
0
def open_available_file(path_object):
    import os
    filename = alc.PathObject(path_object).copy(filename='')
    print(filename.path_root)
    found = False
    files = os.listdir(filename.path_root)

    print(files)
    if files:
        for file in files:
            if file.endswith('.blend') and not found:
                found = True
                print(path_object)
                new_file = filename.copy(filename=file).path_root
                os.rename(new_file, path_object)
                alc.open_file(path_object)

    else:
        alc.confirm_prompt(message='No file found')
Esempio n. 13
0
def selected_path_object():
    from pathlib import Path
    selection = bpy.context.selected_objects
    for obj in selection:
        if 'proxy' in obj.name:
            name = obj.name.split('_')[0]
        else:
            if '.' in obj.name:

                name = obj.name.split('.')[0]
            else:
                name = obj.name
        library = bpy.context.object.instance_collection.library
        library_path = bpy.path.abspath(library.filepath)
        filename = Path(bpy.path.abspath(library_path)).__str__()
        lumber_object = alc.PathObject(filename)
        lumber_object = lumber_object.copy(context='source')

        return lumber_object
Esempio n. 14
0
def parent_linked_environment_assets(library):
    import os
    env = library
    bpy.ops.file.make_paths_absolute()
    env_path = alc.PathObject(env.filepath)
    env_layout = env_path.copy(ext='json').path_root
    asset_collection = create_collection('env')

    if os.path.isfile(env_layout):
        data = load_json(env_layout)
        env_object_collection = create_environment_objects_collection(
            env_path.asset)

        for i in data:
            name = data[i]['name']
            print(44444444444)
            print(env_object_collection)
            move_to_collection(i, env_object_collection)
        print(env_path.asset)
        move_to_collection(env_path.asset, bpy.data.collections['env'])
Esempio n. 15
0
def remove_linked_environment_dependencies(library):
    env = library
    bpy.ops.file.make_paths_absolute()
    env_path = alc.PathObject(env.filepath)
    env_layout = env_path.copy(ext='msd').path_root

    data = load_json(env_layout)

    for i in data:
        print(i)
        name = data[i]['name']

        if i in bpy.data.objects:
            obj = bpy.data.objects[i]
            unlink_asset(obj)
    try:
        env_asset_collection = bpy.data.collections['{}_assets'.format(env_path.asset)]
        bpy.data.collections.remove(env_asset_collection)
    except KeyError:
        pass
Esempio n. 16
0
def run():
    view_layer = bpy.context.scene.objects

    bpy.ops.file.make_paths_absolute()

    reparent_collections(view_layer)
    parent_object(view_layer, 'cam', 'CAMERA')
    parent_object(view_layer, 'light', 'LIGHT')
    parent_object(view_layer, 'gpencil', 'GPENCIL')
    parent_object(view_layer, 'armature', 'ARMATURE')
    create_characters_collections()
    for lib in bpy.data.libraries:
        type = alc.PathObject(return_lib_path(lib)).type
        if type == 'env':
            print('________________________env library found:')
            print(lib)

            parent_linked_environment_assets(lib)

    bpy.ops.file.make_paths_relative()
Esempio n. 17
0
def get_default_shader():
    current_scene = alc.scene_object()
    dict = {
        'company': current_scene.company,
        'context': 'render',
        'project': current_scene.project,
        'branch': 'master',
        'variant': 'default',
        'scope': 'assets',
        'seq': 'lib',
        'shot': 'DEFAULTSHADER',
        'task': 'shd',
        'version': '000.001',
        'user': '******',
        'resolution': 'high',
        'filename': 'lib_DEFAULTSHADER_shd',
        'ext': 'blend'
    }

    path_object = alc.PathObject(dict)

    path_object = path_object.copy(set_proper_filename=True, latest=True)
    print(path_object.path_root)

    default_in_scene = False
    # for group in bpy.data.node_groups:
    #     if 'DEFAULTSHADER' in group.name:
    #         default_in_scene = True

    if not default_in_scene:
        from cgl.plugins.blender.tasks import shd
        from importlib import reload
        import os

        if os.path.isfile(path_object.path_root):

            reload(shd)

            shd.import_materials(path_object.path_root)
        else:
            print('NO DEFAULT SHADER FOUND')
Esempio n. 18
0
def get_users(self, context):
    import os
    scene = bpy.types.Scene.scene_enum
    path_object = alc.PathObject(get_asset_from_name(scene))
    print(path_object.path_root)

    user_list = path_object.glob_project_element('user')

    if not user_list:
        if path_object.type == 'char':
            path_object = path_object.copy(task='rig')
            user_list = path_object.glob_project_element('user')
        else:
            users = os.listdir(path_object.copy(task='mdl').split_after('task'))

    users = reorder_list(user_list, arg='publish')
    print(users)

    value = [(users[i], users[i], '') for i in range(len(users))]

    return (value)
Esempio n. 19
0
def get_shot_from_name(keys=''):
    seq = keys.split(' ')[0]
    shot = keys.split(' ')[1]
    task = keys.split(' ')[2]
    user = keys.split(' ')[3]

    current_scene = alc.scene_object()
    dict_ = {'company': current_scene.company,
             'context': 'source',
             'project': current_scene.project,
             'scope': 'shots',
             'seq': seq,
             'shot': shot,
             'task': task,
             'user': user,
             'resolution': 'high'
             }

    path_object = alc.PathObject(dict_)
    default_asset = path_object.latest_version()
    return default_asset
Esempio n. 20
0
def open_selected_library():
    obj = bpy.context.active_object


    if 'proxy' in obj.name:
        name = obj.name.split('_')[0]
    else:
        if '.' in obj.name:
            name = obj.name.split('.')[0]
        else:

            name = obj.name

    library = bpy.data.collections[name].library
    libraryPath = bpy.path.abspath(library.filepath)
    filename = Path(bpy.path.abspath(libraryPath)).__str__()

    lumber_object = alc.PathObject(filename).copy(context = 'source')
    alc.save_file()
    import os
    os.startfile(lumber_object.path_root, 'open')
Esempio n. 21
0
def get_items(self, context):
    from cgl.plugins.blender import alchemy as alc
    import os

    scene = alc.scene_object()
    project = alc.PathObject(scene.split_after('project'))
    char = project.copy(scope='assets', seq='char')

    assets = ['char', 'prop', 'lib', 'veh', 'env']
    asset_dic = {}

    for asset in assets:
        asset_dic.update({asset: project.copy(scope='assets', seq=asset)})

    type = 'char'
    characters = os.listdir(asset_dic['char'].path_root)
    dictionary = {key: 'char' for key in characters}

    type = 'prop'
    props = os.listdir(asset_dic[type].path_root)
    dictionary.update({key: type for key in props})

    type = 'env'
    environment = os.listdir(asset_dic[type].path_root)
    dictionary.update({key: type for key in environment})

    type = 'veh'
    vehicles = os.listdir(asset_dic[type].path_root)
    dictionary.update({key: type for key in vehicles})

    list = characters + props + environment + vehicles
    print(dictionary)

    # list.append(os.listdir(asset_dic['prop'].path_root))

    value = [('{} {}'.format(list[i], dictionary[list[i]]),
              '{} {}'.format(dictionary[list[i]],
                             list[i]), '') for i in range(len(list))]

    return (value)
Esempio n. 22
0
def get_asset_from_name(keys=''):
    import os
    name = keys.split(' ')[0]
    type = keys.split(' ')[1]
    user = keys.split(' ')[2]

    task = 'mdl'

    current_scene = alc.scene_object()
    dict_ = {'company': current_scene.company,
             'context': 'source',
             'project': current_scene.project,
             'scope': 'assets',
             'seq': type,
             'shot': name,
             'task': task,
             'user': user,
             'branch':current_scene.branch,
             'resolution': 'high'
             }

    path_object = alc.PathObject(dict_)
    path_object.set_attr(filename='%s_%s_%s.%s' % (path_object.seq,
                                                   path_object.shot,
                                                   path_object.task,
                                                   current_scene.ext
                                                   ))
    default_asset = path_object.latest_version()
    if default_asset.type == 'char':
        default_asset = default_asset.copy(task='rig', set_proper_filename=True)

    if not os.path.isfile(default_asset.path_root):
        if default_asset.type == 'char':
            default_asset = path_object.copy(task='rig', set_proper_filename=True)

        else:
            default_asset = path_object.copy(task='mdl')
        # default_asset = default_asset.copy(task='rig', set_proper_filename=True)

    return (default_asset)
def run():
    import os
    """
    This run statement is what's executed when your button is pressed in blender.
    :return:
    """

    object = bpy.context.object

    if object:
        library = get_lib_from_object(object)
        path = return_lib_path(library)
        path_object = alc.PathObject(path)
        json = path_object.copy(ext='json').path_root
        if os.path.isfile(json):
            read_layout(outFile=json)
            bpy.ops.object.setup_collections()

        else:
            alc.confirm_prompt(message='no layout file found')
    else:
        alc.confirm_prompt(message='please select an object')
def get_default_lighting():
    current_scene = alc.scene_object()
    dict_ = {
        'company': current_scene.company,
        'context': 'source',
        'project': current_scene.project,
        'scope': 'shots',
        'seq': 'DEFAULT_LIGHT_SETUP',
        'shot': '0010',
        'task': 'light',
        'user': '******',
        'resolution': 'high'
    }

    path_object = alc.PathObject(dict_)
    path_object.set_attr(filename='%s_%s_%s.%s' %
                         (path_object.seq, path_object.shot, path_object.task,
                          current_scene.ext))
    default_light = path_object.latest_version()
    print(default_light.path_root)

    default_in_scene = False
    for collection in bpy.data.collections:
        if 'defautLightSet' in collection.name:
            default_in_scene = True

    if not default_in_scene:
        alc.import_file(
            filepath=default_light.path_root,
            collection_name=default_light.filename_base,
            linked=False,
            append=False,
            type='COLLECTION',
        )

    bpy.context.scene.collection.children.link(
        bpy.data.collections[path_object.shot])
    return (default_light)
Esempio n. 25
0
def get_items(self, context):
    from cgl.plugins.blender import alchemy as alc
    import os

    scene = alc.scene_object()
    project = alc.PathObject(scene.split_after('project'))
    proj_shots = project.copy(scope='shots',
                              context='source',
                              branch=alc.scene_object().branch)

    print('_______________SHOTS___________')

    sequences = os.listdir(proj_shots.path_root)

    print(sequences)
    shots = []

    for seq in sequences:
        # print(seq)
        seq_path = os.path.join(proj_shots.path_root, seq)
        if os.path.isdir(seq_path):
            # print(seq_path)

            list = os.listdir(seq_path)
            for shot in list:
                if os.path.isdir(os.path.join(seq_path, shot)):
                    shot_dir = os.path.join(seq_path, shot)
                for task in os.listdir(shot_dir):

                    if os.path.isdir(os.path.join(shot_dir, task)):
                        shotid = '{} {} {}'.format(seq, shot, task)
                        if '.json' not in shotid:
                            shots.append((shotid, shotid, ''))
                        # print(22222222222)
                        print(shotid)

    return (shots)
Esempio n. 26
0
def reparent_collections(view_layer):
    for obj in view_layer:

        if obj.instance_type == 'COLLECTION':
            if obj.instance_collection:

                collection = obj.instance_collection
                print(collection)
                print(collection.library)
                if collection.library:

                    path_object = alc.PathObject(collection.library.filepath)

                    if path_object.asset:

                        print(path_object.root)
                        create_collection(path_object.type)
                        for collection in bpy.data.collections:

                            if collection.name == path_object.type:
                                # print(collection.name )

                                if collection not in obj.users_collection:
                                    try:
                                        collection.objects.link(obj)
                                    except RuntimeError:
                                        print(
                                            " Error: Could not link the object {} "
                                            .format(obj),
                                            "because one of it's collections is  is linked."
                                        )
                        unlink_collections(obj, path_object.type)

    for collection in bpy.context.scene.collection.children:
        if len(collection.objects) < 1:
            print(collection.name)
            bpy.context.scene.collection.children.unlink(collection)