Exemplo n.º 1
0
 def execute(self, operation, file_path, **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)
                 
     :returns:   Depends on operation:
                 'current_path' - Return the current scene
                                  file path as a String
                 all others     - None
     """
     from Py3dsMax import mxs
     if operation == "current_path":
         # return 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)
     elif operation == "save":
         # save the current scene:
         file_path = os.path.join(mxs.maxFilePath, mxs.maxFileName)
         mxs.saveMaxFile(file_path)
Exemplo n.º 2
0
 def execute(self, operation, file_path, context, parent_action, **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
                         
     :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
         if not mxs.maxFileName:
             return ""
         return os.path.join(mxs.maxFilePath, mxs.maxFileName)
     elif operation == "open":
         # open the specified scene
         mxs.loadMaxFile(file_path)
     elif operation == "save":
         # save the current scene:
         file_path = os.path.join(mxs.maxFilePath, mxs.maxFileName)
         mxs.saveMaxFile(file_path)
     elif operation == "save_as":
         # save the scene as file_path:
         mxs.saveMaxFile(file_path)
     elif operation == "reset":
         """
         Reset the scene to an empty state
         """
         # 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
    def load_item_from_path_3dsmax(self, path):

        from Py3dsMax import mxs
        
        # there is a file open
        if mxs.getSaveRequired():
            # there are unsaved changes in the scene
            # TODO: handle this for the user!
            
            # the currently opened file has not been saved
            mxs.messageBox("Your current scene has unsaved changes. Please save it before proceeding.")
            return
                    
        else:
            # no need to save any change. load new file.
            mxs.loadMaxFile(path)
    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
            if not mxs.maxFileName:
                return ""
            return os.path.join(mxs.maxFilePath, mxs.maxFileName)
        elif operation == "open":
            # 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 specified scene
            mxs.loadMaxFile(file_path)

        elif operation == "save":
            # save the current scene:
            file_path = os.path.join(mxs.maxFilePath, mxs.maxFileName)
            mxs.saveMaxFile(file_path)
        elif operation == "save_as":
            # 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)

            # save the scene as file_path:
            mxs.saveMaxFile(file_path)
Exemplo n.º 5
0
    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
            if not mxs.maxFileName:
                return ""
            return os.path.join(mxs.maxFilePath, mxs.maxFileName)
        elif operation == "open":
            # 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 specified scene
            mxs.loadMaxFile(file_path)
                
        elif operation == "save":
            # save the current scene:
            file_path = os.path.join(mxs.maxFilePath, mxs.maxFileName)
            mxs.saveMaxFile(file_path)
        elif operation == "save_as":
            # 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)
            
            # save the scene as file_path:
            mxs.saveMaxFile(file_path)