Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Commit

Permalink
BigRoy's comments and add houdini project settings to houdini api
Browse files Browse the repository at this point in the history
  • Loading branch information
MustafaJafar committed Sep 26, 2023
1 parent fdea715 commit 32a88fd
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 26 deletions.
4 changes: 3 additions & 1 deletion openpype/hosts/houdini/api/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from .pipeline import (
HoudiniHost,
ls,
containerise
containerise,
HoudiniProjectSettings
)

from .plugin import (
Expand All @@ -22,6 +23,7 @@

"ls",
"containerise",
"HoudiniProjectSettings",

"Creator",

Expand Down
14 changes: 4 additions & 10 deletions openpype/hosts/houdini/api/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

from openpype.lib import StringTemplate
from openpype.client import get_asset_by_name
from openpype.settings import get_current_project_settings
from openpype.pipeline import get_current_project_name, get_current_asset_name
from openpype.pipeline.context_tools import (
get_current_context_template_data,
Expand Down Expand Up @@ -754,16 +753,13 @@ def get_camera_from_container(container):
return cameras[0]


def validate_job_path():
def update_job_var_context(job_var_settings):
"""Validate job path to ensure it matches the settings."""

project_settings = get_current_project_settings()

if project_settings["houdini"]["general"]["job_path"]["enabled"]:
if job_var_settings["enabled"]:

# get and resolve job path template
job_path_template = \
project_settings["houdini"]["general"]["job_path"]["path"]
job_path_template = job_var_settings["job_path"]
job_path = StringTemplate.format_template(
job_path_template, get_current_context_template_data()
)
Expand All @@ -778,6 +774,4 @@ def validate_job_path():
if current_job != job_path:
hou.hscript("set JOB=" + job_path)
os.environ["JOB"] = job_path
print(" - set $JOB to " + job_path)
else:
print(" - JOB Path is disabled, Skipping Check...")
print(" - update context $JOB to [ {} ]".format(job_path))
44 changes: 42 additions & 2 deletions openpype/hosts/houdini/api/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
from openpype.pipeline.load import any_outdated_containers
from openpype.hosts.houdini import HOUDINI_HOST_DIR
from openpype.hosts.houdini.api import lib, shelves, creator_node_shelves
from openpype.settings import (
get_current_project_settings,
get_project_settings
)

from openpype.lib import (
register_event_callback,
Expand Down Expand Up @@ -48,6 +52,10 @@ def __init__(self):
self._op_events = {}
self._has_been_setup = False

@property
def houdini_project_settings(self):
return HoudiniProjectSettings()

def install(self):
pyblish.api.register_host("houdini")
pyblish.api.register_host("hython")
Expand Down Expand Up @@ -301,7 +309,8 @@ def on_save():
log.info("Running callback on save..")

# Validate $JOB value
lib.validate_job_path()
lib.update_job_var_context(
HoudiniProjectSettings().general["update_job_var_context"])

nodes = lib.get_id_required_nodes()
for node, new_id in lib.generate_ids(nodes):
Expand Down Expand Up @@ -339,7 +348,8 @@ def on_open():
log.info("Running callback on open..")

# Validate $JOB value
lib.validate_job_path()
lib.update_job_var_context(
HoudiniProjectSettings().general["update_job_var_context"])

# Validate FPS after update_task_from_path to
# ensure it is using correct FPS for the asset
Expand Down Expand Up @@ -456,3 +466,33 @@ def main_take(no_update=True):
instance_node.bypass(not new_value)
except hou.PermissionError as exc:
log.warning("%s - %s", instance_node.path(), exc)


class HoudiniProjectSettings:
def __init__(self, project_name=""):
if project_name:
self.houdini_project_settings = \
get_project_settings(project_name).get("houdini")
else:
self.houdini_project_settings = \
get_current_project_settings().get("houdini")

@property
def general(self):
return self.houdini_project_settings["general"]

@property
def imageio(self):
return self.houdini_project_settings["imageio"]

@property
def shelves(self):
return self.houdini_project_settings["shelves"]

@property
def publish(self):
return self.houdini_project_settings["publish"]

@property
def create(self):
return self.houdini_project_settings["create"]
4 changes: 2 additions & 2 deletions openpype/settings/defaults/project_settings/houdini.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"general": {
"job_path": {
"update_job_var_context": {
"enabled": true,
"path": "{root[work]}/{project[name]}/{hierarchy}/{asset}/work/{task[name]}"
"job_path": "{root[work]}/{project[name]}/{hierarchy}/{asset}/work/{task[name]}"
}
},
"imageio": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"type": "dict",
"collapsible": true,
"checkbox_key": "enabled",
"key": "job_path",
"label": "JOB Path",
"key": "update_job_var_context",
"label": "Update $JOB on context change",
"children": [
{
"type": "boolean",
Expand All @@ -19,8 +19,8 @@
},
{
"type": "text",
"key": "path",
"label": "Path"
"key": "job_path",
"label": "JOB Path"
}
]
}
Expand Down
14 changes: 7 additions & 7 deletions server_addon/houdini/server/settings/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@
from ayon_server.settings import BaseSettingsModel


class JobPathModel(BaseSettingsModel):
class UpdateJobVarcontextModel(BaseSettingsModel):
enabled: bool = Field(title="Enabled")
path: str = Field(title="Path")
job_path: str = Field(title="JOB Path")


class GeneralSettingsModel(BaseSettingsModel):
JobPath: JobPathModel = Field(
default_factory=JobPathModel,
title="JOB Path"
update_job_var_context: UpdateJobVarcontextModel = Field(
default_factory=UpdateJobVarcontextModel,
title="Update $JOB on context change"
)


DEFAULT_GENERAL_SETTINGS = {
"JobPath": {
"update_job_var_context": {
"enabled": True,
"path": "{root[work]}/{project[name]}/{hierarchy}/{asset}/work/{task[name]}" # noqa
"job_path": "{root[work]}/{project[name]}/{hierarchy}/{asset}/work/{task[name]}" # noqa
}
}

0 comments on commit 32a88fd

Please sign in to comment.