Public feed
#377887
void node_script_parse_cb(struct bNodeTree *ntree, struct bNode *node)
{
BPy_Node *pynode= NULL;
BPy_ShadeInput *myshi = NULL;
PyObject *outputdef= NULL;
PyObject *inputdef= NULL;
PyObject *key= NULL;
PyObject *value= NULL;
PyObject *testinst= NULL;
PyObject *args= NULL;
int pos = 0;
NodeScriptDict *nsd;
PyObject *pyresult = NULL;
Text *txt = 0;
char *buf;
if(! node->id) {
return;
}
if(node->custom1!=SH_NODE_SCRIPT_READY) {
txt = (Text *)node->id;
nsd = (NodeScriptDict *)node->storage;
buf = txt_to_buf( txt );
printf("nsd %p, nsd->dict %p, buf %p\n", nsd, nsd->dict, buf);
printf("Running script...");
pyresult = PyRun_String(buf, Py_file_input, (PyObject *)(nsd->dict), (PyObject *)(nsd->dict));
printf(" done\n");
MEM_freeN(buf);
if(!pyresult) {
if(PyErr_Occurred()) {
PyErr_Print();
}
Py_XDECREF(pyresult);
return;
}
Py_DECREF(pyresult);
/*PyObject_Del(pyresult);*/
myshi=(BPy_ShadeInput *)ShadeInput_CreatePyObject(NULL);
nsd->shi= myshi;
while(PyDict_Next( (PyObject *)(nsd->dict), &pos, &key, &value) ) {
if(PyObject_TypeCheck(value, &PyType_Type)) {
pynode = (BPy_Node *)Node_CreatePyObject(node);
outputdef= Node_CreateOutputDefMap(pynode);
inputdef= Node_CreateInputDefMap(pynode);
args= Py_BuildValue("(OO)", inputdef, outputdef);
testinst= PyObject_Call(value, args, NULL);
if(testinst && PyObject_TypeCheck(testinst, &Node_Type)==1) {
nsd->node= NULL;//testinst;// -*-*-*-*-*-*-*-* rcruiz was here ;)
node->typeinfo->execfunc= node_script_exec;
if(node->custom1== SH_NODE_SCRIPT_NEW) {
node->typeinfo->pynode= testinst;
node->typeinfo->id= node->id;
nodeRegisterType(ntree, node->typeinfo);
node->custom1= SH_NODE_SCRIPT_CREATED;
} else if(node->custom1== SH_NODE_SCRIPT_REPARSE) {
node->typeinfo->pynode= testinst;
node->typeinfo->id= node->id;
ntreeUpdateType(ntree, node->typeinfo);
node->custom1= SH_NODE_SCRIPT_UPDATED;
} else if(node->custom1== SH_NODE_SCRIPT_LOADED) {
node->typeinfo->pynode= testinst;
node->typeinfo->id= node->id;
nodeRegisterType(ntree, node->typeinfo);
node->custom1= SH_NODE_SCRIPT_READY;
} else if(node->custom1== SH_NODE_SCRIPT_ADDEXIST) {
node->custom1= SH_NODE_SCRIPT_READY;
}
break;
}
}
}
}
}