Allow adding more Houdini vars

This commit is contained in:
Mustafa-Zarkash 2023-09-28 00:46:47 +03:00
parent 61ce75f0c9
commit 7197134954
5 changed files with 82 additions and 50 deletions

View file

@ -755,48 +755,58 @@ def get_camera_from_container(container):
return cameras[0]
def update_job_var_context():
"""Update $JOB to match current context.
def update_houdini_vars_context():
"""Update Houdini vars to match current context.
This will only do something if the setting is enabled in project settings.
"""
project_settings = get_current_project_settings()
job_var_settings = \
project_settings["houdini"]["general"]["update_job_var_context"]
houdini_vars_settings = \
project_settings["houdini"]["general"]["update_houdini_var_context"]
if job_var_settings["enabled"]:
if houdini_vars_settings["enabled"]:
houdini_vars = houdini_vars_settings["houdini_vars"]
# get and resolve job path template
job_path = StringTemplate.format_template(
job_var_settings["job_path"],
get_current_context_template_data()
)
job_path = job_path.replace("\\", "/")
# Remap AYON settings structure to OpenPype settings structure
# It allows me to use the same logic for both AYON and OpenPype
if isinstance(houdini_vars, list):
items = {}
for item in houdini_vars:
items.update({item["var"]: item["path"]})
if job_path == "":
# Set JOB path to HIP path if JOB path is enabled
# and has empty value.
job_path = os.environ["HIP"]
houdini_vars = items
current_job = hou.hscript("echo -n `$JOB`")[0]
for var, path in houdini_vars.items():
# get and resolve job path template
path = StringTemplate.format_template(
path,
get_current_context_template_data()
)
path = path.replace("\\", "/")
# sync both environment variables.
# because when opening new file $JOB is overridden with
# the value saved in the HIP file but os.environ["JOB"] is not!
os.environ["JOB"] = current_job
if var == "JOB" and path == "":
# sync $JOB to $HIP if $JOB is empty
path = os.environ["HIP"]
if current_job != job_path:
hou.hscript("set JOB=" + job_path)
os.environ["JOB"] = job_path
current_path = hou.hscript("echo -n `${}`".format(var))[0]
try:
os.makedirs(job_path)
except OSError as e:
if e.errno != errno.EEXIST:
print(
" - Failed to create JOB dir. Maybe due to "
"insufficient permissions."
)
# sync both environment variables.
# because houdini doesn't do that by default
# on opening new files
os.environ[var] = current_path
print(" - Updated $JOB to {}".format(job_path))
if current_path != path:
hou.hscript("set {}={}".format(var, path))
os.environ[var] = path
try:
os.makedirs(path)
except OSError as e:
if e.errno != errno.EEXIST:
print(
" - Failed to create {} dir. Maybe due to "
"insufficient permissions.".format(var)
)
print(" - Updated ${} to {}".format(var, path))

View file

@ -300,8 +300,8 @@ def on_save():
log.info("Running callback on save..")
# Validate $JOB value
lib.update_job_var_context()
# update houdini vars
lib.update_houdini_vars_context()
nodes = lib.get_id_required_nodes()
for node, new_id in lib.generate_ids(nodes):
@ -338,8 +338,8 @@ def on_open():
log.info("Running callback on open..")
# Validate $JOB value
lib.update_job_var_context()
# update houdini vars
lib.update_houdini_vars_context()
# Validate FPS after update_task_from_path to
# ensure it is using correct FPS for the asset

View file

@ -1,8 +1,10 @@
{
"general": {
"update_job_var_context": {
"update_houdini_var_context": {
"enabled": true,
"job_path": "{root[work]}/{project[name]}/{hierarchy}/{asset}/work/{task[name]}"
"houdini_vars":{
"JOB": "{root[work]}/{project[name]}/{hierarchy}/{asset}/work/{task[name]}"
}
}
},
"imageio": {

View file

@ -9,8 +9,8 @@
"type": "dict",
"collapsible": true,
"checkbox_key": "enabled",
"key": "update_job_var_context",
"label": "Update $JOB on context change",
"key": "update_houdini_var_context",
"label": "Update Houdini Vars on context change",
"children": [
{
"type": "boolean",
@ -18,9 +18,14 @@
"label": "Enabled"
},
{
"type": "text",
"key": "job_path",
"label": "JOB Path"
"type": "dict-modifiable",
"key": "houdini_vars",
"label": "Houdini Vars",
"collapsible": false,
"object_type": {
"type": "path",
"multiplatform": false
}
}
]
}

View file

@ -2,21 +2,36 @@ from pydantic import Field
from ayon_server.settings import BaseSettingsModel
class UpdateJobVarcontextModel(BaseSettingsModel):
class HoudiniVarModel(BaseSettingsModel):
_layout = "expanded"
var: str = Field("", title="Var")
path: str = Field(default_factory="", title="Path")
class UpdateHoudiniVarcontextModel(BaseSettingsModel):
enabled: bool = Field(title="Enabled")
job_path: str = Field(title="JOB Path")
# TODO this was dynamic dictionary '{var: path}'
houdini_vars: list[HoudiniVarModel] = Field(
default_factory=list,
title="Houdini Vars"
)
class GeneralSettingsModel(BaseSettingsModel):
update_job_var_context: UpdateJobVarcontextModel = Field(
default_factory=UpdateJobVarcontextModel,
title="Update $JOB on context change"
update_houdini_var_context: UpdateHoudiniVarcontextModel = Field(
default_factory=UpdateHoudiniVarcontextModel,
title="Update Houdini Vars on context change"
)
DEFAULT_GENERAL_SETTINGS = {
"update_job_var_context": {
"update_houdini_var_context": {
"enabled": True,
"job_path": "{root[work]}/{project[name]}/{hierarchy}/{asset}/work/{task[name]}" # noqa
"houdini_vars": [
{
"var": "JOB",
"path": "{root[work]}/{project[name]}/{hierarchy}/{asset}/work/{task[name]}" # noqa
}
]
}
}