diff --git a/openpype/hosts/houdini/api/lib.py b/openpype/hosts/houdini/api/lib.py index 3db18ca69a..f258dda36e 100644 --- a/openpype/hosts/houdini/api/lib.py +++ b/openpype/hosts/houdini/api/lib.py @@ -13,12 +13,19 @@ import six 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 import ( + get_current_project_name, + get_current_asset_name, + registered_host +) from openpype.pipeline.context_tools import ( get_current_context_template_data, get_current_project_asset ) from openpype.widgets import popup +from openpype.tools.utils.host_tools import get_tool_by_name +from openpype.pipeline.create import CreateContext + import hou @@ -847,3 +854,97 @@ def update_houdini_vars_context_dialog(): dialog.on_clicked.connect(update_houdini_vars_context) dialog.show() + + +def publisher_show_and_publish(comment=None): + """Open publisher window and trigger publishing action. + + Args: + comment (Optional[str]): Comment to set in publisher window. + """ + + main_window = get_main_window() + publisher_window = get_tool_by_name( + tool_name="publisher", + parent=main_window, + ) + publisher_window.show_and_publish(comment) + + +def find_rop_input_dependencies(input_tuple): + """Self publish from ROP nodes. + + Arguments: + tuple (hou.RopNode.inputDependencies) which can be a nested tuples + represents the input dependencies of the ROP node, consisting of ROPs, + and the frames that need to be be rendered prior to rendering the ROP. + + Returns: + list of the RopNode.path() that can be found inside + the input tuple. + """ + + out_list = [] + if isinstance(input_tuple[0], hou.RopNode): + return input_tuple[0].path() + + if isinstance(input_tuple[0], tuple): + for item in input_tuple: + out_list.append(find_rop_input_dependencies(item)) + + return out_list + + +def self_publish(): + """Self publish from ROP nodes. + + Firstly, it gets the node and its dependencies. + Then, it deactivates all other ROPs + And finaly, it triggers the publishing action. + """ + + result, comment = hou.ui.readInput( + "Add Publish Comment", + buttons=("Publish", "Cancel"), + title="Publish comment", + close_choice=1 + ) + + if result: + return + + current_node = hou.node(".") + inputs_paths = find_rop_input_dependencies( + current_node.inputDependencies() + ) + inputs_paths.append(current_node.path()) + + host = registered_host() + context = CreateContext(host, reset=True) + + for instance in context.instances: + node_path = instance.data.get("instance_node") + instance["active"] = node_path and node_path in inputs_paths + + context.save_changes() + + publisher_show_and_publish(comment) + + +def add_self_publish_button(node): + """Adds a self publish button to the rop node.""" + + label = os.environ.get("AVALON_LABEL") or "OpenPype" + + button_parm = hou.ButtonParmTemplate( + "ayon_self_publish", + "{} Publish".format(label), + script_callback="from openpype.hosts.houdini.api.lib import " + "self_publish; self_publish()", + script_callback_language=hou.scriptLanguage.Python, + join_with_next=True + ) + + template = node.parmTemplateGroup() + template.insertBefore((0,), button_parm) + node.setParmTemplateGroup(template) diff --git a/openpype/hosts/houdini/api/plugin.py b/openpype/hosts/houdini/api/plugin.py index a0a7dcc2e4..d79ccc71bd 100644 --- a/openpype/hosts/houdini/api/plugin.py +++ b/openpype/hosts/houdini/api/plugin.py @@ -13,7 +13,7 @@ from openpype.pipeline import ( CreatedInstance ) from openpype.lib import BoolDef -from .lib import imprint, read, lsattr +from .lib import imprint, read, lsattr, add_self_publish_button class OpenPypeCreatorError(CreatorError): @@ -168,6 +168,7 @@ class HoudiniCreator(NewCreator, HoudiniCreatorBase): """Base class for most of the Houdini creator plugins.""" selected_nodes = [] settings_name = None + add_publish_button = False def create(self, subset_name, instance_data, pre_create_data): try: @@ -195,6 +196,10 @@ class HoudiniCreator(NewCreator, HoudiniCreatorBase): self) self._add_instance_to_context(instance) self.imprint(instance_node, instance.data_to_store()) + + if self.add_publish_button: + add_self_publish_button(instance_node) + return instance except hou.Error as er: @@ -245,11 +250,14 @@ class HoudiniCreator(NewCreator, HoudiniCreatorBase): key: changes[key].new_value for key in changes.changed_keys } + # Update ParmTemplates self.imprint( instance_node, new_values, update=True ) + # Update values + instance_node.setParms(new_values) def imprint(self, node, values, update=False): # Never store instance node and instance id since that data comes @@ -316,6 +324,12 @@ class HoudiniCreator(NewCreator, HoudiniCreatorBase): def apply_settings(self, project_settings): """Method called on initialization of plugin to apply settings.""" + # Apply General Settings + houdini_general_settings = project_settings["houdini"]["general"] + self.add_publish_button = houdini_general_settings.get( + "add_self_publish_button", False) + + # Apply Creator Settings settings_name = self.settings_name if settings_name is None: settings_name = self.__class__.__name__ diff --git a/openpype/settings/defaults/project_settings/houdini.json b/openpype/settings/defaults/project_settings/houdini.json index 4f57ee52c6..9d8142d751 100644 --- a/openpype/settings/defaults/project_settings/houdini.json +++ b/openpype/settings/defaults/project_settings/houdini.json @@ -1,5 +1,6 @@ { "general": { + "add_self_publish_button": false, "update_houdini_var_context": { "enabled": true, "houdini_vars":[ diff --git a/openpype/settings/entities/schemas/projects_schema/schemas/schema_houdini_general.json b/openpype/settings/entities/schemas/projects_schema/schemas/schema_houdini_general.json index de1a0396ec..e118f83d21 100644 --- a/openpype/settings/entities/schemas/projects_schema/schemas/schema_houdini_general.json +++ b/openpype/settings/entities/schemas/projects_schema/schemas/schema_houdini_general.json @@ -5,6 +5,11 @@ "collapsible": true, "is_group": true, "children": [ + { + "type": "boolean", + "key": "add_self_publish_button", + "label": "Add Self Publish Button" + }, { "type": "dict", "collapsible": true, diff --git a/openpype/tools/publisher/window.py b/openpype/tools/publisher/window.py index 39e78c01bb..312cf1dd5c 100644 --- a/openpype/tools/publisher/window.py +++ b/openpype/tools/publisher/window.py @@ -388,6 +388,45 @@ class PublisherWindow(QtWidgets.QDialog): def controller(self): return self._controller + def show_and_publish(self, comment=None): + """Show the window and start publishing. + + The method will reset controller and start the publishing afterwards. + + Todos: + Move validations from '_on_publish_clicked' and change of + 'comment' value in controller to controller so it can be + simplified. + + Args: + comment (Optional[str]): Comment to be set to publish. + If is set to 'None' a comment is not changed at all. + """ + + self._reset_on_show = False + self._reset_on_first_show = False + + if comment is not None: + self.set_comment(comment) + self.make_sure_is_visible() + # Reset controller + self._controller.reset() + # Fake publish click to trigger save validation and propagate + # comment to controller + self._on_publish_clicked() + + def set_comment(self, comment): + """Change comment text. + + Todos: + Be able to set the comment via controller. + + Args: + comment (str): Comment text. + """ + + self._comment_input.setText(comment) + def make_sure_is_visible(self): if self._window_is_visible: self.setWindowState(QtCore.Qt.WindowActive) diff --git a/openpype/tools/utils/host_tools.py b/openpype/tools/utils/host_tools.py index 29c8c0ba8e..cc20774349 100644 --- a/openpype/tools/utils/host_tools.py +++ b/openpype/tools/utils/host_tools.py @@ -296,7 +296,8 @@ class HostToolsHelper: ILoadHost.validate_load_methods(host) publisher_window = PublisherWindow( - controller=controller, parent=parent or self._parent + controller=controller, + parent=parent or self._parent ) self._publisher_tool = publisher_window diff --git a/server_addon/houdini/server/settings/general.py b/server_addon/houdini/server/settings/general.py index 21cc4c452c..aee44f1648 100644 --- a/server_addon/houdini/server/settings/general.py +++ b/server_addon/houdini/server/settings/general.py @@ -25,6 +25,10 @@ class UpdateHoudiniVarcontextModel(BaseSettingsModel): class GeneralSettingsModel(BaseSettingsModel): + add_self_publish_button: bool = Field( + False, + title="Add Self Publish Button" + ) update_houdini_var_context: UpdateHoudiniVarcontextModel = Field( default_factory=UpdateHoudiniVarcontextModel, title="Update Houdini Vars on context change" @@ -32,6 +36,7 @@ class GeneralSettingsModel(BaseSettingsModel): DEFAULT_GENERAL_SETTINGS = { + "add_self_publish_button": False, "update_houdini_var_context": { "enabled": True, "houdini_vars": [ diff --git a/server_addon/houdini/server/version.py b/server_addon/houdini/server/version.py index bbab0242f6..1276d0254f 100644 --- a/server_addon/houdini/server/version.py +++ b/server_addon/houdini/server/version.py @@ -1 +1 @@ -__version__ = "0.1.4" +__version__ = "0.1.5"