Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Reset current scene now prefers using Tank Apps for saving. #11

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 28 additions & 18 deletions hooks/scene_operation_tk-3dsmax.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,62 +12,72 @@

class SceneOperation(Hook):
"""
Hook called to perform an operation with the
Hook called to perform an operation with the
current scene
"""

def execute(self, operation, file_path, context, **kwargs):
"""
Main hook entry point

:operation: String
Scene operation to perform

:file_path: String
File path to use if the operation
requires it (e.g. open)

:context: Context
The context the file operation is being
performed in.

:returns: Depends on operation:
'current_path' - Return the current scene
file path as a String
'reset' - True if scene was reset to an empty
'reset' - True if scene was reset to an empty
state, otherwise False
all others - None
"""

if operation == "current_path":
# return the current scene path
"""
Returns the current scene path
"""
if not mxs.maxFileName:
return ""
return os.path.join(mxs.maxFilePath, mxs.maxFileName)

elif operation == "open":
# open the specified scene
mxs.loadMaxFile(file_path)
return True

elif operation == "save":
# save the current scene:
file_path = os.path.join(mxs.maxFilePath, mxs.maxFileName)
mxs.saveMaxFile(file_path)
return True

elif operation == "save_as":
# save the scene as file_path:
mxs.saveMaxFile(file_path)
return True

elif operation == "scene_modified":
"""
Returns True if the current scene is dirty
"""
return mxs.getSaveRequired()

elif operation == "reset":
"""
Reset the scene to an empty state
Reset the scene to an empty state.
Does not check if saving is needed.
"""
# use the standard Max mechanism to check
# for and save the file if required:
if not mxs.checkForSave():
return False

# now reset the scene:
mxs.resetMAXFile(mxs.pyhelper.namify("noPrompt"))

return True

else:
raise TankError("Don't know how to perform scene operation '%s'" % operation)


62 changes: 29 additions & 33 deletions hooks/scene_operation_tk-maya.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,47 +13,52 @@

class SceneOperation(Hook):
"""
Hook called to perform an operation with the
Hook called to perform an operation with the
current scene
"""

def execute(self, operation, file_path, context, **kwargs):
"""
Main hook entry point

:operation: String
Scene operation to perform

:file_path: String
File path to use if the operation
requires it (e.g. open)

:context: Context
The context the file operation is being
performed in.

:returns: Depends on operation:
'current_path' - Return the current scene
file path as a String
'reset' - True if scene was reset to an empty
'reset' - True if scene was reset to an empty
state, otherwise False
all others - None
"""
if operation == "current_path":
# return the current scene path
return cmds.file(query=True, sceneName=True)

elif operation == "open":
# do new scene as Maya doesn't like opening
# the scene it currently has open!
cmds.file(new=True, force=True)
# do new scene as Maya doesn't like opening
# the scene it currently has open!
cmds.file(new=True, force=True)
cmds.file(file_path, open=True)
return True

elif operation == "save":
# save the current scene:
cmds.file(save=True)
return True

elif operation == "save_as":
# first rename the scene as file_path:
cmds.file(rename=file_path)

# Maya can choose the wrong file type so
# we should set it here explicitely based
# on the extension
Expand All @@ -62,38 +67,29 @@ def execute(self, operation, file_path, context, **kwargs):
maya_file_type = "mayaAscii"
elif file_path.lower().endswith(".mb"):
maya_file_type = "mayaBinary"

# save the scene:
if maya_file_type:
cmds.file(save=True, force=True, type=maya_file_type)
else:
cmds.file(save=True, force=True)

return True

elif operation == "scene_modified":
"""
Returns True if the current scene is dirty
"""
return cmds.file(query=True, modified=True)

elif operation == "reset":
"""
Reset the scene to an empty state
Reset the scene to an empty state.
Does not check if saving is needed.
"""
while cmds.file(query=True, modified=True):
# changes have been made to the scene
res = QtGui.QMessageBox.question(None,
"Save your scene?",
"Your scene has unsaved changes. Save before proceeding?",
QtGui.QMessageBox.Yes|QtGui.QMessageBox.No|QtGui.QMessageBox.Cancel)

if res == QtGui.QMessageBox.Cancel:
return False
elif res == QtGui.QMessageBox.No:
break
else:
scene_name = cmds.file(query=True, sn=True)
if not scene_name:
cmds.SaveSceneAs()
else:
cmds.file(save=True)

# do new file:
# do new file:
cmds.file(newFile=True, force=True)
return True

else:
raise TankError("Don't know how to perform scene operation '%s'" % operation)

Expand Down
79 changes: 39 additions & 40 deletions hooks/scene_operation_tk-nuke.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,95 +13,94 @@

class SceneOperation(Hook):
"""
Hook called to perform an operation with the
Hook called to perform an operation with the
current scene
"""

def execute(self, operation, file_path, context, **kwargs):
"""
Main hook entry point

:operation: String
Scene operation to perform

:file_path: String
File path to use if the operation
requires it (e.g. open)

:context: Context
The context the file operation is being
performed in.

:returns: Depends on operation:
'current_path' - Return the current scene
file path as a String
'reset' - True if scene was reset to an empty
'reset' - True if scene was reset to an empty
state, otherwise False
all others - None
"""

if file_path:
file_path = file_path.replace("/", os.path.sep)

if operation == "current_path":
# return the current script path
return nuke.root().name().replace("/", os.path.sep)

scene_name = nuke.root().name()
if scene_name == "Root":
return ""
return scene_name.replace("/", os.path.sep)

elif operation == "open":
# open the specified script
nuke.scriptOpen(file_path)

# reset any write node render paths:
if self._reset_write_node_render_paths():
# something changed so make sure to save the script again:
nuke.scriptSave()

return True

elif operation == "save":
# save the current script:
nuke.scriptSave()

elif operation == "save_as":
old_path = nuke.root()["name"].value()
try:
# rename script:
nuke.root()["name"].setValue(file_path)

# reset all write nodes:
self._reset_write_node_render_paths()

# save script:
nuke.scriptSaveAs(file_path, -1)
nuke.scriptSaveAs(file_path, -1)
except Exception, e:
# something went wrong so reset to old path:
nuke.root()["name"].setValue(old_path)
raise TankError("Failed to save scene %s", e)

elif operation == "reset":
return True

elif operation == "scene_modified":
"""
Reset the scene to an empty state
Returns True if the current scene is dirty
"""
while nuke.root().modified():
# changes have been made to the scene
res = QtGui.QMessageBox.question(None,
"Save your script?",
"Your script has unsaved changes. Save before proceeding?",
QtGui.QMessageBox.Yes|QtGui.QMessageBox.No|QtGui.QMessageBox.Cancel)

if res == QtGui.QMessageBox.Cancel:
return False
elif res == QtGui.QMessageBox.No:
break
else:
nuke.scriptSave()
return nuke.root().modified()

elif operation == "reset":
"""
Reset the scene to an empty state.
Does not check if saving is needed.
"""
# now clear the script:
nuke.scriptClear()

nuke.createNode("Viewer")
return True

else:
raise TankError("Don't know how to perform scene operation '%s'" % operation)


def _reset_write_node_render_paths(self):
"""
Use the tk-nuke-writenode app interface to find and reset
Expand All @@ -110,11 +109,11 @@ def _reset_write_node_render_paths(self):
write_node_app = self.parent.engine.apps.get("tk-nuke-writenode")
if not write_node_app:
return

write_nodes = write_node_app.get_write_nodes()
for write_node in write_nodes:
write_node_app.reset_node_render_path(write_node)

return len(write_nodes) > 0


Loading