2021-09-17 16:31:26 +02:00
|
|
|
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"}
|
2021-09-21 18:23:25 +02:00
|
|
|
|
|
|
|
class GPEXP_OT_lower_layers_name(bpy.types.Operator):
|
|
|
|
bl_idname = "gp.lower_layers_name"
|
2021-09-22 12:06:40 +02:00
|
|
|
bl_label = "Normalize Layers Name"
|
|
|
|
bl_description = "Make the object and layers name lowercase with dashed converted to underscore (without touching layer prefix and suffix)"
|
2021-09-21 18:23:25 +02:00
|
|
|
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'}
|
|
|
|
|
2021-09-22 12:06:40 +02:00
|
|
|
object_name : BoolProperty(name='Normalize Object Name',
|
2021-09-21 18:23:25 +02:00
|
|
|
default=True, description='Make the object name lowercase') # , options={'SKIP_SAVE'}
|
|
|
|
|
2021-09-22 12:06:40 +02:00
|
|
|
layer_name : BoolProperty(name='Normalize Layers Names',
|
2021-09-21 18:23:25 +02:00
|
|
|
default=True, description='Make the layers name lowercase') # , options={'SKIP_SAVE'}
|
2021-09-22 12:06:40 +02:00
|
|
|
|
|
|
|
# dash_to_undescore : BoolProperty(name='Dash To Underscore',
|
|
|
|
# default=True, description='Make the layers name lowercase') # , options={'SKIP_SAVE'}
|
2021-09-21 18:23:25 +02:00
|
|
|
|
|
|
|
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')
|
2021-09-22 12:06:40 +02:00
|
|
|
# if self.layer_name:
|
|
|
|
# box = layout.box()
|
|
|
|
# box.prop(self, 'dash_to_undescore')
|
|
|
|
|
2021-09-21 18:23:25 +02:00
|
|
|
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
|
2021-09-22 12:06:40 +02:00
|
|
|
ob.name = ob.name.lower().replace('-', '_')
|
2021-09-21 18:23:25 +02:00
|
|
|
if rename_data:
|
2021-09-22 12:06:40 +02:00
|
|
|
ob.data.name = ob.name
|
2021-09-21 18:23:25 +02:00
|
|
|
|
|
|
|
if self.layer_name:
|
|
|
|
for l in ob.data.layers:
|
2021-09-22 12:28:35 +02:00
|
|
|
# if self.dash_to_undescore:
|
|
|
|
l.info = l.info.replace('-', '_')
|
2021-09-22 12:06:40 +02:00
|
|
|
fn.normalize_layer_name(l) # default : lower=True, dash_to_underscore=self.dash_to_undescore
|
2021-09-21 18:23:25 +02:00
|
|
|
|
|
|
|
return {"FINISHED"}
|
|
|
|
|
2021-09-17 16:31:26 +02:00
|
|
|
classes=(
|
|
|
|
GPEXP_OT_layers_state,
|
2021-09-21 18:23:25 +02:00
|
|
|
GPEXP_OT_lower_layers_name
|
2021-09-17 16:31:26 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
def register():
|
|
|
|
for cls in classes:
|
|
|
|
bpy.utils.register_class(cls)
|
|
|
|
|
|
|
|
def unregister():
|
|
|
|
for cls in reversed(classes):
|
|
|
|
bpy.utils.unregister_class(cls)
|