Example #1
0
def save_query(log):
    cancel = False

    if HOST == STANDALONE:
        from tentaculo.api import standalone
        cancel = standalone.message_function("save_query")[0]
    elif HOST == MAYA or HOST == MAYA2:
        file_name = mc.file(query=True, sceneName=True)
        need_save = mc.file(query=True, modified=True)
        if len(file_name) > 0 and need_save:
            ret = mc.confirmDialog(title='Closing file',
                                   message='Save current file?',
                                   messageAlign='center',
                                   button=['Yes', 'No', 'Cancel'],
                                   defaultButton='Yes',
                                   cancelButton='Cancel',
                                   dismissString='Cancel')
            if ret == "Yes":
                mc.file(save=True, type="mayaAscii")
            elif ret == "Cancel":
                cancel = True
    elif HOST == NUKE:
        cancel = not nuke.scriptClose()
    elif HOST == HOUDINI:
        need_save = hou.hipFile.hasUnsavedChanges()
        if need_save:
            hou.hipFile.clear()
            cancel = hou.hipFile.hasUnsavedChanges()
    elif HOST == MAX:
        cancel = not MaxPlus.FileManager.CheckForSave()
    elif HOST == C4D:
        doc = c4d.documents.GetActiveDocument()
        if doc is not None and doc.GetChanged():
            cancel = not c4d.documents.SaveDocument(
                doc,
                doc.GetDocumentPath() + "/" + doc.GetDocumentName(),
                c4d.SAVEDOCUMENTFLAGS_DIALOGSALLOWED, c4d.FORMAT_C4DEXPORT)
    elif HOST == BLENDER:
        if bpy.data.is_dirty:
            bpy.ops.wm.save_mainfile(check_existing=True)
            cancel = bpy.data.is_dirty
    elif HOST == KATANA:
        if KatanaFile.IsFileDirty():
            mb = UI4.App.Application.QtGui.QMessageBox(app_window())
            mb.setText("Closing file")
            mb.setInformativeText("Save current file?")
            mb.setStandardButtons(
                UI4.App.Application.QtGui.QMessageBox.Yes
                | UI4.App.Application.QtGui.QMessageBox.No
                | UI4.App.Application.QtGui.QMessageBox.Cancel)
            ret = mb.exec_()
            if ret == UI4.App.Application.QtGui.QMessageBox.Yes:
                KatanaFile.Save(
                    NodegraphAPI.NodegraphGlobals.GetProjectAssetID())
            cancel = ret == UI4.App.Application.QtGui.QMessageBox.Cancel

    return not cancel
Example #2
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 file_path
        elif operation == "open":
            KatanaFile.Load(file_path)
        elif operation == "save":
            if not os.path.exists(os.path.dirname(file_path)):
                os.makedirs(os.path.dirname(file_path))
            KatanaFile.Save(file_path)
        elif operation == "save_as":
            if not os.path.exists(os.path.dirname(file_path)):
                os.makedirs(os.path.dirname(file_path))
            KatanaFile.Save(file_path)

        elif operation == "reset":

            while KatanaFile.IsFileDirty():
                # 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:
                    if not os.path.exists(os.path.dirname(file_path)):
                        os.makedirs(os.path.dirname(file_path))
                KatanaFile.Save(
                    file_path)  # TODO: warning: this may not work...
            return True
    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 file_path:
            file_path = file_path.replace("/", os.path.sep)

        if operation == "current_path":
            # return the current script path
            return "/path/here".replace("/", os.path.sep)  # TODO!!

        elif operation == "open":
            # open the specified script
            KatanaFile.Load(file_path)

        elif operation == "save":
            # save the current script:
            if not os.path.exists(os.path.dirname(file_path)):
                os.makedirs(os.path.dirname(file_path))
            KatanaFile.Save(file_path)  # TODO: warning: this may not work...

        elif operation == "save_as":
            if not os.path.exists(os.path.dirname(file_path)):
                os.makedirs(os.path.dirname(file_path))
            KatanaFile.Save(file_path)

        elif operation == "reset":
            """
            Reset the scene to an empty state
            """
            while KatanaFile.IsFileDirty():
                # 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:
                    if not os.path.exists(os.path.dirname(file_path)):
                        os.makedirs(os.path.dirname(file_path))
                    KatanaFile.Save(
                        file_path)  # TODO: warning: this may not work...
            return True

        # Create a new engine instance from the existing one, with the new context
        # Specify "shot_step" environment if the current context specifies a step
        if context.step:
            env = context.tank.pipeline_configuration.get_environment(
                "shot_step", context=context)
        # Otherwise, just get a "project" level context
        else:
            env = context.tank.pipeline_configuration.get_environment(
                "project", context=context)

        name = "tk-katana"  # TODO: Get this properly?
        new_katana_engine = engine.KatanaEngine(context.tank, context, name,
                                                env)
        new_katana_engine.add_katana_menu()
Example #4
0
    def execute(self, operation, file_path, context, parent_action,
                file_version, read_only, **kwargs):
        """Main hook entry point.

        Args:
            operation (str):
                Scene operation to perform

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

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

            parent_action (str):
                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 (bool):
                Specifies if the file should be opened read-only or not

        Returns:
            object: Depending on ``operation``:

                - 'current_path': Current scene file path as a ``str``
                - '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 file_path

        elif operation == "open":
            KatanaFile.Load(file_path)

        elif operation == "save":
            if not os.path.exists(os.path.dirname(file_path)):
                os.makedirs(os.path.dirname(file_path))
            KatanaFile.Save(file_path)

        elif operation == "save_as":
            if not os.path.exists(os.path.dirname(file_path)):
                os.makedirs(os.path.dirname(file_path))
            KatanaFile.Save(file_path)

        elif operation == "reset":
            while KatanaFile.IsFileDirty():
                # 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:
                    if not os.path.exists(os.path.dirname(file_path)):
                        os.makedirs(os.path.dirname(file_path))
                KatanaFile.Save(
                    file_path)  # TODO: warning: this may not work...

            return True