import bpy from bpy.props import (FloatProperty, BoolProperty, EnumProperty, StringProperty, IntProperty) from . import fn class GPEXP_OT_layers_state(bpy.types.Operator): bl_idname = "gp.layers_state" bl_label = "Set Layers State" bl_description = "Display state of layer that migh need adjustement" bl_options = {"REGISTER"} # , "UNDO" # clear_unused_view_layers :BoolProperty(name="Clear unused view layers", # description="Delete view layer that aren't used in the nodetree anymore", # default=True) # TODO : (optional) export layer opacity to json and/or text # (that way compo artists can re-affect opacity quickly or at least have a reminder) all_objects : BoolProperty(name='On All Object', default=False, description='On All object, else use selected objects') # , options={'SKIP_SAVE'} set_full_opacity : BoolProperty(name='Set Full Opacity', default=True, description='Check/Set full opacity') # , options={'SKIP_SAVE'} set_use_lights : BoolProperty(name='Disable Use Light', default=True, description='Check/Set use lights disabling') # , options={'SKIP_SAVE'} set_blend_mode : BoolProperty(name='Set Regular Blend Mode', default=True, description='Check/Set blend mode to regular') # , options={'SKIP_SAVE'} @classmethod def poll(cls, context): return context.object and context.object.type == 'GPENCIL' def invoke(self, context, event): # self.ctrl=event.ctrl # self.alt=event.alt if event.alt: self.all_objects=True # return self.execute(context) return context.window_manager.invoke_props_dialog(self) def draw(self, context): layout = self.layout layout.prop(self, 'all_objects') layout.separator() layout.label(text='Set (or only perform a check):') layout.prop(self, 'set_full_opacity') layout.prop(self, 'set_use_lights') layout.prop(self, 'set_blend_mode') # layout.prop(self, 'clear_unused_view_layers') def execute(self, context): if self.all_objects: pool = [o for o in context.scene.objects if o.type == 'GPENCIL'] else: pool = [o for o in context.selected_objects if o.type == 'GPENCIL'] # pool = [context.object] changes = [] for ob in pool: changes.append(f'>> {ob.name}') layers = ob.data.layers for l in layers: used = False ## mask check # if l.mask_layers: # print(f'-> masks') # state = '' if l.use_mask_layer else ' (disabled)' # print(f'{ob.name} > {l.info}{state}:') # used = True # for ml in l.mask_layers: # mlstate = ' (disabled)' if ml.hide else '' # mlinvert = ' <>' if ml.invert else '' # print(f'{ml.info}{mlstate}{mlinvert}') if l.opacity != 1: full_opacity_state = '' if self.set_full_opacity else ' (check only)' mess = f'{l.info} : opacity {l.opacity:.2f} >> 1.0{full_opacity_state}' print(mess) changes.append(mess) if self.set_full_opacity: l.opacity = 1.0 used = True if l.use_lights: use_lights_state = '' if self.set_use_lights else ' (check only)' mess = f'{l.info} : disable use lights{use_lights_state}' print(mess) changes.append(mess) if self.set_use_lights: l.use_lights = False used = True if l.blend_mode != 'REGULAR': blend_mode_state = '' if self.set_blend_mode else ' (check only)' mess = f'{l.info} : blend mode "{l.blend_mode}" >> regular{blend_mode_state}' print(mess) changes.append(mess) if self.set_blend_mode: l.blend_mode = 'REGULAR' used = True if used: print() if changes: changes.append('') fn.show_message_box(_message=changes, _title="Layers Check Report", _icon='INFO') # render = bpy.data.scenes.get('Render') # if not render: # print('SKIP, no Render scene') # return {"CANCELLED"} return {"FINISHED"} PATTERN = r'^(?P-\s)?(?P[A-Z]{2}_)?(?P.*?)(?P_[A-Z]{2})?(?P\.\d{3})?$' # numering def lower_layer_name(layer, prefix='', desc='', suffix=''): '''GET a layer and argumen to build and assign name''' import re name = layer.info pattern = PATTERN sep = '_' res = re.search(pattern, name.strip()) grp = '' if res.group('grp') is None else res.group('grp') tag = '' if res.group('tag') is None else res.group('tag') # tag2 = '' if res.group('tag2') is None else res.group('tag2') name = '' if res.group('name') is None else res.group('name') sfix = '' if res.group('sfix') is None else res.group('sfix') inc = '' if res.group('inc') is None else res.group('inc') if grp: grp = ' ' + grp # name is strip(), so grp first spaces are gones. if prefix: if prefix == 'prefixkillcode': tag = '' else: tag = prefix.upper().strip() + sep # if prefix2: # tag2 = prefix2.upper().strip() + sep if desc: name = desc if suffix: if suffix == 'suffixkillcode': sfix = '' else: sfix = sep + suffix.upper().strip() # check if name is available without the increment ending new = f'{grp}{tag}{name.lower()}{sfix}' # lower suffix ? if new != layer.info: print(f'{layer.info} >> new') layer.info = new class GPEXP_OT_lower_layers_name(bpy.types.Operator): bl_idname = "gp.lower_layers_name" bl_label = "Lower Layers Name" bl_description = "Make the layer name lowercase without touching prefix and suffix" bl_options = {"REGISTER", "UNDO"} @classmethod def poll(cls, context): return context.object and context.object.type == 'GPENCIL' all_objects : BoolProperty(name='On All Object', default=False, description='On All object, else use selected objects') # , options={'SKIP_SAVE'} object_name : BoolProperty(name='Lower Object Name', default=True, description='Make the object name lowercase') # , options={'SKIP_SAVE'} layer_name : BoolProperty(name='Lower Layers Names', default=True, description='Make the layers name lowercase') # , options={'SKIP_SAVE'} def invoke(self, context, event): # self.ctrl=event.ctrl # self.alt=event.alt if event.alt: self.all_objects=True # return self.execute(context) return context.window_manager.invoke_props_dialog(self) def draw(self, context): layout = self.layout layout.prop(self, 'all_objects') if self.all_objects: gp_ct = len([o for o in context.scene.objects if o.type == 'GPENCIL']) else: gp_ct = len([o for o in context.selected_objects if o.type == 'GPENCIL']) layout.label(text=f'{gp_ct} to lower-case') layout.separator() layout.label(text=f'Choose what to rename:') layout.prop(self, 'object_name') layout.prop(self, 'layer_name') if not self.object_name and not self.layer_name: layout.label(text=f'At least one choice!', icon='ERROR') def execute(self, context): if self.all_objects: pool = [o for o in context.scene.objects if o.type == 'GPENCIL'] else: pool = [o for o in context.selected_objects if o.type == 'GPENCIL'] for ob in pool: if self.object_name: rename_data = ob.name == ob.data.name ob.name = ob.name.lower() if rename_data: ob.data.name = ob.data.name.lower() if self.layer_name: for l in ob.data.layers: lower_layer_name(l) return {"FINISHED"} classes=( GPEXP_OT_layers_state, GPEXP_OT_lower_layers_name ) def register(): for cls in classes: bpy.utils.register_class(cls) def unregister(): for cls in reversed(classes): bpy.utils.unregister_class(cls)