Open Reality Reference Guide
FBPython Class Reference

FBPython is for python users to run python script and communicate with MotionBuilder internal python facility. More...

#include <fbpython.h>

Static Public Member Functions

static const char * GetVersion ()
 Get the version of the Python interpreter. More...
 
static const char * GetPlatform ()
 Get the target platform of the Python interpreter. More...
 
static const char * GetStdout (FBPythonContext *pPythonContext=NULL)
 Get the value of stdout. More...
 
static const char * GetStderr (FBPythonContext *pPythonContext=NULL)
 Get the value of stderr. More...
 
static bool ParseLine (const char *pLine, FBPythonContext *pPythonContext=NULL)
 Submit a line of code for parsing. More...
 
static bool EvalLine (FBPythonContext *pPythonContext=NULL)
 Submit the last line of code parsed for evaluation. More...
 
static bool EvalLines (const char *pScript, FBPythonContext *pPythonContext=NULL)
 Submit a script for parsing and execution. More...
 
static bool EvalFile (const char *pFilename, FBPythonContext *pPythonContext=NULL)
 Execute a python script file within the given context. More...
 
static bool ExecuteScript (const char *pFilename)
 Put a python script file in the execution queue. More...
 
static bool ClearContext (FBPythonContext *pPythonContext=NULL)
 Clears the python context. More...
 

Detailed Description

FBPython is for python users to run python script and communicate with MotionBuilder internal python facility.

Warning: When the user is calling the methods of FBPython in another thread other than MotionBuilder main thread, the user needs to create new thread state because Python internally prevents from illegal access to its internal Python objects if the current thread is not created by Python or has no thread state. In order to address this issue, the user could use the following workaround.

PyGILState_STATE gstate;
gstate = PyGILState_Ensure();
FBPython::ParseLine("import sys");
FBPython::EvalLine(); // MotionBuilder would crash if PyGILState_Ensure is not called before it.
PyGILState_Release(gstate);
static bool EvalLine(FBPythonContext *pPythonContext=NULL)
Submit the last line of code parsed for evaluation.
static bool ParseLine(const char *pLine, FBPythonContext *pPythonContext=NULL)
Submit a line of code for parsing.

PyGILState_Ensure will create a new thread state for current calling thread.

Definition at line 93 of file fbpython.h.

Member Function Documentation

◆ ClearContext()

static bool ClearContext ( FBPythonContext pPythonContext = NULL)
static

Clears the python context.

Parameters
pPythonContextContext to clear.
Returns
false If there were no interpreter or if the context is invalid.
true If there was a Python interpreter and the context was valid.

◆ EvalFile()

static bool EvalFile ( const char *  pFilename,
FBPythonContext pPythonContext = NULL 
)
static

Execute a python script file within the given context.

Parameters
pFilenameThe script file to execute.
pPythonContextContext in which the parse will occur.
Returns
false If there were no interpreter or there were errors/unhandled exceptions. (consult stderr for more infos)
true If there was a Python interpreter and the code ran succesfully. (consult stdout for output, if any)
Remarks
This function can only be used in the UI thread.

◆ EvalLine()

static bool EvalLine ( FBPythonContext pPythonContext = NULL)
static

Submit the last line of code parsed for evaluation.

Parameters
pPythonContextContext in which the execution will occur.
Returns
false If there were no interpreter or there were errors/unhandled exceptions. (consult stderr for more infos)
true If there was a Python interpreter and the code ran succesfully. (consult stdout for output, if any)

◆ EvalLines()

static bool EvalLines ( const char *  pScript,
FBPythonContext pPythonContext = NULL 
)
static

Submit a script for parsing and execution.

Parameters
pScriptString to evaluate.
pPythonContextContext in which the execution will occur.
Returns
false If there were no interpreter or there were errors/unhandled exceptions. (consult stderr for more infos)
true If there was a Python interpreter and the code ran succesfully. (consult stdout for output, if any)

◆ ExecuteScript()

static bool ExecuteScript ( const char *  pFilename)
static

Put a python script file in the execution queue.

Clears the current context.

Parameters
pFilenameThe script file to execute.
Returns
false If there were no interpreter or there were errors/unhandled exceptions. (consult stderr for more infos)
true If there was a Python interpreter and the code ran succesfully. (consult stdout for output, if any)
Remarks
This function can be used in any thread.

◆ GetPlatform()

static const char* GetPlatform ( )
static

Get the target platform of the Python interpreter.

Returns
A string indicating the platform for which the interpreter was compiled.

◆ GetStderr()

static const char* GetStderr ( FBPythonContext pPythonContext = NULL)
static

Get the value of stderr.

Parameters
pPythonContextContext to get the Stderr from.
Returns
A string containing the last stderr output.

◆ GetStdout()

static const char* GetStdout ( FBPythonContext pPythonContext = NULL)
static

Get the value of stdout.

Parameters
pPythonContextContext to get the Stdout from.
Returns
A string containing the last stdout output.

◆ GetVersion()

static const char* GetVersion ( )
static

Get the version of the Python interpreter.

Returns
A string indicating the version of the interpreter.

◆ ParseLine()

static bool ParseLine ( const char *  pLine,
FBPythonContext pPythonContext = NULL 
)
static

Submit a line of code for parsing.

Parameters
pLineLine of code that the Python interpreter should parse.
pPythonContextContext in which the parse will occur.
Returns
true If there was a Python interpreter and the line was valid.
false If there were no interpreter or if there was an error parsing the code (consult stderr for more infos)

The documentation for this class was generated from the following file: