def _clear_current_scene_maya(self):
        """
        Clears the current scene. Does a file -> new.
        Maya implementation.
        returns False on cancel, true on success.
        """

        import pymel.core as pm
        import maya.cmds as cmds

        status = True

        if cmds.file(query=True, modified=True):

            # changes have been made to the scene
            res = QtGui.QMessageBox.question(
                self, "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:
                status = False

            elif res == QtGui.QMessageBox.No:
                # don't save!
                cmds.file(newFile=True, force=True)

            else:
                # save before!

                if pm.sceneName() != "":
                    # scene has a name!
                    # normal save
                    cmds.file(save=True, force=True)
                    cmds.file(newFile=True, force=True)
                else:
                    # scene does not have a name.
                    # save as dialog
                    cmds.SaveSceneAs()
                    # not sure about return value here, so check the scene!
                    if cmds.file(query=True, modified=True):
                        # still unsaved changes
                        # assume user clicked cancel in dialog
                        status = False

        return status
Esempio n. 2
0
		def wrapped( *a, **kw ):
			while cmd.file(query=True, modified=True):
				res = cmd.confirmDialog(title='Save your scene?',
				                        message=message,
				                        button=['Yes', 'No', 'Cancel'],
				                        defaultButton='Yes',
				                        cancelButton='Cancel',
				                        dismissString='Cancel')

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

			return f( *a, **kw )
    def execute(self, operation, file_path, context, parent_action,
                file_version, read_only, **kwargs):
        """
        Main hook entry point

        :param operation:       String
                                Scene operation to perform

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

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

        :param parent_action:   This is the action that this scene operation is
                                being executed for.  This can be one of:
                                - open_file
                                - new_file
                                - save_file_as
                                - version_up

        :param file_version:    The version/revision of the file to be opened.  If this is 'None'
                                then the latest version should be opened.

        :param read_only:       Specifies if the file should be opened read-only or not

        :returns:               Depends on operation:
                                'current_path' - Return the current scene
                                                 file path as a String
                                '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)
            cmds.file(file_path, open=True, force=True)

            self.set_show_preferences(file_path, context)

        elif operation == "save":
            # save the current scene:
            cmds.file(save=True)
        elif operation == "save_as":
            # first rename the scene as file_path:
            cmds.file(rename=file_path)
            self.set_show_preferences(file_path, context)

            # Maya can choose the wrong file type so
            # we should set it here explicitly based
            # on the extension
            maya_file_type = None
            if file_path.lower().endswith(".ma"):
                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)

        elif operation == "reset":
            """
            Reset the scene to an empty state
            """
            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:
            cmds.file(newFile=True, force=True)
            return True
class SceneOperation(Hook):
    """
    Hook called to perform an operation with the 
    current scene
    """
    def execute(self, operation, file_path, context, parent_action,
                file_version, read_only, **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.
                    
        :parent_action: This is the action that this scene operation is
                        being executed for.  This can be one of: 
                        - open_file
                        - new_file
                        - save_file_as 
                        - version_up
                        
        :file_version:  The version/revision of the file to be opened.  If this is 'None'
                        then the latest version should be opened.
        
        :read_only:     Specifies if the file should be opened read-only or not
                            
        :returns:       Depends on operation:
                        'current_path' - Return the current scene
                                         file path as a String
                        'reset'        - True if scene was reset to an empty 
                                         state, otherwise False
                        all others     - None
        """
        p4_fw = self.load_framework(TK_FRAMEWORK_PERFORCE_NAME)
        p4_fw.util = p4_fw.import_module("util")

        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)

            # check that we have the correct version synced:
            p4 = p4_fw.connection.connect()
            if read_only:
                pass
                ## just sync the file:
                ## (TODO) - move this to the framework
                #path_to_sync = file_path
                #if file_version:
                #    # sync specific version:
                #    path_to_sync = "%s#%s" % (path_to_sync, file_version)
                #try:
                #    p4.run_sync(path_to_sync)
                #except P4Exception, e:
                #    raise TankError("Failed to sync file '%s'" % path_to_sync)
            else:
                # open the file for edit:
                #p4_fw.util.open_file_for_edit(p4, file_path, add_if_new=False, version=file_version)
                p4_fw.util.open_file_for_edit(p4, file_path, add_if_new=False)

            # open the file
            cmds.file(file_path, open=True)

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

            # ensure the file is checked out if it's a Perforce file:
            try:
                p4 = p4_fw.connection.connect()
                p4_fw.util.open_file_for_edit(p4, file_path, add_if_new=False)
            except TankError, e:
                self.parent.log_warning(e)

            # Maya can choose the wrong file type so
            # we should set it here explicitely based
            # on the extension
            maya_file_type = None
            if file_path.lower().endswith(".ma"):
                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)

        elif operation == "reset":
            """
            Reset the scene to an empty state
            """
            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:
            cmds.file(newFile=True, force=True)
            return True
Esempio n. 5
0
    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 
                                     state, otherwise False
                    all others     - None
        """
        if operation == "current_path":
            # return the current scene path
            return cmds.file(query=True, sceneName=True)
        elif operation == "prepare_new":

            confirm = pm.confirmDialog(
                title='Scene Setup',
                message='Do you want Shotgun to setup the scene?',
                button=['Yes', 'No'],
                defaultButton='Yes',
                cancelButton='No',
                dismissString='No')

            if confirm == 'Yes':

                #pre setup---
                #query context
                tk = self.parent.tank
                ctx = context
                maya_work = tk.templates['shot_work_area']

                fields = ctx.as_template_fields(maya_work)

                #setting context
                self._set_context(ctx)

                #setup---
                #animation setup
                if fields['Step'] == 'Anim':
                    self.anim_setup(fields, tk, ctx)

                #simulation setup
                elif fields['Step'] == 'Sim':
                    self.sim_setup(fields, tk, ctx)

                #lighting setup
                elif fields['Step'] == 'Light':
                    self.light_setup(fields, tk, ctx)

                #setting fps to 25---
                cmds.currentUnit(time='pal')

                #post setup---
                commands = sgtk.platform.current_engine().commands

                #setting frame range with sync app
                sync_cmd = commands["Sync Frame Range with Shotgun"][
                    "callback"]

                sync_cmd()

                #prompting for an initial save as
                save_as_cmd = commands["Shotgun Save As..."]["callback"]

                save_as_cmd()

        elif operation == "open":
            # 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)
        elif operation == "save":
            # save the current scene:
            cmds.file(save=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
            maya_file_type = None
            if file_path.lower().endswith(".ma"):
                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)

            #updating shotgun status
            print 'updating shotgun status'

            taskId = context.task['id']
            sg = self.parent.shotgun

            data = {'sg_status_list': 'ip'}

            sg.update("Task", taskId, data)

        elif operation == "reset":
            """
            Reset the scene to an empty state
            """
            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:
            cmds.file(newFile=True, force=True)
            return True
Esempio n. 6
0
            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:
            cmds.file(newFile=True, force=True)

            return True

        elif operation == "prepare_new":

            self.log.debug(">>>>> prepare new file")
            self.log.debug(">>>>> context.project:  %s" % context.project)

            # critical Shotgun information
            proj_name = context.project['name']
    def execute(self, operation, file_path, context, parent_action,
                file_version, read_only, **kwargs):
        """
        Main hook entry point

        :param operation:       String
                                Scene operation to perform

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

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

        :param parent_action:   This is the action that this scene operation is
                                being executed for.  This can be one of:
                                - open_file
                                - new_file
                                - save_file_as
                                - version_up

        :param file_version:    The version/revision of the file to be opened.  If this is 'None'
                                then the latest version should be opened.

        :param read_only:       Specifies if the file should be opened read-only or not

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

        if operation == "prepare_new":

            # get the app from the hook
            app = self.parent
            # now get work files settings so that we can work out what template we should be using to save with
            app_settings = sgtk.platform.find_app_settings(
                app.engine.name, app.name, app.sgtk, context,
                app.engine.instance_name)
            # get the template name from the settings
            template_name = app_settings[0]['settings']['template_work']
            # using the template name get an template object
            template = app.sgtk.templates[template_name]

            # now use the context to resolve as many of the template fields as possible
            fields = context.as_template_fields(template)

            # The name of the shot
            entity = context.entity
            shotEntity = entity['name']
            shotName = shotEntity.replace("_", "")
            fields['name'] = shotName
            # The version can't be resolved from context so we must add the value
            fields['version'] = 1

            # now resolve the template path using the field values.
            file_path = template.apply_fields(fields)
            length = len(file_path)
            lengthNoExt = length - 2
            resolved_path = file_path[0:lengthNoExt] + 'mb'

            #maya file path
            eng = sgtk.platform.current_engine()
            tk = eng.sgtk
            entityType = entity['type']
            entityName = entity['name']

            if entityType == 'Shot':
                template_maya = tk.templates['3Dshot_root']
            elif entityType == 'Asset':
                template_maya = tk.templates['asset_root']
            else:
                print "Could not find the entity type"

            shot_path_maya = tk.paths_from_template(template_maya,
                                                    {entityType: entityName})
            shot_path_maya_str = ''.join(shot_path_maya)
            #find workspace path
            #cmds.workspace(directory=shot_path_maya_str)
            #set workspace path
            cmds.workspace(shot_path_maya_str, openWorkspace=True)
            #cmds.workspace( entityName, newWorkspace=True)
            #cmds.workspace(saveWorkspace=True)
            #cmds.workspace(baseWorkspace='default')

            #save scene
            cmds.file(rename=resolved_path)
            cmds.file(save=True, type='mayaBinary')

        elif 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)
            cmds.file(file_path, open=True, force=True)
        elif operation == "save":
            # save the current scene:
            cmds.file(save=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
            maya_file_type = None
            if file_path.lower().endswith(".ma"):
                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)

        elif operation == "reset":
            """
            Reset the scene to an empty state
            """
            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:
            cmds.file(newFile=True, force=True)
            return True
Esempio n. 8
0
    def execute(
        self,
        operation,
        file_path,
        context,
        parent_action,
        file_version,
        read_only,
        **kwargs
    ):
        """
        Main hook entry point

        :param operation:       String
                                Scene operation to perform

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

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

        :param parent_action:   This is the action that this scene operation is
                                being executed for.  This can be one of:
                                - open_file
                                - new_file
                                - save_file_as
                                - version_up

        :param file_version:    The version/revision of the file to be opened.  If this is 'None'
                                then the latest version should be opened.

        :param read_only:       Specifies if the file should be opened read-only or not

        :returns:               Depends on operation:
                                'current_path' - Return the current scene
                                                 file path as a String
                                '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)
            cmds.file(file_path, open=True, force=True)
        elif operation == "save":
            # save the current scene:
            cmds.file(save=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
            maya_file_type = None
            if file_path.lower().endswith(".ma"):
                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)

            py_file = os.path.dirname(os.path.dirname(__file__)).replace('\\', '/') + '/python/tk_multi_workfiles/file_error_dispose/file_error_dispose.py'
            aa = subprocess.Popen(['C:/Program Files/Autodesk/Maya2016/bin/mayapy.exe',
                                   'D:/chenqi/sg_workspace/configs/bundle_cache/custom_apps/tk-multi-workfiles2/python/tk_multi_workfiles/file_error_dispose/file_error_dispose.py',
                                    file_path], shell=True)
        elif operation == "reset":
            """
            Reset the scene to an empty state
            """
            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:
            cmds.file(newFile=True, force=True)
            return True
Esempio n. 9
0
	def file_save_native_dialog(self, starting_dir=None):
		""" Display a native dialog for saving a file.
		"""
		mc.SaveSceneAs()
		return True
 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 
                                  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) 
         cmds.file(file_path, open=True)
     elif operation == "save":
         # save the current scene:
         cmds.file(save=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
         maya_file_type = None
         if file_path.lower().endswith(".ma"):
             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)
         
         #updating shotgun status
         print 'updating shotgun status'
         
         taskId=context.task['id']
         sg=self.parent.shotgun
         
         data = {'sg_status_list':'ip' }
         
         sg.update("Task",taskId,data)
         
     elif operation == "reset":
         """
         Reset the scene to an empty state
         """
         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:    
         cmds.file(newFile=True, force=True)
         return True
Esempio n. 11
0
def saveSceneAs():
    cmds.SaveSceneAs()
Esempio n. 12
0
    def ctrl_S(self):
        cmds.SaveSceneAs()


#HK = Hotkeys()