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] return cameras[0]
def update_job_var_context(): def update_houdini_vars_context():
"""Update $JOB to match current context. """Update Houdini vars to match current context.
This will only do something if the setting is enabled in project settings. This will only do something if the setting is enabled in project settings.
""" """
project_settings = get_current_project_settings() project_settings = get_current_project_settings()
job_var_settings = \ houdini_vars_settings = \
project_settings["houdini"]["general"]["update_job_var_context"] 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 # Remap AYON settings structure to OpenPype settings structure
job_path = StringTemplate.format_template( # It allows me to use the same logic for both AYON and OpenPype
job_var_settings["job_path"], if isinstance(houdini_vars, list):
get_current_context_template_data() items = {}
) for item in houdini_vars:
job_path = job_path.replace("\\", "/") items.update({item["var"]: item["path"]})
if job_path == "": houdini_vars = items
# Set JOB path to HIP path if JOB path is enabled
# and has empty value.
job_path = os.environ["HIP"]
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. if var == "JOB" and path == "":
# because when opening new file $JOB is overridden with # sync $JOB to $HIP if $JOB is empty
# the value saved in the HIP file but os.environ["JOB"] is not! path = os.environ["HIP"]
os.environ["JOB"] = current_job
if current_job != job_path: current_path = hou.hscript("echo -n `${}`".format(var))[0]
hou.hscript("set JOB=" + job_path)
os.environ["JOB"] = job_path
try: # sync both environment variables.
os.makedirs(job_path) # because houdini doesn't do that by default
except OSError as e: # on opening new files
if e.errno != errno.EEXIST: os.environ[var] = current_path
print(
" - Failed to create JOB dir. Maybe due to "
"insufficient permissions."
)
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..") log.info("Running callback on save..")
# Validate $JOB value # update houdini vars
lib.update_job_var_context() lib.update_houdini_vars_context()
nodes = lib.get_id_required_nodes() nodes = lib.get_id_required_nodes()
for node, new_id in lib.generate_ids(nodes): for node, new_id in lib.generate_ids(nodes):
@ -338,8 +338,8 @@ def on_open():
log.info("Running callback on open..") log.info("Running callback on open..")
# Validate $JOB value # update houdini vars
lib.update_job_var_context() lib.update_houdini_vars_context()
# Validate FPS after update_task_from_path to # Validate FPS after update_task_from_path to
# ensure it is using correct FPS for the asset # ensure it is using correct FPS for the asset

View file

@ -1,8 +1,10 @@
{ {
"general": { "general": {
"update_job_var_context": { "update_houdini_var_context": {
"enabled": true, "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": { "imageio": {

View file

@ -9,8 +9,8 @@
"type": "dict", "type": "dict",
"collapsible": true, "collapsible": true,
"checkbox_key": "enabled", "checkbox_key": "enabled",
"key": "update_job_var_context", "key": "update_houdini_var_context",
"label": "Update $JOB on context change", "label": "Update Houdini Vars on context change",
"children": [ "children": [
{ {
"type": "boolean", "type": "boolean",
@ -18,9 +18,14 @@
"label": "Enabled" "label": "Enabled"
}, },
{ {
"type": "text", "type": "dict-modifiable",
"key": "job_path", "key": "houdini_vars",
"label": "JOB Path" "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 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") 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): class GeneralSettingsModel(BaseSettingsModel):
update_job_var_context: UpdateJobVarcontextModel = Field( update_houdini_var_context: UpdateHoudiniVarcontextModel = Field(
default_factory=UpdateJobVarcontextModel, default_factory=UpdateHoudiniVarcontextModel,
title="Update $JOB on context change" title="Update Houdini Vars on context change"
) )
DEFAULT_GENERAL_SETTINGS = { DEFAULT_GENERAL_SETTINGS = {
"update_job_var_context": { "update_houdini_var_context": {
"enabled": True, "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
}
]
} }
} }