61 lines
1.7 KiB
Python
61 lines
1.7 KiB
Python
import bpy
|
|
from . import fn
|
|
|
|
class GPEXP_OT_number_outputs(bpy.types.Operator):
|
|
bl_idname = "gp.number_outputs"
|
|
bl_label = "Number Outputs"
|
|
bl_description = "(Re)Number the outputs to have ordered file by name in export directories\nCtrl+Clic : Delete numbering"
|
|
bl_options = {"REGISTER"}
|
|
|
|
@classmethod
|
|
def poll(cls, context):
|
|
return True
|
|
|
|
mode : bpy.props.StringProperty(default='SELECTED', options={'SKIP_SAVE'})
|
|
# ctrl : bpy.props.StringProperty(default=False, options={'SKIP_SAVE'}) # no need
|
|
|
|
def invoke(self, context, event):
|
|
self.ctrl = event.ctrl
|
|
return self.execute(context)
|
|
|
|
def execute(self, context):
|
|
render = bpy.data.scenes.get('Render')
|
|
if not render:
|
|
print('SKIP, no Render scene')
|
|
return {"CANCELLED"}
|
|
|
|
ct = 0
|
|
nodes = render.node_tree.nodes
|
|
for fo in nodes:
|
|
if fo.type != 'OUTPUT_FILE':
|
|
continue
|
|
if self.mode == 'SELECTED' and not fo.select:
|
|
continue
|
|
# print(f'numbering {fo.name}')
|
|
ct += 1
|
|
if self.ctrl:
|
|
fn.delete_numbering(fo)
|
|
else:
|
|
fn.renumber_keep_existing(fo)
|
|
# fn.renumber(fo)
|
|
|
|
txt = 'de-numbered' if self.ctrl else 're-numbered'
|
|
if ct:
|
|
self.report({'INFO'}, f'{ct} output nodes {txt}')
|
|
else:
|
|
self.report({'ERROR'}, f'No output nodes {txt}')
|
|
|
|
return {"FINISHED"}
|
|
|
|
|
|
classes=(
|
|
GPEXP_OT_number_outputs,
|
|
)
|
|
|
|
def register():
|
|
for cls in classes:
|
|
bpy.utils.register_class(cls)
|
|
|
|
def unregister():
|
|
for cls in reversed(classes):
|
|
bpy.utils.unregister_class(cls) |