[MB][Python][PySide] Callback at the start of Motion Builder

Hello, I’m trying to display a window at the start of motion builder with Python. Thanks to this autodesk’ site : http://docs.autodesk.com/MOBPRO/2016/ENU/MotionBuilder-Developer-Help/files/GUID-391A97C9-35B9-4C98-A8CE-5CD718A7D70A.htm
I managed to launch my script before the app was even ready. My window is perfectly displaying but this blocks motion builder from opening until I closed my generated window.

So I tried to look for events that I could use to execute my script and failed.
The event that I tried to use is FBApplication.OnFileOpenCompleted. I put my script into a def and run with the event, and now my def is not calling at all.

Here is the script.

from PySide2 import QtCore, QtGui, QtWidgets
import sys
import interface.testInterface as uiInterfaceTest

    from pyfbsdk import *

    class MainWindow(QtWidgets.QWidget, uiInterfaceTest.Ui_Dialog):
    	def __init__(self):
    		super(MainWindow, self).__init__()


    def launchApp(pCaller, pEvent):
    	print "launchApp enter"

    	myApp = QtWidgets.QApplication.instance()
    	window = MainWindow()

    mobuApp = FBApplication()

If you have any ideas of “how to run a script that opens a window proprely at the start of MB” that would be appreciate! Thank you for your time.

Hey @GuillaumeR, Welcome to the forum!

  1. In your first test, I assume you created your own startup folder? Looks to be the last thing that gets called from the link you provided. Note #4.

  2. Does Mobu load an existing file or create a new scene on start up? If so you may need to use the FileNew() callback. Note though - make sure your de-registering your callbacks when not in use.

If you’re encapsulating startup in a toolchain, you might be able to just pass the script to the command line.

Hey @chalk !
Thank you for the welcome and the answer.

Unfortunately, the callback seems to be saved in the memory or something for the next action while MB is open. So it does working if I open MotionBuilder AND if I do “File new” from the file menu. (Even like that, it seems that my window won’t open, but the print is happening !)

For the moment I will go for adding a menu in the menu bar that leads to a better result in my opinion.

The callback runs every time a new scene is instantiated.
This includes, file new and open and probably even merge?
If you want it to run once, then you need to add logic to unregister it from within itself once it has run.

Hey @GuillaumeR,

The very first post you supplied, shows an example of both registering the callback and deregistering it:


# Register the callback function to the OnFileNew event.

# Create a new scene. This triggers the OnFileNew event.

# Remove the callback function we have created when we are done.

Callbacks are great for modal state - i.e. going into a mode, doing something then leaving. A good analogy is a while state or a with context in Python.

Question for you - Do you want this dialog to only pop up when you start up Mobu or every time you create a file? From your initial post it sounds like the former - imo I would roll this into either a start-up script or as a command line argument. It sounds like you want to steer users instead of it being a tool they use, but knowing more about what your looking for would be helpful.

About the script, I wanted to create an interface where the user could load different scripts. And so I wanted that script to launch at the start up. Because the interface showed up before mobu and because the callback was not working with my Interface, I created a menu in the menu bar. This way works better that I expected.

That’s what I did with the functions that Chalk sent. It works if I open a new scene while Mobu is open. I can’t add my function to the event before the event is triggered.