add environnement variable
1.5.2
- add environnement variables to set addon preferences project settings at register through `os.getenv('KEY')`:
- `RENDER_WIDTH` : resolution x
- `RENDER_HEIGHT` : resolution y
- `FPS` : project frame rate
- `PALETTES` : path to the blends (or json) containing materials palettes
- `BRUSHES` : path to the blend containing brushes to load
This commit is contained in:
+51
-6
@@ -15,7 +15,7 @@ bl_info = {
|
||||
"name": "GP toolbox",
|
||||
"description": "Set of tools for Grease Pencil in animation production",
|
||||
"author": "Samuel Bernou, Christophe Seux",
|
||||
"version": (1, 5, 1),
|
||||
"version": (1, 5, 2),
|
||||
"blender": (2, 91, 0),
|
||||
"location": "Sidebar (N menu) > Gpencil > Toolbox / Gpencil properties",
|
||||
"warning": "",
|
||||
@@ -66,6 +66,7 @@ from bpy.props import (FloatProperty,
|
||||
IntProperty)
|
||||
|
||||
import bpy
|
||||
import os
|
||||
from bpy.app.handlers import persistent
|
||||
from pathlib import Path
|
||||
# from .eyedrop import EyeDropper
|
||||
@@ -205,11 +206,23 @@ class GPTB_prefs(bpy.types.AddonPreferences):
|
||||
description="Character delimiter to use for detecting namespace (prefix), default is '_', space if nothing specified",
|
||||
default="_", maxlen=0, subtype='NONE')
|
||||
|
||||
use_env_palettes : BoolProperty(
|
||||
name="Use Project Palettes",
|
||||
description="Load the palette path in environnement at startup (key 'PALETTES')",
|
||||
default=True,
|
||||
)
|
||||
|
||||
palette_path : StringProperty(
|
||||
name="Palettes directory",
|
||||
description="Path to palette containing palette.json files to save and load",
|
||||
default="//", maxlen=0, subtype='DIR_PATH')#, update = set_palette_path
|
||||
|
||||
use_env_brushes : BoolProperty(
|
||||
name="Use Project Brushes",
|
||||
description="Load the brushes path in environnement at startup (key 'BRUSHES')",
|
||||
default=True,
|
||||
)
|
||||
|
||||
brush_path : StringProperty(
|
||||
name="Brushes directory",
|
||||
description="Path to brushes containing the blends holding the brushes",
|
||||
@@ -336,13 +349,20 @@ class GPTB_prefs(bpy.types.AddonPreferences):
|
||||
row.label(text='Render Resolution')
|
||||
row.prop(self, 'render_res_x', text='Width')
|
||||
row.prop(self, 'render_res_y', text='Height')
|
||||
|
||||
## Palette
|
||||
box.label(text='Project folders:')
|
||||
box.prop(self, 'palette_path')
|
||||
box.prop(self, 'brush_path')
|
||||
|
||||
subbox = box.box()
|
||||
subbox.prop(self, 'use_env_palettes', text='Use Palettes Environnement Path')
|
||||
subbox.prop(self, 'palette_path')
|
||||
|
||||
## Brushes
|
||||
subbox.prop(self, 'use_env_brushes', text='Use Brushes Environnement Path')
|
||||
subbox.prop(self, 'brush_path')
|
||||
|
||||
## render output
|
||||
box.prop(self, 'output_path')
|
||||
subbox.prop(self, 'output_path')
|
||||
box.prop(self, 'use_relative_remap_on_save')
|
||||
|
||||
### TODO add render settings
|
||||
@@ -465,6 +485,30 @@ class GPTB_prefs(bpy.types.AddonPreferences):
|
||||
addon_updater_ops.update_settings_ui(self, context)
|
||||
|
||||
|
||||
|
||||
### --- ENV_PROP ---
|
||||
|
||||
def set_env_properties():
|
||||
prefs = get_addon_prefs()
|
||||
|
||||
fps = os.getenv('FPS')
|
||||
prefs.fps = fps if fps else prefs.fps
|
||||
|
||||
render_height = os.getenv('RENDER_HEIGHT')
|
||||
prefs.render_res_x = render_height if render_height else prefs.render_res_x
|
||||
|
||||
render_width = os.getenv('RENDER_WIDTH')
|
||||
prefs.render_res_y = render_width if render_width else prefs.render_res_y
|
||||
|
||||
palettes = os.getenv('PALETTES')
|
||||
if prefs.use_env_palettes:
|
||||
prefs.palette_path = palettes if palettes else prefs.palette_path
|
||||
|
||||
brushes = os.getenv('BRUSHES')
|
||||
if prefs.use_env_brushes:
|
||||
prefs.brush_path = brushes if brushes else prefs.brush_path
|
||||
|
||||
|
||||
### --- REGISTER ---
|
||||
|
||||
# class GP_PG_ToolsSettings(bpy.types.PropertyGroup) :
|
||||
@@ -509,8 +553,9 @@ def register():
|
||||
keymaps.register()
|
||||
bpy.types.Scene.gptoolprops = bpy.props.PointerProperty(type = GP_PG_ToolsSettings)
|
||||
|
||||
# add handler (if option is on)
|
||||
|
||||
set_env_properties()
|
||||
|
||||
## add handler (if option is on)
|
||||
if get_addon_prefs().use_relative_remap_on_save:
|
||||
if not 'remap_relative' in [hand.__name__ for hand in bpy.app.handlers.save_pre]:
|
||||
bpy.app.handlers.save_pre.append(remap_relative)
|
||||
|
||||
Reference in New Issue
Block a user