Esempio n. 1
0
    def _do_motionbuilder_post_publish(self, work_template, progress_cb):
        """
        Do any Motion Builder post-publish work

        :param work_template:   The primary work template used for the publish
        :param progress_cb:     Callback to be used when reporting progress
        """
        from pyfbsdk import FBApplication

        mb_app = FBApplication()
        
        progress_cb(0, "Versioning up the script")

        # get the current script path:
        original_path = mb_app.FBXFileName
        script_path = os.path.abspath(original_path)

        # increment version and construct new name:
        progress_cb(25, "Finding next version number")
        fields = work_template.get_fields(script_path)
        next_version = self._get_next_work_file_version(work_template, fields)
        fields["version"] = next_version
        new_path = work_template.apply_fields(fields)

        # log info
        self.parent.log_debug("Version up work file %s --> %s..." % (script_path, new_path))

        # save the script:
        progress_cb(75, "Saving the scene file")
        mb_app.FileSave(new_path)

        progress_cb(100)
    def execute(self, operation, file_path, **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)
                    
        :returns:               Depends on operation:
                                'current_path' - Return the current scene
                                                 file path as a String
                                all others     - None
        """

        fb_app = FBApplication()

        if operation == "current_path":
            # return the current scene path
            return fb_app.FBXFileName
        elif operation == "open":
            # do new scene as Maya doesn't like opening
            # the scene it currently has open!
            fb_app.FileOpen(file_path)
        elif operation == "save":
            # save the current scene:
            # Note - have to pass the current scene name to
            # avoid showing the save-as dialog
            fb_app.FileSave(fb_app.FBXFileName)
    def _clear_current_scene_motionbuilder(self):
        """
        Clears the current scene. Does a file -> new.
        Motionbuilder implementation.
        returns False on cancel, true on success.
        """
        from pyfbsdk import FBApplication
        status = True

        fb_app = FBApplication()

        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!
            fb_app.FileNew()

        else:
            # save before!
            fb_app.FileSave()
            fb_app.FileNew()

        return status
    def _do_motionbuilder_publish(self, task, work_template, comment,
                                  thumbnail_path, sg_task, progress_cb):
        """
        Publish the main Motion Builder scene

        :param task:            The primary task to publish
        :param work_template:   The primary work template to use
        :param comment:         The publish description/comment
        :param thumbnail_path:  The path to the thumbnail to associate with the published file
        :param sg_task:         The Shotgun task that this publish should be associated with
        :param progress_cb:     A callback to use when reporting any progress
                                to the UI
        :returns:               The path to the file that has been published        
        """
        from pyfbsdk import FBApplication

        mb_app = FBApplication()

        progress_cb(0.0, "Finding scene dependencies", task)
        dependencies = self._motionbuilder_find_additional_scene_dependencies()

        # get scene path
        scene_path = os.path.abspath(mb_app.FBXFileName)

        if not work_template.validate(scene_path):
            raise TankError(
                "File '%s' is not a valid work path, unable to publish!" %
                scene_path)

        # use templates to convert to publish path:
        output = task["output"]
        fields = work_template.get_fields(scene_path)
        fields["TankType"] = output["tank_type"]
        publish_template = output["publish_template"]
        publish_path = publish_template.apply_fields(fields)

        if os.path.exists(publish_path):
            raise TankError("The published file named '%s' already exists!" %
                            publish_path)

        # save the scene:
        progress_cb(10.0, "Saving the scene")
        self.parent.log_debug("Saving the scene...")
        mb_app.FileSave(scene_path)

        # copy the file:
        progress_cb(50.0, "Copying the file")
        try:
            publish_folder = os.path.dirname(publish_path)
            self.parent.ensure_folder_exists(publish_folder)
            self.parent.log_debug("Copying %s --> %s..." %
                                  (scene_path, publish_path))
            self.parent.copy_file(scene_path, publish_path, task)
        except Exception, e:
            raise TankError("Failed to copy file from %s to %s - %s" %
                            (scene_path, publish_path, e))
Esempio n. 5
0
    def _do_motionbuilder_post_publish(self, work_template, progress_cb,
                                       user_data):
        """
        Do any Motion Builder post-publish work

        :param work_template:   The primary work template used for the publish
        :param progress_cb:     Callback to be used when reporting progress
        :param user_data:       A dictionary containing any data shared by other hooks run prior to
                                this hook. Additional data may be added to this dictionary that will
                                then be accessible from user_data in any hooks run after this one.
        """
        from pyfbsdk import FBApplication

        mb_app = FBApplication()

        progress_cb(0, "Versioning up the script")

        # get the current script path:
        original_path = mb_app.FBXFileName
        script_path = os.path.abspath(original_path)

        # increment version and construct new name:
        progress_cb(25, "Finding next version number")
        fields = work_template.get_fields(script_path)
        next_version = self._get_next_work_file_version(work_template, fields)
        fields["version"] = next_version
        new_path = work_template.apply_fields(fields)

        # log info
        self.parent.log_debug("Version up work file %s --> %s..." %
                              (script_path, new_path))

        # save the script:
        progress_cb(75, "Saving the scene file")
        mb_app.FileSave(new_path)

        progress_cb(100)
Esempio n. 6
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
        """
        fb_app = FBApplication()

        if operation == "current_path":
            # return the current scene path
            return fb_app.FBXFileName
        elif operation == "open":
            # do new scene as Maya doesn't like opening
            # the scene it currently has open!
            fb_app.FileOpen(file_path)
        elif operation == "save":
            # save the current scene:
            # Note - have to pass the current scene name to
            # avoid showing the save-as dialog
            fb_app.FileSave(fb_app.FBXFileName)
        elif operation == "save_as":
            fb_app.FileSave(file_path)
        elif operation == "reset":
            """
            Reset the scene to an empty state
            """

            while True:
                # Note, there doesn't appear to be any way to query if
                # there are unsaved changes through the MotionBuilder
                # Python API.  Therefore we just assume there are and
                # prompt the user anyway!
                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:
                    # stop now!
                    return False
                elif res == QtGui.QMessageBox.No:
                    break
                else:
                    # save the file first
                    # Note - have to pass the current scene name to
                    # avoid showing the save-as dialog
                    if fb_app.FileSave(fb_app.FBXFileName):
                        break

            # perform file-new
            fb_app.FileNew()
            return True