FBPython Class Reference
 
 
 
FBPython Class Reference

#include <fbpython.h>


Class 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);

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

Definition at line 93 of file fbpython.h.

Static Public Member Functions

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

Member Function Documentation

static const char* FBPython::GetVersion ( ) [static]

Get the version of the Python interpreter.

Returns:
A string indicating the version of the interpreter.
static const char* FBPython::GetPlatform ( ) [static]

Get the target platform of the Python interpreter.

Returns:
A string indicating the platform for which the interpreter was compiled.
static const char* FBPython::GetStdout ( FBPythonContext pPythonContext = NULL ) [static]

Get the value of stdout.

Parameters:
pPythonContext Context to get the Stdout from.
Returns:
A string containing the last stdout output.
static const char* FBPython::GetStderr ( FBPythonContext pPythonContext = NULL ) [static]

Get the value of stderr.

Parameters:
pPythonContext Context to get the Stderr from.
Returns:
A string containing the last stderr output.
static bool FBPython::ParseLine ( const char *  pLine,
FBPythonContext pPythonContext = NULL 
) [static]

Submit a line of code for parsing.

Parameters:
pLine Line of code that the Python interpreter should parse.
pPythonContext Context 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)
static bool FBPython::EvalLine ( FBPythonContext pPythonContext = NULL ) [static]

Submit the last line of code parsed for evaluation.

Parameters:
pPythonContext Context 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)
static bool FBPython::EvalFile ( const char *  pFilename,
FBPythonContext pPythonContext = NULL 
) [static]

Execute a python script file within the given context.

Parameters:
pFilename The script file to execute.
pPythonContext Context 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.
static bool FBPython::ExecuteScript ( const char *  pFilename ) [static]

Put a python script file in the execution queue.

Clears the current context.

Parameters:
pFilename The 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.
static bool FBPython::ClearContext ( FBPythonContext pPythonContext = NULL ) [static]

Clears the python context.

Parameters:
pPythonContext Context 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.

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