def run(): """ This run statement is what's executed when your button is pressed in blender. :return: """ active = bpy.context.active_object selection = bpy.context.selected_objects instanced_collection = None for obj in selection: if not obj == active: if obj.is_instancer: instanced_collection = bpy.data.collections[obj.name.split('.')[0]] bpy.ops.object.particle_system_add() instance = active.particle_systems['ParticleSettings'] instance.name = 'instance' settings = instance.settings settings.type = 'HAIR' settings.use_advanced_hair = True settings.use_rotations = True settings.rotation_mode = 'GLOB_Y' settings.render_type = 'COLLECTION' settings.use_whole_collection = True if instanced_collection: settings.instance_collection = instanced_collection instance.name = obj.name.split('.')[0] alc.confirm_prompt(message='Instance Created') else: alc.confirm_prompt(message='instance created please select collection in the render section ')
def run(): """ This run statement is what's executed when your button is pressed in blender. :return: """ from cgl.plugins.blender import alchemy as alc import bpy import os scene = alc.scene_object() texture_task = scene.copy(task='tex').latest_version() texture_task = texture_task.copy(version=texture_task.next_minor_version_number(), filename='') # print(texture_task_next.path_root) os.makedirs(texture_task.path_root) os.makedirs(texture_task.copy(context='render').path_root) ignore_list = ['b_painter_brush_img', 'Render Result'] for image in bpy.data.images: filename = image.name.split(':') if len(filename) > 1: filename = filename[1] if image.name not in ignore_list: out_path = texture_task.copy(filename=filename, context='render', ext='exr').path_root image.save_render(out_path) image.filepath = out_path alc.save_file_as(texture_task.copy(context='source', set_proper_filename=True).path_root) alc.confirm_prompt(message='textures exported!!! ')
def switch_user(user): import os from cgl.plugins.blender.utils import get_scene_collection, get_object, load_library, purge_unused_data, \ set_all_paths_relative from cgl.plugins.blender.msd import path_object_from_source_path selection = bpy.context.selected_objects set_all_paths_relative(False) for object in selection: library = object['source_path'] lumber_object = path_object_from_source_path(library) latest_version = lumber_object.copy(user=user, context='render').latest_version() if latest_version.task == 'mdl': print(latest_version.path_root) load_library(latest_version) collection = get_collection_from_path_object(path_object=latest_version) print(collection) object.instance_collection = collection purge_unused_data() alc.confirm_prompt(message='{} update to {}'.format(latest_version.asset, latest_version.version)) set_all_paths_relative(True)
def execute(self, context): self.report({'INFO'}, "Selected: %s" % self.selected_task) if self.selected_task == 'Base Mesh': new_task = alc.scene_object().copy( context='render', task='mdl', type='lib', asset='baseMesh', user='******', set_proper_filename=True).latest_version().path_root else: new_task = alc.scene_object().copy( context='render', task=self.selected_task, user='******', set_proper_filename=True).latest_version().path_root if os.path.isfile(new_task): print(new_task) alc.import_file(new_task, linked=True, append=False) else: alc.confirm_prompt( message= 'publish not found, please check if the task has been published or import manually ' ) return {'FINISHED'}
def run(): get_default_shader() failed_items = [] for obj in get_valid_meshes(): assign_default(obj) selection = bpy.data.materials print(len(selection)) for material in selection: if 'cs_' not in material.name: if material.use_nodes: print(selection) failed = updateShader(material) if len(failed): for m in failed: failed_items.append(m.name) if len(failed_items): print(5 * '_' + 'Failed Materials' + 5 * '_') for i in failed_items: print(i) alc.confirm_prompt( message='Failed materials : {}'.format(failed_items)) else: alc.confirm_prompt(message='Default shader assigned') delete_duplicate_groups('DEFAULTSHADER') delete_duplicate_groups('toon_material')
def run(): """ This run statement is what's executed when your button is pressed in blender. :return: """ from cgl.plugins.blender import alchemy as alc import bpy import os scene = alc.scene_object() texture_task = scene.copy(task='tex').latest_version() texture_task = texture_task.copy( version=texture_task.next_minor_version_number(), filename='') # print(texture_task_next.path_root) os.makedirs(texture_task.path_root) os.makedirs(texture_task.copy(context='render').path_root) for image in bpy.data.images: out_path = texture_task.copy(filename=image.name, context='render').path_root image.save_render(out_path) alc.save_file_as( texture_task.copy(context='source', set_proper_filename=True).path_root) alc.confirm_prompt(message='textures exported!!! ')
def run(): """ This run statement is what's executed when your button is pressed in blender. :return: """ try: read_materials() except FileNotFoundError: alc.confirm_prompt( message='the latest shader task is empty please export shader again' )
def versionToLatest(): from cgl.plugins.blender.utils import get_scene_collection, get_object, load_library, purge_unused_data, \ set_all_paths_relative from cgl.plugins.blender.msd import tag_object from cgl.plugins.blender.msd import path_object_from_source_path, tag_object selection = bpy.context.selected_objects set_all_paths_relative(False) purge_unused_data() if not selection: selection = bpy.data.libraries for obj in selection: if obj.type == 'EMPTY': if 'proxy' in obj.name: obj = bpy.data.objects[obj.name.replace('_proxy', '')] print(obj) object = get_object(obj) try: library = object['source_path'] except: print('ERROR ON {}'.format(obj)) continue lumber_object = path_object_from_source_path(library) latest_version = lumber_object.latest_version().copy(context='render') print(latest_version.path_root) if latest_version.task == 'mdl': load_library(latest_version) collection = get_collection_from_path_object(path_object=latest_version) # print(222222222222222222) # print(collection) obj.instance_collection = collection tag_object(obj, 'source_path', latest_version.path) if latest_version.task == 'rig': library = obj.instance_collection.library library.filepath = latest_version.path_root library.reload() tag_object(obj, 'source_path', latest_version.path) set_all_paths_relative(True) alc.confirm_prompt(message='{} update to {}'.format(latest_version.asset, latest_version.version))
def run(): """ This run statement is what's executed when your button is pressed in blender. :return: """ selection = bpy.context.selected_objects if not selection: alc.confirm_prompt(message='please select an object') for obj in selection: obj.data.name = '{}_mesh'.format(obj.name) alc.confirm_prompt(message='Mesh data renamed!')
def run(): """ This run statement is what's executed when your button is pressed in blender. :return: """ objects = get_selection_order() if len(objects) == 2: copy_vertex_weight() remove_controllers(objects[0]) bpy.ops.object.cleanup_weights() else: alc.confirm_prompt(message='please select source and destination mesh')
def run(): """ This run statement is what's executed when your button is pressed in blender. :return: """ path_object = utils.create_task_on_asset('shd') jsonFile = path_object.copy(ext='json') outFile = path_object.copy(ext='json').path_root print(path_object.path_root) save_json(outFile, data=utils.get_materials_dictionary()) alc.save_file_as(path_object.copy(set_proper_filename=True).path_root) bpy.ops.object.build() alc.save_file() alc.confirm_prompt(message='Shaders Exported !!')
def run(): """ This run statement is what's executed when your button is pressed in blender. :return: """ if bpy.context.selected_objects: try: bpy.ops.object.delete_defaults() bpy.ops.object.delete_turntable() except AttributeError: print('no objects to delete') alc.create_turntable() get_default_lighting() else: alc.confirm_prompt(message='Please select geo')
def run(): """ This run statement is what's executed when your button is pressed in blender. :return: """ from cgl.plugins.blender import msd, utils from cgl.plugins.blender.alchemy import scene_object task = 'mdl' utils.cleanup_file(task) collection = utils.get_scene_collection() collection.name = collection.name.replace( ':{}'.format(scene_object().task), ':{}'.format(task)) mdl_task = utils.save_to_task('mdl') alc.confirm_prompt('file exported to mdl task user: {} version: {}'.format( mdl_task.user, mdl_task.version))
def switch_context(): import os scene = alc.scene_object() if scene.context == 'source': newpath = scene.copy(context='render') else: newpath = scene.copy(context='source') if os.path.isdir(newpath.copy(filename='').path_root): alc.open_file(newpath.path_root) else: alc.confirm_prompt(message='ERROR no such directory')
def renanme_action(): objects = bpy.context.selected_objects # selected_object = bpy.context.object for selected_object in objects: action = selected_object.animation_data.action if action: currentScene = alc.scene_object() newActionName = '_'.join([ currentScene.filename_base, selected_object.name, currentScene.version ]) action.name = newActionName print(newActionName) else: alc.confirm_prompt(message='No action linked to object')
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')
def run(): """ This run statement is what's executed when your button is pressed in blender. :return: """ scene = alc.scene_object() if scene.context == 'source': if scene.resolution == 'high': alc.launch_preflight() else: alc.confirm_prompt( message= "This is a low resolution version , please publish high file") else: alc.confirm_prompt( message= "files in the render context shouldn't be published please switch to source file" )
def execute(self, context): self.report({'INFO'}, "Selected: %s" % self.selected_task) new_user = alc.scene_object().copy( task=self.selected_task, set_proper_filename=True).latest_version().path_root if os.path.isfile(new_user): alc.open_file(new_user) else: new_user = alc.scene_object().copy( task=self.selected_task, user='******', set_proper_filename=True).latest_version().path_root if os.path.isfile(new_user): alc.open_file(new_user) else: alc.confirm_prompt( message='file des not exist, please check manually ') return {'FINISHED'}
def run(): """ This run statement is what's executed when your button is pressed in blender. :return: """ scene = alc.scene_object() if scene.context == 'source': if scene.resolution == 'high': alc.version_up() bpy.ops.file.make_paths_relative() low_res = alc.scene_object().copy(resolution='low') for res in low_res.glob_project_element('filename'): create_file_dirs(res) cgl_copy(res.path_root, low_res.path_root) alc.confirm_prompt(message="Version up to {}".format(alc.scene_object().version)) else: alc.confirm_prompt(message="This is a low resolution version , please edit source file") else: alc.confirm_prompt(message="files in the render context shouldn't be versioned up, please edit source file")
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 convert_low_to_main_collection(assetName=''): if assetName == '': assetName = alc.scene_object().shot for collection in bpy.data.collections: if collection.name == assetName: collection.name = '{}_high'.format(assetName) elif collection.name == '{}_low'.format(assetName): collection.name = assetName elif alc.scene_object().resolution == 'low': alc.confirm_prompt( message= 'ALERT: you are currently in the low version nothing to do here' ) elif alc.scene_object().resolution == 'high': alc.confirm_prompt( title='ERROR', message= 'ERROR: no low collection found, please create {}_low collection' .format(assetName))
object = lay.import_rig(path_object) from cgl.plugins.blender.utils import parent_object else: object = alc.reference_file(path_object.path_root, namespace=path_object.asset) parent_object(object, get_layer('MAIN')) print(object) cursor = bpy.context.scene.cursor.location print(object.location) print(cursor) object.location = cursor else: alc.confirm_prompt(message='This file doesnt exist, please check for sync or review for errors') # if alc.scene_object().type is not 'env': # bpy.ops.object.setup_collections() self.report({'INFO'}, message) return {'FINISHED'} def invoke(self, context, event): wm = context.window_manager return wm.invoke_props_dialog(self) bpy.utils.register_class(DialogUserB)
def execute(self, context): # my_users = bpy.props.EnumProperty(items = split_string(self.my_string)) path_object = get_asset_from_name( bpy.types.Scene.scene_enum.replace('publish', self.users)) path_object = path_object.copy(task=self.task, variant=self.variant, set_proper_filename=True) path_object = path_object.latest_version().copy( set_proper_filename=True) render = path_object.copy(context='render') if os.path.isfile(render.path_root): path_object = render open_file = path_object.path_root message = 'selected {}'.format(open_file) try: bpy.ops.object.mode_set(mode='OBJECT') except RuntimeError: pass if os.path.isfile((open_file)): from cgl.core.path import PathObject file_to_be_imported = PathObject(open_file) if file_to_be_imported.task == 'bndl': from cgl.plugins.blender.tasks import bndl bndl.bundle_import(file_to_be_imported.msd_path) return if path_object.type in [ 'char', ] and path_object.task == 'rig': print(path_object.path_root) object = lay.import_rig(path_object) else: from cgl.plugins.blender.utils import get_object, parent_object, get_scene_object from cgl.plugins.blender import alchemy as alc object = alc.reference_file(path_object.path_root) main = get_layer('MAIN') if not main: try: main = get_scene_object() parent_object(object, main) except: alc.confirm_prompt('please click on build') print(object) cursor = bpy.context.scene.cursor.location print(object.location) print(cursor) object.location = cursor else: alc.confirm_prompt( message= 'This file doesnt exist, please check for sync or review for errors' ) # if alc.scene_object().type is not 'env': # bpy.ops.object.setup_collections() self.report({'INFO'}, message) return {'FINISHED'}