In Python, all variables, functions and module names are in either the local namespace (restricted to a function) or in the global namespace. To see what names are available in the current namespace, type dir() in the interactive console.
The editor stores the Python global namespace. That is, all names that are available. When you execute a script, names in your script replace those in the global namespace. For example: in the interactive console define the following string.
s = "mystring"
Next, create a new script and execute it (any script will do, even an empty one). After this script executes, if you try to access your variable, the name is now undefined.
Traceback (most recent call last):File "<MotionBuilder>", line 1, in <module>NameError: name 's' is not defined
The names available in the editor and the Python global namespace are always the names defined in the last script executed plus all names defined after executing a script. This affects the Python object system and the autocomplete feature.
In the interactive console, access auto complete with Ctrl+Space.
Auto completion uses the Python global namespace to make a suggestion. That means, any name that can be found by typing dir() in the interactive console can be auto completed or examined to suggest completion for its member. However, how the auto complete list is populated depends on the state of the interactive console:
From a name contained in the global Python namespace, you can also use auto completion to know which functions and properties are available for an object. For example:
For example, entering FBEdit.On and pressing Ctrl+Space pops up a list of available events for FBEdit, since all property events begin with "On".
Autocompletion also works in the work area, in the same way as in the interactive console. It always checks the Python global namespace. To get the most out of the autocompletion feature, execute the script often, as in the following example.
from pyfbsdk import * from pyfbsdk_additions import *
tool.StartSizeX = 800 tool.StartSizeY = 200 ShowTool(tool)
It is good practice to execute a script each time you add new variables, and use autocompletion. If autocompletion does not work, either the name you are trying to complete is not in the global namespace, or you have a typing error.
External Custom Python Libraries
When setting up external custom Python libraries for use with MotionBuilder, if the application is having trouble finding the external Python libraries, ensure the environment variables contain a path to the appropriate directory, and that this path ends with a forward slash "/".