generated from ynput/ayon-addon-template
-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support publishing and loading node presets #70
Closed
MustafaJafar
wants to merge
5
commits into
develop
from
feature/AY-6061_Render-Setup-Workflow-alternative-for-Houdini
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
58d0d97
add support for publishing node presets
MustafaJafar fea866b
add support for loading node presets
MustafaJafar 7fd74c3
Merge branch 'develop' into feature/AY-6061_Render-Setup-Workflow-alt…
MustafaJafar 3818b57
move functions defs to lib
MustafaJafar 2e15b96
remove unused import
MustafaJafar 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
105 changes: 105 additions & 0 deletions
105
client/ayon_houdini/plugins/create/create_node_preset.py
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,105 @@ | ||
# -*- coding: utf-8 -*- | ||
"""Creator plugin for creating houdini node presets.""" | ||
from ayon_houdini.api import plugin | ||
import hou | ||
|
||
|
||
def _update_node_parmtemplate(node, defaults): | ||
"""update node parm template. | ||
|
||
It adds a new folder parm that includes | ||
filepath and operator node selector. | ||
""" | ||
parm_group = node.parmTemplateGroup() | ||
|
||
# Hide unnecessary parameters | ||
for parm in {"execute", "renderdialog"}: | ||
p = parm_group.find(parm) | ||
p.hide(True) | ||
parm_group.replace(parm, p) | ||
|
||
# Create essential parameters | ||
folder_template = hou.FolderParmTemplate( | ||
name="main", | ||
label="Main", | ||
folder_type=hou.folderType.Tabs | ||
) | ||
|
||
filepath_template = hou.StringParmTemplate( | ||
name="filepath", | ||
label="Preset File", | ||
num_components=1, | ||
default_value=(defaults.get("filepath", ""),), | ||
string_type=hou.stringParmType.FileReference, | ||
tags= { | ||
"filechooser_pattern" : "*.json", | ||
} | ||
) | ||
|
||
operatore_template = hou.StringParmTemplate( | ||
name="source_node", | ||
label="Source Node", | ||
num_components=1, | ||
default_value=(defaults.get("source_node", ""),), | ||
string_type=hou.stringParmType.NodeReference, | ||
tags= { | ||
"oprelative" : "." | ||
} | ||
) | ||
|
||
folder_template.addParmTemplate(filepath_template) | ||
folder_template.addParmTemplate(operatore_template) | ||
|
||
# TODO: make the Main and Extra Tab next to each other. | ||
parm_group.insertBefore((0,), folder_template) | ||
|
||
node.setParmTemplateGroup(parm_group) | ||
|
||
|
||
class CreateNodePreset(plugin.HoudiniCreator): | ||
"""NodePreset creator. | ||
|
||
Node Presets capture the parameters of the source node. | ||
""" | ||
identifier = "io.ayon.creators.houdini.node_preset" | ||
label = "Node Preset" | ||
product_type = "node_preset" | ||
icon = "gears" | ||
|
||
def create(self, product_name, instance_data, pre_create_data): | ||
|
||
instance_data.update({"node_type": "null"}) | ||
|
||
instance = super(CreateNodePreset, self).create( | ||
product_name, | ||
instance_data, | ||
pre_create_data) | ||
|
||
instance_node = hou.node(instance.get("instance_node")) | ||
|
||
|
||
filepath = "{}{}".format( | ||
hou.text.expandString("$HIP/pyblish/"), | ||
f"{product_name}.json" | ||
) | ||
source_node = "" | ||
|
||
if self.selected_nodes: | ||
source_node = self.selected_nodes[0].path() | ||
|
||
defaults= { | ||
"filepath": filepath, | ||
"source_node": source_node | ||
} | ||
_update_node_parmtemplate(instance_node, defaults) | ||
|
||
|
||
def get_pre_create_attr_defs(self): | ||
attrs = super().get_pre_create_attr_defs() | ||
|
||
return attrs + self.get_instance_attr_defs() | ||
|
||
def get_network_categories(self): | ||
return [ | ||
hou.ropNodeTypeCategory() | ||
] |
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
61 changes: 61 additions & 0 deletions
61
client/ayon_houdini/plugins/publish/extract_render_setup.py
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,61 @@ | ||
import os | ||
import hou | ||
import json | ||
import pyblish.api | ||
|
||
from ayon_houdini.api import plugin | ||
|
||
|
||
def getparms(node): | ||
|
||
parameters = node.parms() | ||
parameters += node.spareParms() | ||
param_data = {} | ||
|
||
for param in parameters: | ||
if param.parmTemplate().type().name() == 'FolderSet': | ||
continue | ||
|
||
# Add parameter data to the dictionary | ||
# FIXME: I also evaluate expressions. | ||
param_data[param.name()] = param.eval() | ||
|
||
return param_data | ||
|
||
|
||
class ExtractNodePreset(plugin.HoudiniExtractorPlugin): | ||
"""Node Preset Extractor for any node.""" | ||
label = "Extract Node Preset" | ||
order = pyblish.api.ExtractorOrder | ||
|
||
families = ["node_preset"] | ||
targets = ["local", "remote"] | ||
|
||
def process(self, instance: pyblish.api.Instance): | ||
if instance.data.get("farm"): | ||
self.log.debug("Should be processed on farm, skipping.") | ||
return | ||
|
||
instance_node = hou.node(instance.data["instance_node"]) | ||
|
||
source_node = instance_node.parm("source_node").evalAsNode() | ||
json_path = instance_node.evalParm("filepath") | ||
|
||
param_data = getparms(source_node) | ||
node_preset = { | ||
"metadata":{ | ||
"type": source_node.type().name() | ||
}, | ||
"param_data": param_data | ||
} | ||
with open(json_path, "w+") as f: | ||
json.dump(node_preset, fp=f, indent=2, sort_keys=True) | ||
|
||
representation = { | ||
"name": "json", | ||
"ext": "json", | ||
"files": os.path.basename(json_path), | ||
"stagingDir": os.path.dirname(json_path), | ||
} | ||
|
||
instance.data.setdefault("representations", []).append(representation) |
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.
A question: Does this function imprint the data into the instance_node already? (Or it is like the temp data publisher and it won't imprint the instance data?)
i.e. some variables you can find in almost every creator and they are missing in this creator.
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.
The method
_update_node_parmtemplate
doesn't create the extra ayon parameters created by imprint.It actually doesn't create any parameters at all.
It only captures the values of any existent parameters (including ayon extra parameters) from the source node and reassigns these values to the target node.
I have that feeling that the method name should be refactored but I couldn't come up with a better name :/
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.
I remember @BigRoy has written a one-time publish node(along with the generic nodes for publishing). Maybe he can give some maps on this.