import bpy from .import gen_vlayer class GPEXP_OT_add_layer_to_render(bpy.types.Operator): bl_idname = "gp.add_layer_to_render" bl_label = "Add Gp Layer as render nodes" bl_description = "Create a view_layer for GP > add node > connect to output" bl_options = {"REGISTER"} @classmethod def poll(cls, context): return context.object and context.object.type == 'GPENCIL' # mode : bpy.props.StringProperty(options={'SKIP_SAVE'}) def execute(self, context): ob = context.object layer = ob.data.layers.active if not layer: self.report({'ERROR'}, 'No active layer') return {"CANCELLED"} ct = 0 # send scene ? for l in ob.data.layers: if not l.select: continue gen_vlayer.get_set_viewlayer_from_gp(ob, l) ct += 1 if ct: self.report({'INFO'}, f'{ct} layer(s) added to scene "Render"') return {"FINISHED"} def export_gp_objects(oblist, exclude_list=['MA', 'IN']): # Skip layer containing element in excluyde list if not isinstance(oblist, list): oblist = [oblist] for ob in oblist: for l in ob.data.layers: if any(x + '_' in l.info for x in exclude_list): continue if l.hide: continue vl, cp = gen_vlayer.get_set_viewlayer_from_gp(ob, l) # scene=fn.get_render_scene()) ## send operator with mode ALL or SELECTED to batch build class GPEXP_OT_add_objects_to_render(bpy.types.Operator): bl_idname = "gp.add_object_to_render" bl_label = "Add all Gp Layer of active object as render nodes" bl_description = "Setup GP object in render scene\nNote: 'send all' mode skip hided objects" bl_options = {"REGISTER"} @classmethod def poll(cls, context): return context.object and context.object.type == 'GPENCIL' mode : bpy.props.StringProperty(default='ALL', options={'SKIP_SAVE'}) def execute(self, context): if self.mode == 'SELECTED': export_gp_objects([o for o in context.selected_objects if o.type == 'GPENCIL']) elif self.mode == 'ALL': scn = bpy.data.scenes.get('Scene') if not scn: self.report({'ERROR'}, 'Could not found default scene') return {"CANCELLED"} export_gp_objects([o for o in scn.objects if o.type == 'GPENCIL' and not o.hide_get()]) return {"FINISHED"} classes=( GPEXP_OT_add_layer_to_render, GPEXP_OT_add_objects_to_render, ) def register(): for cls in classes: bpy.utils.register_class(cls) def unregister(): for cls in reversed(classes): bpy.utils.unregister_class(cls)