[Bf-python] Bringing objects into a scripts namespace

Nathan Letwory jesterking at letwory.net
Sun Feb 19 17:51:50 CET 2006


Hi,

I'm currently working on some code that requires me to give a script an
PyObject, which I have to create in C before calling evaluation of the
script. I have some code, but it does not work at all. This is a rather
new area for me, so here I am calling upon your help :)

Snippets - the C side:

static void init_scriptdict( )
{

	scriptdict = PyDict_New(  );
	PyDict_SetItemString( scriptdict, "__builtins__", PyEval_GetBuiltins(  ) );
	PyDict_SetItemString( scriptdict, "__name__", PyString_FromString(
"__main__" ) );
	Py_XINCREF ( scriptdict );

}

------------

Text txt = (Text *)node->id;
if(!scriptdict) init_scriptdict(scriptdict);
BPy_Node *pynode = (BPy_Node *)Node_CreatePyObject(node);
pynode->type = 1;
Py_XINCREF(pynode);

PyDict_SetItemString(scriptdict, "currentnode", (PyObject *)pynode);

pyresult = RunPython(txt, scriptdict);

-------------

The idea is that when the script in txt is run currentnode is available
for operations:

The python side:

##start
indict = {}
outdict = {}
try:
    currentnode.refreshPyNod(INPUT=indict, OUTPUT=outdict)
pass:
    print "currentnode not available :("
    pass
##end

The questions: Why is 'currentnode' not accessible? How to fix this?

Thanks in advance,

/Nathan




More information about the Bf-python mailing list