diff --git a/CHANGELOG.md b/CHANGELOG.md index 4aad74a..03968c8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,11 @@ Activate / deactivate layer opacity according to prefix Activate / deactivate all masks using MA layers --> +1.2.1 + +- added: bundle app_template to load "GR Render" workspace from it +- added: ui button in dopesheet to load GP render workspace if not loaded + 1.2.0 - changed: enabled when launched in background diff --git a/OP_auto_build.py b/OP_auto_build.py index 71346b6..b218ddf 100644 --- a/OP_auto_build.py +++ b/OP_auto_build.py @@ -241,24 +241,11 @@ class GPEXP_OT_render_auto_build(bpy.types.Operator): if (render_wkspace := bpy.data.workspaces.get('GP Render')): context.window.workspace = render_wkspace else: - render_wkspace_filepath = Path(bpy.utils.user_resource('SCRIPTS'), 'startup', 'bl_app_templates_user', 'GP', 'startup.blend') - ret = bpy.ops.workspace.append_activate(idname='GP Render', filepath=str(render_wkspace_filepath)) - - if ret != {'FINISHED'}: - print(f'Fallback to addon stored workspaces: (No "GP Render" found in {render_wkspace_filepath})') - # Fallback to workspace template shipped with addon (TODO : add template blend file in addon) - render_wkspace_filepath = Path(__file__).parent / 'workspaces' / 'startup.blend' - ret = bpy.ops.workspace.append_activate(idname='GP Render', filepath=str(render_wkspace_filepath)) - - if ret != {'FINISHED'}: + ret = fn.activate_workspace('GP Render') + # render_wkspace_filepath = Path(__file__).parent / 'app_templates' / 'GP_render' / 'startup.blend' + # ret = bpy.ops.workspace.append_activate(idname='GP Render', filepath=str(render_wkspace_filepath)) + if not ret: print('No GP render workspace available') - - ## extra retry after append activate ?... - if ret == {'FINISHED'}: - render_wkspace = bpy.data.workspaces.get('GP Render') - if render_wkspace: - context.window.workspace = render_wkspace - # context.workspace.update_tag() # context.scene.update_tag() diff --git a/OP_scene_switch.py b/OP_scene_switch.py index cbd08d2..1f096e2 100644 --- a/OP_scene_switch.py +++ b/OP_scene_switch.py @@ -89,9 +89,20 @@ class GPEXP_OT_swap_render_cams(bpy.types.Operator): return {"FINISHED"} +class GPEXP_OT_set_gp_render_workspace(bpy.types.Operator): + bl_idname = "gp.set_gp_render_workspace" + bl_label = 'Set GP Render Workspace' + bl_description = "Switch to GP render workspace, append and activate if not exists" + bl_options = {'REGISTER', 'INTERNAL'} + + def execute(self, context): + fn.activate_workspace(name='GP Render', context=context) + return {"FINISHED"} + classes=( GPEXP_OT_render_scene_switch, GPEXP_OT_swap_render_cams, +GPEXP_OT_set_gp_render_workspace, ) def register(): diff --git a/__init__.py b/__init__.py index 367dd9c..9858036 100644 --- a/__init__.py +++ b/__init__.py @@ -2,7 +2,7 @@ bl_info = { "name": "GP Render", "description": "Organise export of gp layers through compositor output", "author": "Samuel Bernou", - "version": (1, 2, 0), + "version": (1, 2, 1), "blender": (2, 93, 0), "location": "View3D", "warning": "", diff --git a/app_templates/GP_Render/__init__.py b/app_templates/GP_Render/__init__.py new file mode 100644 index 0000000..6bf597c --- /dev/null +++ b/app_templates/GP_Render/__init__.py @@ -0,0 +1,22 @@ +import bpy +from bpy.app.handlers import persistent + +@persistent +def setup_gp_render_workspace(): + + scn = bpy.context.scene + if not scn.camera: + scn.camera = next((o for o in scn.objects if o.type == 'CAMERA'), None) + + # Use rendered preview shading. + for screen in bpy.data.screens: + for area in screen.areas: + for space in area.spaces: + if space.type == 'VIEW_3D': + space.region_3d.view_perspective = 'CAMERA' + +def register(): + bpy.app.handlers.load_post.append(setup_gp_render_workspace) + +def unregister(): + bpy.app.handlers.load_factory_startup_post.remove(setup_gp_render_workspace) \ No newline at end of file diff --git a/app_templates/GP_Render/startup.blend b/app_templates/GP_Render/startup.blend new file mode 100644 index 0000000..ce86047 Binary files /dev/null and b/app_templates/GP_Render/startup.blend differ diff --git a/fn.py b/fn.py index b2c9457..b119f92 100644 --- a/fn.py +++ b/fn.py @@ -92,6 +92,31 @@ def create_aa_nodegroup(tree): ## -- object and scene settings +def activate_workspace(name='', context=None): + if not name: + return + if context is None: + context = bpy.context + + if context.window.workspace.name == name: + print(f'Already in {name} workspace') + return + + if (wkspace := bpy.data.workspaces.get(name)): + context.window.workspace = wkspace + return True + + # Same name with spaces as underscore + dir_name = name.replace(' ', '_') + filepath = Path(__file__).parent / 'app_templates' / dir_name / 'startup.blend' + + ret = bpy.ops.workspace.append_activate(idname=name, filepath=str(filepath)) + if ret != {'FINISHED'}: + print(f'Could not found {name} at {filepath}') + return False + + return context.window.workspace + def copy_settings(obj_a, obj_b): exclusion = ['bl_rna', 'id_data', 'identifier','name_property','rna_type','properties', 'stamp_note_text','use_stamp_note', 'settingsFilePath', 'settingsStamp', 'select', 'matrix_local', 'matrix_parent_inverse', @@ -706,7 +731,6 @@ def clean_nodegroup_inputs(ng, skip_existing_pass=True): # a render layer of this name still exists continue ngroup.inputs.remove(ngroup.inputs[i]) - # clear_nodegroup_content_if_disconnected(ngroup) def bridge_reconnect_nodegroup(ng, socket_name=None): diff --git a/gen_vlayer.py b/gen_vlayer.py index 9047793..098adef 100644 --- a/gen_vlayer.py +++ b/gen_vlayer.py @@ -222,7 +222,7 @@ def get_set_viewlayer_from_gp(ob, l, scene=None): else: scene = fn.get_render_scene() - print('Set viewlayer Scene: ', scene.name) + # print('Set viewlayer Scene: ', scene.name) node_tree = scene.node_tree nodes = node_tree.nodes diff --git a/ui.py b/ui.py index 8d8818d..5a1cb5c 100644 --- a/ui.py +++ b/ui.py @@ -1,5 +1,6 @@ import bpy from bpy.types import Panel +from pathlib import Path from .prefs import get_addon_prefs # from .preferences import get_addon_prefs @@ -122,7 +123,6 @@ class GPEXP_PT_gp_node_ui(Panel): if advanced: subcol.operator('gp.set_output_node_format', icon='OUTPUT', text='Copy Active Output Format') subcol.operator('gp.set_active_fileout_to_compout', icon='OUTPUT', text='Active Slot to Composite') - layout.separator() @@ -236,7 +236,11 @@ class GPEXP_PT_gp_dopesheet_ui(Panel): row = layout.row() row.operator('gp.export_as_pdf', icon='RENDER_STILL', text='Render All to PDF Sequences') if bpy.app.version < (3,0,0): - row.label(text='Not Blender 3.0.0') + row.label(text='Not Blender 3.0.0+') + + ## Append GP Render workspace (usefull for user with disabled 'load_UI') + if not bpy.data.workspaces.get('GP Render'): + layout.operator('gp.set_gp_render_workspace') class GPEXP_MT_multi_user_doc(bpy.types.Menu):