This repository has been archived by the owner on Sep 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ef33105
commit 2d7bc88
Showing
5 changed files
with
194 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
from collections import defaultdict | ||
import shutil | ||
import os | ||
import json | ||
import re | ||
|
||
from openpype.client import get_project, get_asset_by_id | ||
from openpype.settings import get_system_settings, get_project_settings | ||
from openpype.pipeline import Anatomy, registered_host | ||
from openpype.pipeline.template_data import get_template_data | ||
from openpype.pipeline.workfile import get_workdir_with_workdir_data | ||
from openpype import PACKAGE_DIR | ||
from openpype.lib import get_openpype_execute_args, run_subprocess | ||
|
||
import nuke | ||
|
||
|
||
def bake_container(container): | ||
"""Bake containers to read nodes.""" | ||
|
||
node = container["node"] | ||
|
||
# Fetch knobs to remove in order. | ||
knobs_to_remove = [] | ||
remove = False | ||
for count in range(0, node.numKnobs()): | ||
knob = node.knob(count) | ||
|
||
# All knobs from "OpenPype" tab knob onwards. | ||
if knob.name() == "OpenPype": | ||
remove = True | ||
|
||
if remove: | ||
knobs_to_remove.append(knob) | ||
|
||
# Dont remove knobs from "containerId" onwards. | ||
if knob.name() == "containerId": | ||
remove = False | ||
|
||
# Knobs needs to be remove in reverse order, because child knobs needs to | ||
# be remove first. | ||
for knob in reversed(knobs_to_remove): | ||
node.removeKnob(knob) | ||
|
||
node["tile_color"].setValue(0) | ||
|
||
|
||
def main(): | ||
# Get project name, asset id and task name. | ||
push_tool_script_path = os.path.join( | ||
PACKAGE_DIR, | ||
"tools", | ||
"push_to_project", | ||
"app.py" | ||
) | ||
|
||
args = get_openpype_execute_args( | ||
"run", | ||
push_tool_script_path, | ||
"--library_filter", "False", | ||
"--context_only", "True" | ||
) | ||
output = run_subprocess(args) | ||
dict_string = re.search(r'\{.*\}', output).group() | ||
result = json.loads(dict_string) | ||
|
||
# Get workfile path to save to. | ||
project_name = result["project_name"] | ||
project_doc = get_project(project_name) | ||
asset_doc = get_asset_by_id(project_name, result["asset_id"]) | ||
task_name = result["task_name"] | ||
host = registered_host() | ||
system_settings = get_system_settings() | ||
project_settings = get_project_settings(project_name) | ||
anatomy = Anatomy(project_name) | ||
|
||
workdir_data = get_template_data( | ||
project_doc, asset_doc, task_name, host.name, system_settings | ||
) | ||
|
||
workdir = get_workdir_with_workdir_data( | ||
workdir_data, | ||
project_name, | ||
anatomy, | ||
project_settings=project_settings | ||
) | ||
|
||
# Warn about saving current workfile. | ||
# Save current workfile. | ||
current_file = host.current_file() | ||
host.save_file(current_file) | ||
|
||
for container in host.ls(): | ||
bake_container(container) | ||
|
||
# Copy all read node files to "resources" folder next to workfile and | ||
# change file path. | ||
first_frame = int(nuke.root()["first_frame"].value()) | ||
last_frame = int(nuke.root()["last_frame"].value()) | ||
files_by_node_name = defaultdict(set) | ||
nodes_by_name = {} | ||
for count in range(first_frame, last_frame + 1): | ||
nuke.frame(count) | ||
for node in nuke.allNodes(filter="Read"): | ||
files_by_node_name[node.name()].add( | ||
nuke.filename(node, nuke.REPLACE) | ||
) | ||
nodes_by_name[node.name()] = node | ||
|
||
resources_dir = os.path.join(workdir, "resources") | ||
for name, files in files_by_node_name.items(): | ||
dir = os.path.join(resources_dir, name) | ||
if not os.path.exists(dir): | ||
os.makedirs(dir) | ||
|
||
for f in files: | ||
shutil.copy(f, os.path.join(dir, os.path.basename(f))) | ||
|
||
node = nodes_by_name[name] | ||
path = node["file"].value().replace(os.path.dirname(f), dir) | ||
node["file"].setValue(path.replace("\\", "/")) | ||
|
||
# Save current workfile to new context. | ||
basename = os.path.basename(current_file) | ||
host.save_file(os.path.join(workdir, basename)) | ||
|
||
# Open current contex workfile. | ||
host.open_file(current_file) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters