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

Houdini: Move get_current_context_template_data function to a proper place #5846

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 76 additions & 3 deletions openpype/hosts/houdini/api/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,23 @@
import six

from openpype.lib import StringTemplate
from openpype.client import get_asset_by_name
from openpype.client import (
get_asset_by_name,
get_project
)
from openpype.settings import get_current_project_settings
from openpype.pipeline import (
get_current_project_name,
get_current_asset_name,
registered_host
)

from openpype.pipeline.template_data import get_template_data
from openpype.pipeline.anatomy import Anatomy
from openpype.pipeline.context_tools import (
get_current_context_template_data,
get_current_project_asset
get_current_project_asset,
get_current_context,
get_current_host_name
)
from openpype.widgets import popup
from openpype.tools.utils.host_tools import get_tool_by_name
Expand Down Expand Up @@ -992,3 +999,69 @@ def add_self_publish_button(node):
template = node.parmTemplateGroup()
template.insertBefore((0,), button_parm)
node.setParmTemplateGroup(template)


def get_current_context_template_data():
"""Template data for template fill from current context

Returns:
Dict[str, Any] of the following tokens and their values
Supported Tokens:
- Regular Tokens
- app
- user
- asset
- parent
- hierarchy
- folder[name]
- root[work, ...]
- studio[code, name]
- project[code, name]
- task[type, name, short]

- Context Specific Tokens
- assetData[frameStart]
- assetData[frameEnd]
- assetData[handleStart]
- assetData[handleEnd]
- assetData[frameStartHandle]
- assetData[frameEndHandle]
- assetData[resolutionHeight]
- assetData[resolutionWidth]
"""

# pre-prepare get_template_data args
current_context = get_current_context()
project_name = current_context["project_name"]
asset_name = current_context["asset_name"]
anatomy = Anatomy(project_name)

# prepare get_template_data args
project_doc = get_project(project_name)
asset_doc = get_asset_by_name(project_name, asset_name)
task_name = current_context["task_name"]
host_name = get_current_host_name()

# get regular template data
template_data = get_template_data(
project_doc, asset_doc, task_name, host_name
)

template_data["root"] = anatomy.roots

# get context specific vars
asset_data = asset_doc["data"].copy()

# compute `frameStartHandle` and `frameEndHandle`
if "frameStart" in asset_data and "handleStart" in asset_data:
asset_data["frameStartHandle"] = \
asset_data["frameStart"] - asset_data["handleStart"]

if "frameEnd" in asset_data and "handleEnd" in asset_data:
asset_data["frameEndHandle"] = \
asset_data["frameEnd"] + asset_data["handleEnd"]

# add assetData
template_data["assetData"] = asset_data

return template_data
2 changes: 1 addition & 1 deletion openpype/hosts/houdini/api/shelves.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from openpype.pipeline import get_current_project_name

from openpype.lib import StringTemplate
from openpype.pipeline.context_tools import get_current_context_template_data
from .lib import get_current_context_template_data

import hou

Expand Down
72 changes: 1 addition & 71 deletions openpype/pipeline/context_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@

from .publish.lib import filter_pyblish_plugins
from .anatomy import Anatomy
from .template_data import (
get_template_data_with_names,
get_template_data
)
from .template_data import get_template_data_with_names
from .workfile import (
get_workfile_template_key,
get_custom_workfile_template_by_string_context,
Expand Down Expand Up @@ -661,70 +658,3 @@ def get_process_id():
if _process_id is None:
_process_id = str(uuid.uuid4())
return _process_id


def get_current_context_template_data():
"""Template data for template fill from current context

Returns:
Dict[str, Any] of the following tokens and their values
Supported Tokens:
- Regular Tokens
- app
- user
- asset
- parent
- hierarchy
- folder[name]
- root[work, ...]
- studio[code, name]
- project[code, name]
- task[type, name, short]

- Context Specific Tokens
- assetData[frameStart]
- assetData[frameEnd]
- assetData[handleStart]
- assetData[handleEnd]
- assetData[frameStartHandle]
- assetData[frameEndHandle]
- assetData[resolutionHeight]
- assetData[resolutionWidth]

"""

# pre-prepare get_template_data args
current_context = get_current_context()
project_name = current_context["project_name"]
asset_name = current_context["asset_name"]
anatomy = Anatomy(project_name)

# prepare get_template_data args
project_doc = get_project(project_name)
asset_doc = get_asset_by_name(project_name, asset_name)
task_name = current_context["task_name"]
host_name = get_current_host_name()

# get regular template data
template_data = get_template_data(
project_doc, asset_doc, task_name, host_name
)

template_data["root"] = anatomy.roots

# get context specific vars
asset_data = asset_doc["data"].copy()

# compute `frameStartHandle` and `frameEndHandle`
if "frameStart" in asset_data and "handleStart" in asset_data:
asset_data["frameStartHandle"] = \
asset_data["frameStart"] - asset_data["handleStart"]

if "frameEnd" in asset_data and "handleEnd" in asset_data:
asset_data["frameEndHandle"] = \
asset_data["frameEnd"] + asset_data["handleEnd"]

# add assetData
template_data["assetData"] = asset_data

return template_data
Loading