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 129
Nuke: Build workfile by template #3544
Closed
friquette
wants to merge
15
commits into
ynput:develop
from
quadproduction:build-workfile-template-nuke
Closed
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
1278a3f
first implementation
f2b0e0c
clean divided
87be0db
clean divided into multiple commented methods
9b6a231
clean divided into multiple commented methods
4fcad75
doc
2b4cd2a
doc
5b0fdd8
fix linting errors
703f660
useless comments removed
a06f755
useless comments removed
74135fa
update doc
5c57626
empty problem solved
3529611
fix linting
c730b07
import qargparse fixed
43c55e9
Merge branch 'build-workfile-template-nuke' of https://gitlab.fixstud…
a2ad8c3
import qargparse fixed
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,206 @@ | ||||||
from collections import OrderedDict | ||||||
|
||||||
from openpype.vendor.python.common import qargparse | ||||||
from openpype.tools.utils.widgets import OptionDialog | ||||||
from openpype.hosts.nuke.api.lib import imprint | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
import nuke | ||||||
|
||||||
|
||||||
# To change as enum | ||||||
build_types = ["context_asset", "linked_asset", "all_assets"] | ||||||
|
||||||
|
||||||
def get_placeholder_attributes(node, enumerate=False): | ||||||
list_atts = ['builder_type', 'family', 'representation', 'loader', | ||||||
'loader_args', 'order', 'asset', 'subset', | ||||||
'hierarchy', 'siblings', 'last_loaded'] | ||||||
attributes = {} | ||||||
for attr in node.knobs().keys(): | ||||||
if attr in list_atts: | ||||||
if enumerate: | ||||||
try: | ||||||
attributes[attr] = node.knob(attr).values() | ||||||
except AttributeError: | ||||||
attributes[attr] = node.knob(attr).getValue() | ||||||
else: | ||||||
attributes[attr] = node.knob(attr).getValue() | ||||||
|
||||||
return attributes | ||||||
|
||||||
|
||||||
def delete_placeholder_attributes(node): | ||||||
''' | ||||||
function to delete all extra placeholder attributes | ||||||
''' | ||||||
extra_attributes = get_placeholder_attributes(node) | ||||||
for attribute in extra_attributes.keys(): | ||||||
try: | ||||||
node.removeKnob(node.knob(attribute)) | ||||||
except ValueError: | ||||||
continue | ||||||
|
||||||
|
||||||
def hide_placeholder_attributes(node): | ||||||
''' | ||||||
function to hide all extra placeholder attributes | ||||||
''' | ||||||
extra_attributes = get_placeholder_attributes(node) | ||||||
for attribute in extra_attributes.keys(): | ||||||
try: | ||||||
node.knob(attribute).setVisible(False) | ||||||
except ValueError: | ||||||
continue | ||||||
|
||||||
|
||||||
def create_placeholder(): | ||||||
|
||||||
args = placeholder_window() | ||||||
|
||||||
if not args: | ||||||
return # operation canceled, no locator created | ||||||
|
||||||
placeholder = nuke.nodes.NoOp() | ||||||
placeholder.setName('PLACEHOLDER') | ||||||
placeholder.knob('tile_color').setValue(4278190335) | ||||||
|
||||||
# custom arg parse to force empty data query | ||||||
# and still imprint them on placeholder | ||||||
# and getting items when arg is of type Enumerator | ||||||
options = OrderedDict() | ||||||
for arg in args: | ||||||
if not type(arg) == qargparse.Separator: | ||||||
options[str(arg)] = arg._data.get("items") or arg.read() | ||||||
imprint(placeholder, options) | ||||||
imprint(placeholder, {'is_placeholder': True}) | ||||||
placeholder.knob('is_placeholder').setVisible(False) | ||||||
|
||||||
|
||||||
def update_placeholder(): | ||||||
placeholder = nuke.selectedNodes() | ||||||
if not placeholder: | ||||||
raise ValueError("No node selected") | ||||||
if len(placeholder) > 1: | ||||||
raise ValueError("Too many selected nodes") | ||||||
placeholder = placeholder[0] | ||||||
|
||||||
args = placeholder_window(get_placeholder_attributes(placeholder)) | ||||||
if not args: | ||||||
return # operation canceled | ||||||
# delete placeholder attributes | ||||||
delete_placeholder_attributes(placeholder) | ||||||
|
||||||
options = OrderedDict() | ||||||
for arg in args: | ||||||
if not type(arg) == qargparse.Separator: | ||||||
options[str(arg)] = arg._data.get("items") or arg.read() | ||||||
imprint(placeholder, options) | ||||||
|
||||||
|
||||||
def imprint_enum(placeholder, args): | ||||||
""" | ||||||
Imprint method doesn't act properly with enums. | ||||||
Replacing the functionnality with this for now | ||||||
""" | ||||||
enum_values = {str(arg): arg.read() | ||||||
for arg in args if arg._data.get("items")} | ||||||
string_to_value_enum_table = { | ||||||
build: i for i, build | ||||||
in enumerate(build_types)} | ||||||
attrs = {} | ||||||
for key, value in enum_values.items(): | ||||||
attrs[key] = string_to_value_enum_table[value] | ||||||
|
||||||
|
||||||
def placeholder_window(options=None): | ||||||
from openpype.hosts.nuke.api.pipeline import get_main_window | ||||||
options = options or dict() | ||||||
dialog = OptionDialog(parent=get_main_window()) | ||||||
dialog.setWindowTitle("Create Placeholder") | ||||||
|
||||||
args = [ | ||||||
qargparse.Separator("Main attributes"), | ||||||
qargparse.Enum( | ||||||
"builder_type", | ||||||
label="Asset Builder Type", | ||||||
default=options.get("builder_type", 0), | ||||||
items=build_types, | ||||||
help="""Asset Builder Type | ||||||
Builder type describe what template loader will look for. | ||||||
|
||||||
context_asset : Template loader will look for subsets of | ||||||
current context asset (Asset bob will find asset) | ||||||
|
||||||
linked_asset : Template loader will look for assets linked | ||||||
to current context asset. | ||||||
Linked asset are looked in avalon database under field "inputLinks" | ||||||
""" | ||||||
), | ||||||
qargparse.String( | ||||||
"family", | ||||||
default=options.get("family", ""), | ||||||
label="OpenPype Family", | ||||||
placeholder="ex: model, look ..."), | ||||||
qargparse.String( | ||||||
"representation", | ||||||
default=options.get("representation", ""), | ||||||
label="OpenPype Representation", | ||||||
placeholder="ex: ma, abc ..."), | ||||||
qargparse.String( | ||||||
"loader", | ||||||
default=options.get("loader", ""), | ||||||
label="Loader", | ||||||
placeholder="ex: ReferenceLoader, LightLoader ...", | ||||||
help="""Loader | ||||||
|
||||||
Defines what openpype loader will be used to load assets. | ||||||
Useable loader depends on current host's loader list. | ||||||
Field is case sensitive. | ||||||
"""), | ||||||
qargparse.String( | ||||||
"loader_args", | ||||||
default=options.get("loader_args", ""), | ||||||
label="Loader Arguments", | ||||||
placeholder='ex: {"camera":"persp", "lights":True}', | ||||||
help="""Loader | ||||||
|
||||||
Defines a dictionnary of arguments used to load assets. | ||||||
Useable arguments depend on current placeholder Loader. | ||||||
Field should be a valid python dict. Anything else will be ignored. | ||||||
"""), | ||||||
qargparse.Integer( | ||||||
"order", | ||||||
default=options.get("order", 0), | ||||||
min=0, | ||||||
max=999, | ||||||
label="Order", | ||||||
placeholder="ex: 0, 100 ... (smallest order loaded first)", | ||||||
help="""Order | ||||||
|
||||||
Order defines asset loading priority (0 to 999) | ||||||
Priority rule is : "lowest is first to load"."""), | ||||||
qargparse.Separator( | ||||||
"Optional attributes "), | ||||||
qargparse.String( | ||||||
"asset", | ||||||
default=options.get("asset", ""), | ||||||
label="Asset filter", | ||||||
placeholder="regex filtering by asset name", | ||||||
help="Filtering assets by matching field regex to asset's name"), | ||||||
qargparse.String( | ||||||
"subset", | ||||||
default=options.get("subset", ""), | ||||||
label="Subset filter", | ||||||
placeholder="regex filtering by subset name", | ||||||
help="Filtering assets by matching field regex to subset's name"), | ||||||
qargparse.String( | ||||||
"hierarchy", | ||||||
default=options.get("hierarchy", ""), | ||||||
label="Hierarchy filter", | ||||||
placeholder="regex filtering by asset's hierarchy", | ||||||
help="Filtering assets by matching field asset's hierarchy") | ||||||
] | ||||||
dialog.create(args) | ||||||
if not dialog.exec_(): | ||||||
return None | ||||||
|
||||||
return args |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.