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)
This commit is contained in:
		
							parent
							
								
									dd57f0651e
								
							
						
					
					
						commit
						d99199ed48
					
				| @ -17,6 +17,8 @@ Activate / deactivate all masks using MA layers | |||||||
| 1.1.1 | 1.1.1 | ||||||
| 
 | 
 | ||||||
| - changed: autobuild beta | - 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 | 1.1.0 | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -1,4 +1,5 @@ | |||||||
| import bpy | import bpy | ||||||
|  | import re | ||||||
| from pathlib import Path | from pathlib import Path | ||||||
| from . import gen_vlayer, fn | 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', |         name='Excluded Layer By Prefix', default='GP,RG,PO', | ||||||
|         description='Exclude layer to send to render by prefix (comma separated list)') |         description='Exclude layer to send to render by prefix (comma separated list)') | ||||||
| 
 | 
 | ||||||
|     ## TODO: add props to fine tune the auto-build |     timer : bpy.props.FloatProperty(default=0.01, options={'SKIP_SAVE'}) | ||||||
|     # mode : bpy.props.StringProperty(options={'SKIP_SAVE'}) |  | ||||||
| 
 | 
 | ||||||
|     def execute(self, context): |     def execute(self, context): | ||||||
|         print('-- Auto-build Render scene --\n') |         print('-- Auto-build Render scene --\n') | ||||||
|         ## TODO: Add colors to layers (specified in ENV or hardcoded for now...) |         ## 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!) |         ## 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') |         render_scn = bpy.data.scenes.get('Render') | ||||||
|         if render_scn: |         if render_scn: | ||||||
|             self.report({'ERROR'}, 'A "Render" scene already exists') |             self.report({'ERROR'}, 'A "Render" scene already exists') | ||||||
|             return {'CANCELLED'} |             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)] |         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: |         if not ob_list: | ||||||
|             self.report({'ERROR'}, 'No GP object to render found') |             self.report({'ERROR'}, 'No GP object to render found') | ||||||
|             return {'CANCELLED'} |             return {'CANCELLED'} | ||||||
|  | 
 | ||||||
|         print('GP objects to send:') |         print('GP objects to send:') | ||||||
|         for o in ob_list: |         for o in ob_list: | ||||||
|             print(f' - {o.name}') |             print(f' - {o.name}') | ||||||
| 
 | 
 | ||||||
|  |         # Set layers colors (skip if colors were already set ?) | ||||||
|  |         fn.set_layer_colors(skip_if_colored=True) | ||||||
|  | 
 | ||||||
|         ## Trigger rename lowercase |         ## Trigger rename lowercase | ||||||
|         print('Trigger rename lowercase') |         print('Trigger rename lowercase') | ||||||
|         bpy.ops.gp.lower_layers_name('EXEC_DEFAULT') |         bpy.ops.gp.lower_layers_name('EXEC_DEFAULT') | ||||||
| @ -134,7 +156,7 @@ class GPEXP_OT_render_auto_build(bpy.types.Operator): | |||||||
|                 if ret != {'FINISHED'}: |                 if ret != {'FINISHED'}: | ||||||
|                     print('No GP render workspace available') |                     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 ? |         ## Trigger check file before finishing ? | ||||||
|         # bpy.ops.gp.check_render_scene('INVOKE_DEFAULT') |         # bpy.ops.gp.check_render_scene('INVOKE_DEFAULT') | ||||||
|  | |||||||
| @ -2,7 +2,7 @@ bl_info = { | |||||||
|     "name": "GP Render", |     "name": "GP Render", | ||||||
|     "description": "Organise export of gp layers through compositor output", |     "description": "Organise export of gp layers through compositor output", | ||||||
|     "author": "Samuel Bernou", |     "author": "Samuel Bernou", | ||||||
|     "version": (1, 1, 0), |     "version": (1, 1, 1), | ||||||
|     "blender": (2, 93, 0), |     "blender": (2, 93, 0), | ||||||
|     "location": "View3D", |     "location": "View3D", | ||||||
|     "warning": "", |     "warning": "", | ||||||
|  | |||||||
							
								
								
									
										32
									
								
								fn.py
									
									
									
									
									
								
							
							
						
						
									
										32
									
								
								fn.py
									
									
									
									
									
								
							| @ -1545,3 +1545,35 @@ def set_scene_output_from_active_fileout_item(): | |||||||
|             continue |             continue | ||||||
|         if hasattr(scn.render.image_settings, attr) and not scn.render.image_settings.is_property_readonly(attr): |         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)) |             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 | ||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user