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)
Esempio n. 2
0
def bootstrap_tank():

    try:
        import tank
    except Exception as e:
        FBMessageBox("Shotgun: Error",
                     "Could not import sgtk! Disabling for now: %s" % e, "Ok")
        return

    if not "TANK_ENGINE" in os.environ:
        FBMessageBox("Shotgun: Error",
                     "Missing required environment variable TANK_ENGINE.",
                     "Ok")
        return

    engine_name = os.environ.get("TANK_ENGINE")
    try:
        context = tank.context.deserialize(os.environ.get("TANK_CONTEXT"))
    except Exception as e:
        FBMessageBox(
            "Shotgun: Error",
            "Could not create context! Shotgun Pipeline Toolkit will be disabled. Details: %s"
            % e,
            "Ok",
        )
        return

    try:
        engine = tank.platform.start_engine(engine_name, context.tank, context)
    except Exception as e:
        FBMessageBox("Shotgun: Error", "Could not start engine: %s" % e, "Ok")
        return

    # if a file was specified, load it now
    file_to_open = os.environ.get("TANK_FILE_TO_OPEN")
    if file_to_open:
        FBApplication.FileOpen(file_to_open)

    # clean up temp env vars
    for var in ["TANK_ENGINE", "TANK_CONTEXT", "TANK_FILE_TO_OPEN"]:
        if var in os.environ:
            del os.environ[var]
Esempio n. 3
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
Esempio n. 4
0
        return

    engine_name = os.environ.get("TANK_ENGINE")
    try:
        context = tank.context.deserialize(os.environ.get("TANK_CONTEXT"))
    except Exception, e:
        FBMessageBox(
            "Shotgun: Error",
            "Could not create context! Shotgun Pipeline Toolkit will be disabled. Details: %s"
            % e, "Ok")
        return

    try:
        engine = tank.platform.start_engine(engine_name, context.tank, context)
    except Exception, e:
        FBMessageBox("Shotgun: Error", "Could not start engine: %s" % e, "Ok")
        return

    # if a file was specified, load it now
    file_to_open = os.environ.get("TANK_FILE_TO_OPEN")
    if file_to_open:
        FBApplication.FileOpen(file_to_open)

    # clean up temp env vars
    for var in ["TANK_ENGINE", "TANK_CONTEXT", "TANK_FILE_TO_OPEN"]:
        if var in os.environ:
            del os.environ[var]


bootstrap_tank()