Add preferences with default templates with option to set them from env (falling back to prefs) at startup
change default templates to use label instead of name
This commit is contained in:
@@ -0,0 +1,91 @@
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
import bpy
|
||||
import os
|
||||
|
||||
from bpy.props import (FloatProperty,
|
||||
BoolProperty,
|
||||
EnumProperty,
|
||||
StringProperty,
|
||||
IntProperty,
|
||||
PointerProperty,
|
||||
FloatVectorProperty)
|
||||
|
||||
from bpy.app.handlers import persistent
|
||||
|
||||
# region Preferences
|
||||
|
||||
class RT_prefs(bpy.types.AddonPreferences):
|
||||
bl_idname = __package__
|
||||
|
||||
use_env_base_path_templates : BoolProperty(
|
||||
name="Use Environment Base Path Templates",
|
||||
description="Use environmenet variables to set base path for file output templates\
|
||||
\nFollowing env variable are available:\
|
||||
\nRENDERTOOLBOX_EXR_PATH_TEMPLATE fo single base path file output\
|
||||
\nRENDERTOOLBOX_MULTILAYER_PATH_TEMPLATE for multilayer base path file output",
|
||||
default=True,
|
||||
)
|
||||
|
||||
base_path_template: StringProperty(
|
||||
name="Base Path Template",
|
||||
description="Template for base paths",
|
||||
default="//render/{node_label}/",
|
||||
)
|
||||
|
||||
base_path_multilayer_template: StringProperty(
|
||||
name="Base Path Multilayer Template",
|
||||
description="Template for base paths of multilayer files",
|
||||
default="//render/{node_label}/{node_label}_",
|
||||
)
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
layout.use_property_split = True
|
||||
layout.use_property_decorate = False
|
||||
|
||||
layout.prop(self, "use_env_base_path_templates", text="Use Environment Base Path Templates")
|
||||
col = layout.column()
|
||||
# col.active = not self.use_env_base_path_templates
|
||||
col.prop(self, "base_path_template", text="Base Path Template")
|
||||
col.prop(self, "base_path_multilayer_template", text="Base Path Multilayer Template")
|
||||
|
||||
if self.use_env_base_path_templates:
|
||||
col.separator()
|
||||
col.label(text="Environment variables will override above templates if set", icon='INFO')
|
||||
# col.label(text="RENDERTOOLBOX_EXR_PATH_TEMPLATE for single base path file output")
|
||||
# col.label(text="RENDERTOOLBOX_MULTILAYER_PATH_TEMPLATE for multilayer base path file output")
|
||||
col.label(text'If environment variables are not found, preferences will be used instead')
|
||||
|
||||
|
||||
# region Handlers
|
||||
|
||||
@persistent
|
||||
def set_render_toolbox_settings(dummy):
|
||||
## Handler for prefs to scene properties replications
|
||||
prefs = bpy.context.preferences.addons[__package__].preferences
|
||||
reset_scene_path_templates()
|
||||
|
||||
# region Register
|
||||
|
||||
classes = (
|
||||
RT_prefs,
|
||||
)
|
||||
|
||||
def register():
|
||||
for cls in classes:
|
||||
bpy.utils.register_class(cls)
|
||||
|
||||
# prefs = bpy.context.preferences.addons[__package__].preferences
|
||||
|
||||
if not 'set_render_toolbox_settings' in [hand.__name__ for hand in bpy.app.handlers.load_post]:
|
||||
bpy.app.handlers.load_post.append(set_render_toolbox_settings)
|
||||
|
||||
def unregister():
|
||||
if not 'set_render_toolbox_settings' in [hand.__name__ for hand in bpy.app.handlers.load_post]:
|
||||
bpy.app.handlers.load_post.remove(set_render_toolbox_settings)
|
||||
|
||||
for cls in reversed(classes):
|
||||
bpy.utils.unregister_class(cls)
|
||||
|
||||
# endregion
|
||||
Reference in New Issue
Block a user