Skip to content

Commit

Permalink
Merge pull request #3 from nfa-vfxim/feature/add-background-save
Browse files Browse the repository at this point in the history
Background save option
  • Loading branch information
mervinvb authored Nov 18, 2024
2 parents e0012e1 + 94ca469 commit 84b7bac
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
4 changes: 2 additions & 2 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ def init_app(self):
tk_houdini_usdrop = self.import_module("tk_houdini_usdrop")
self.handler = tk_houdini_usdrop.TkUSDRopNodeHandler(self)

def execute_export(self, node):
self.handler.execute_export(node)
def execute_export(self, node, is_background_export):
self.handler.execute_export(node, is_background_export)

def get_nodes(self):
# Get all nodes from this session
Expand Down
Binary file modified otls/sgtk_usd_rop.otl
Binary file not shown.
30 changes: 25 additions & 5 deletions python/tk_houdini_usdrop/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ class TkUSDRopNodeHandler(object):
def __init__(self, app):
self.app = app

def execute_export(self, node):
def execute_export(self, node, is_background_export):
inputs = node.inputs()
if len(inputs) > 0:
file_path = self.calculate_path(node)
self.execute_usd_export(node, file_path)
self.execute_usd_export(node, file_path, is_background_export)
else:
message = "ShotGrid USD ROP node not connected to any input."
self.app.logger.debug(message)
Expand All @@ -28,6 +28,16 @@ def calculate_path(self, node):
fields = work_template.get_fields(current_filepath)
fields["name"] = node.parm("name").eval()

# Validate name parm is alphanumeric
regex = re.compile("^[a-zA-Z0-9_-]*$")
match = regex.match(fields["name"])
if not match:
hou.ui.displayMessage(
"You may only use letters and numbers for the publish name!",
severity=hou.severityType.Error,
)
return

# Apply fields
file_path = usd_template.apply_fields(fields).replace(os.sep, "/")

Expand Down Expand Up @@ -88,8 +98,7 @@ def get_layer_type(node):

return layer

def execute_usd_export(self, node, file_path):

def execute_usd_export(self, node, file_path, is_background_export):
# Set all SGTK Configure Layers node to the correct path
layer_nodes = (
hou.lopNodeTypeCategory().nodeType("sgtk_configurelayer").instances()
Expand All @@ -98,10 +107,21 @@ def execute_usd_export(self, node, file_path):
self.populate_configure_layers(layer_nodes, file_path)

# Set filepath on SGTK USD ROP node to the publish path
if file_path is None:
self.app.logger.error(
"File path is None. An invalid publish name was probably used."
)
return

node.parm("path").set(file_path)

try:
# Execute the USD Export
node.node("usd_rop").parm("execute").pressButton()
if is_background_export:
hou.hipFile.save()
node.node("usd_rop").parm("executebackground").pressButton()
else:
node.node("usd_rop").parm("execute").pressButton()
self.app.logger.debug("Exported USD %s." % file_path)

except Exception as e:
Expand Down

0 comments on commit 84b7bac

Please sign in to comment.