Re: Registering a python function in C



On Aug 31, 3:33 pm, fernando <fernandofariajun...@xxxxxxxxx> wrote:
Thanks for the responses. To be more specific, this code is part of a
Maya plugin. The funcion MFnPlugin::registerUI takes a pointer to a
PyObject which is the function that will set up the UI for that
plugin. The code Matimus posted seems to me exactly like what I need
to do, except that maya gives me an error when I call
PyImport_ImportModule... I don't even have a chance to check the
return value, Maya simply gives up. I have checked that python is
initialized by the time I call this function, and the python path is
correct, I can load the module from the maya python interpreter. What
bugs me is that PyImport_ImportModule doesn't even return, it should
return 0 if something bad happened, right?

Here's my code:

if(Py_IsInitialized())
cout << "python is already initialized" << endl;
if(!Py_IsInitialized()){
cout << "had do initialize python" << endl;
Py_Initialize();}

PyObject* mod= PyImport_ImportModule("vzPyTest");
if(mod == 0){
cout << "didn't load" << endl;}

PyObject* func1 = PyObject_GetAttrString(mod, "vzPyTest.test1");
PyObject* func2 = PyObject_GetAttrString(mod, "vzPyTest.test2");
plugin.registerUI(func1, func2);

Thanks for the help!!!
One thing I've learned is that the C interface can be tricky the first
time.

Is Maya a different python build than what is contained at python.org?
If so, I suggest you get your C program to work with the latest python
build
from python.org. Then see if you can get it to work with the Maya
version.

.



Relevant Pages

  • Python Interactive Interpreter Breakage
    ... I am trying to write a Python module to embed the functionality of ... Maya (the 3D modelling and animation application from Autodesk, ... processes in Python. ... An input script for this would be something like: ...
    (comp.lang.python)
  • ANN: Python cgkit v2.0.0alpha7 & Maya/Python 0.9.3
    ... The Python Computer Graphics Kit is an Open Source software package ... into Maya, and the accompanying Python package "maya" that makes Maya ... functionality available in Python. ...
    (comp.graphics.rendering.renderman)
  • ANN: Python cgkit v2.0.0alpha7 & Maya/Python 0.9.3
    ... The Python Computer Graphics Kit is an Open Source software package ... into Maya, and the accompanying Python package "maya" that makes Maya ... The newly wrapped classes mainly consist of the ...
    (comp.lang.python.announce)
  • frequency analysis without numpy
    ... I've been using python now for about 2 months for plugin development ... within Maya. ... I'm reluctant to use an external python module for FFT'ing. ... def nextpow2: ...
    (comp.lang.python)
  • ANN: Python cgkit v2.0.0alpha6 & Maya Python package
    ... The sixth alpha release of version 2 of the Python Computer Graphics ... This release also comes with a "preview" version of a Maya Python ... package that integrates Python into Maya. ... used to display the scene either interactively or by rendering it ...
    (comp.graphics.rendering.renderman)