-
Notifications
You must be signed in to change notification settings - Fork 9
/
maya_python_c_ext_plugin_main.cpp
51 lines (36 loc) · 1.09 KB
/
maya_python_c_ext_plugin_main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include "maya_python_c_ext_plugin_main.h"
#include <maya/MFnPlugin.h>
const char *kAUTHOR = "Siew Yi Liang";
const char *kVERSION = "1.0.0";
const char *kREQUIRED_API_VERSION = "Any";
PyObject *module = NULL;
MStatus initializePlugin(MObject obj)
{
MFnPlugin plugin(obj, kAUTHOR, kVERSION, kREQUIRED_API_VERSION);
if (!Py_IsInitialized()) {
Py_Initialize();
}
if (Py_IsInitialized()) {
// NOTE: (sonictk) Since the Maya main thread is not a Python thread, we
// need to register the GIL (thread state structure) towards that thread
// so that the Python interpreter can see it and execute the code without
// crashing Maya.
PyGILState_STATE pyGILState = PyGILState_Ensure();
module = Py_InitModule3("maya_python_c_ext",
mayaPythonCExtMethods,
MAYA_PYTHON_C_EXT_DOCSTRING);
MGlobal::displayInfo("Registered Python bindings!");
if (module == NULL) {
return MStatus::kFailure;
}
Py_INCREF(module);
PyGILState_Release(pyGILState);
}
return MStatus::kSuccess;
}
MStatus uninitializePlugin(MObject obj)
{
MStatus status;
Py_DECREF(module);
return status;
}