Python Editor
MotionBuilder's Python Editor
The MotionBuilder Python Editor is accessed under Window > Python Editor. This editor is a convenient place to write and run Python programs for MotionBuilder. The Python Editor (as shown below) is composed of three major sections.
- A. Toolbar
- B. Interactive console
- C. Work area
Python Preferences
Editor preferences may be modified in MotionBuilder > Settings > Preferences > Python
. Syntax highlighting, line numbering, auto indentation, and script reloading are enabled by default. The color scheme and font styles for the work area and the interactive console may also be customized here.
The Python server can also be enabled through the Python Telnet Console, and incoming connections can be allowed. These features are enabled by default. The startup directory can be customized here. For more information, see Running Python Scripts.
Syntax Highlighting
Color | Description |
---|---|
Red | Comment |
Green | String |
Orange | Keyword |
Blue | Output |
Purple | Python reserved words |
Editor Commands and Shortcuts
Many editor commands are accessible from the toolbar; all are assigned keyboard shortcuts. There is no menu interface. In the interactive console, you can list shortcuts by hitting F1. The shortcut mappings for the editor are in config\Python\PythonKeyboard.txt. A graphical editor for this file is provided with the script KeyboardMapper.py.
By default, the Python editor has its own shortcut files. When it has focus, it uses its own shortcut mapping. So for example hitting Ctrl+S when it has focus saves the current script file and not the current MotionBuilder scene.
You can re-open a file, but this does not update other files referencing it. To update them, call the built-in Python function reload on the current script with the keyboard shortcut Shift+F1
. This is implemented in pythonidelib.py. This ensures that any other module referencing the reloaded module is updated.
To add a shortcut:
- Assign a shortcut to an action in the
PythonKeyboard.txt
file, either by editing the file in a text editor or by using the graphical interface provided by the script KeyboardMapper.py. - Assign a Python action to this shortcut in the file: config\Python\pythonidelib.py. The Python function bound to the shortcut takes as input one parameter: the name of the current script.
- To create the bindings between the shortcut and the function, change the shortcut variable (which is a Python dictionary).
Default Interactive Console Shortcuts
Shortcut | Description |
---|---|
Ctrl+T | New script (in new tab) |
Ctrl+O | Open script |
Ctrl+- | Close script |
Ctrl+S | Save |
F2 | Save As |
F1 | Context help |
Alt+C | Comment selection |
Alt+U | Uncomment selection |
Tab | Indent text block |
Ctrl+. | Next tab |
Ctrl+, | Previous tab |
Ctrl+G | Go to line |
Ctrl+F | Find |
F3 | Find next |
Ctrl+H | Find and replace |
F10 | Open the Python Tool Manager |
F5 | Execute script |
Ctrl+* | Add script to scene |
F7 | Debug current script |
Default Work Area Shortcuts
Shortcut | Description |
---|---|
Alt+N | Next command |
Alt+P | Previous command |
F1 | List shortcuts, or display in the interactive console help for the selected Python object. |
Inline Help
In the work area or the interactive console, select (highlight) a statement, and press F1
. Reference information is displayed in the interactive console. You can also do this by clicking the Contextual Help
tool in the toolbar.
Character Encoding
If you edit a script outside of MotionBuilder, it must be encoded with UTF-8 before you can open it in the MotionBuilder Python editor.
By default, Python assumes all scripts are written in ASCII. To use Unicode (e.g. to write a language other than American English), declare the encoding in the first or second line of your script like this: # coding=<encoding name>
. This line may not contain any Python statement. For more details, see "PEP 0263 -- Defining Python Source Code Encodings" at python.org.