From d99199ed48bc80052acf014ee73a4fbcf4f86993 Mon Sep 17 00:00:00 2001 From: pullusb Date: Tue, 10 Jan 2023 15:39:05 +0100 Subject: [PATCH] fix empty names - set color 1.1.1 - changed: autobuild beta - added: autobuild: fix layer name with empty desc (only prefix) - added: autobuild: Set layer color autoamtically (if not some already there) --- CHANGELOG.md | 2 ++ OP_auto_build.py | 28 +++++++++++++++++++++++++--- __init__.py | 2 +- fn.py | 34 +++++++++++++++++++++++++++++++++- 4 files changed, 61 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index efaeed0..d492663 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,8 @@ Activate / deactivate all masks using MA layers 1.1.1 - changed: autobuild beta +- added: autobuild: fix layer name with empty desc (only prefix) +- added: autobuild: Set layer color autoamtically (if not some already there) 1.1.0 diff --git a/OP_auto_build.py b/OP_auto_build.py index 431da25..de6cf4a 100644 --- a/OP_auto_build.py +++ b/OP_auto_build.py @@ -1,4 +1,5 @@ import bpy +import re from pathlib import Path from . import gen_vlayer, fn @@ -58,26 +59,47 @@ class GPEXP_OT_render_auto_build(bpy.types.Operator): name='Excluded Layer By Prefix', default='GP,RG,PO', description='Exclude layer to send to render by prefix (comma separated list)') - ## TODO: add props to fine tune the auto-build - # mode : bpy.props.StringProperty(options={'SKIP_SAVE'}) + timer : bpy.props.FloatProperty(default=0.01, options={'SKIP_SAVE'}) def execute(self, context): print('-- Auto-build Render scene --\n') ## TODO: Add colors to layers (specified in ENV or hardcoded for now...) ## Option: Maybe find a way to create a color from prefix hash ? (always give unique color with same prefix on other project!) + prefix_to_render = ['CO', 'CU', 'FX', 'TO', 'MA'] # TODO : add to preferences / environment var + render_scn = bpy.data.scenes.get('Render') if render_scn: self.report({'ERROR'}, 'A "Render" scene already exists') return {'CANCELLED'} + + ## clean name and visibility + for o in [o for o in context.scene.objects if o.type == 'GPENCIL']: + if o.hide_render: + print(f'skip: {o.name} hide render') + continue + for l in o.data.layers: + ## Clean name when layer has no name after prefix + if re.match(r'^[A-Z]{2}_$', l.info): + l.info = l.info + o.name.lower() + ## Make used prefix visible ? + if (res := re.search(r'^([A-Z]{2})_', l.info)): + if res.group(1) in prefix_to_render and l.hide == True: + print(f'{o.name} -> {l.info} : Switch visibility On') + l.hide = False + ob_list = [o for o in context.scene.objects if o.type == 'GPENCIL' and not o.hide_get() and fn.is_valid_name(o.name)] if not ob_list: self.report({'ERROR'}, 'No GP object to render found') return {'CANCELLED'} + print('GP objects to send:') for o in ob_list: print(f' - {o.name}') + # Set layers colors (skip if colors were already set ?) + fn.set_layer_colors(skip_if_colored=True) + ## Trigger rename lowercase print('Trigger rename lowercase') bpy.ops.gp.lower_layers_name('EXEC_DEFAULT') @@ -134,7 +156,7 @@ class GPEXP_OT_render_auto_build(bpy.types.Operator): if ret != {'FINISHED'}: print('No GP render workspace available') - bpy.app.timers.register(batch_setup_render_scene, first_interval=0.001) + bpy.app.timers.register(batch_setup_render_scene, first_interval=self.timer) ## Trigger check file before finishing ? # bpy.ops.gp.check_render_scene('INVOKE_DEFAULT') diff --git a/__init__.py b/__init__.py index 60a9aa4..287f021 100644 --- a/__init__.py +++ b/__init__.py @@ -2,7 +2,7 @@ bl_info = { "name": "GP Render", "description": "Organise export of gp layers through compositor output", "author": "Samuel Bernou", - "version": (1, 1, 0), + "version": (1, 1, 1), "blender": (2, 93, 0), "location": "View3D", "warning": "", diff --git a/fn.py b/fn.py index 2f88ab5..34f5ff6 100644 --- a/fn.py +++ b/fn.py @@ -1544,4 +1544,36 @@ def set_scene_output_from_active_fileout_item(): if attr.startswith('__') or attr.startswith('bl_') or attr in excluded: continue if hasattr(scn.render.image_settings, attr) and not scn.render.image_settings.is_property_readonly(attr): - setattr(scn.render.image_settings, attr, getattr(fmt, attr)) \ No newline at end of file + setattr(scn.render.image_settings, attr, getattr(fmt, attr)) + + +def set_layer_colors(skip_if_colored=False): + '''Set hardcoded color to grease pencil layer channel according to prefixes''' + + ## UW -> TO (here used fo CU): (0.015996, 0.246201, 0.246201) # Indigo + ## invisible (close to violet light) in UW: (0.246201, 0.132868, 0.496933) + prefix_color = { + # 'MA_': (0.09, 0.08, 0.46), # Vivid blue + 'MA_': (0.65, 0.4, 0.6), # Pink Light + + 'FX_': (0.12, 0.33, 0.58), # (0.3, 0.49, 0.63) # Blue Light + # 'CO_': (0.35, 0.0085, 0.25), + 'CO_': (0.5,0.1,0.5), # Clear Pink + # 'CU': (0.092070, 0.177356, 0.447959), # Blue clear + 'CU_': (0.02, 0.27, 0.27), # Indigo + } + + for ob in bpy.context.scene.objects: + if ob.type != 'GPENCIL': + continue + if skip_if_colored and any([has_channel_color(l) for l in ob.data.layers]): + continue + for l in ob.data.layers: + # if l.info.startswith(prefix_color.keys()): + color = prefix_color.get(l.info[:3]) + if not color: + continue + print(l.info, '->', color) + l.channel_color = color + + bpy.context.preferences.edit.use_anim_channel_group_colors = True \ No newline at end of file