|
#1
|
|||
|
|||
Dear Farshizzo,
Looking at the code more (and the C++ implementation of viz:ata), is it true that it is possible to pass an arbitrary number of arguments (with arbitrary names and somewhat arbitrary datatypes) through the Python interface to the C++ extension code? That's great! But how would one go about that at the Python side? Hmm, looking at the code in viz.VizExtensionNode and viz.VizExtension maybe its not possible yet). Anyway, that would be very cool! I do see I am able to pass back to Python arbitrary data structures (because lists and such are supported! and with some hacking any other Python datatype i see) Another question is how to set error conditions in the C++ code and communicate them to the Python code? In the old code, one could say ((VizCustomNodeObj*)custom)->status = 0; in some functions (but not CommandCustomNode sadly) which would cause Vizard to communicate an error ocurred. Is it possible through the interface defined in pyerrors.h? If something is possible, could you add an example? Lastly, I'm happy to see the void MyExtension::update(const viz::Event &e) function, that seems useful! Some questions though: 1) From inside this function, is it possible to retrieve pointers to the Nodes/Sensors/Textures attached to the extension to perform operations on them and/or pass data along? 2) I see that the viz::Event object has function for getting the X, Y and Z input arguments, amongst others. How are these set? 3) related to that, is it possible to override the update call from Python? I'd like to define my own function to run every frame (I now do that using vizact.ontimer(0,self.stim.update), where self.stim.update is a function i defined) where it does some processing and then passes some data along to the plugin. If you answer to 1) is no, I guess I'll keep doing what I'm doing now? Thank you for the answers! Best, Dee |
#2
|
|||
|
|||
Dear Farshizzo,
I did run into some trouble. My C++ also uses boost, and I get a whole bunch of redefinition warnings for boost::any. My version of boost (as does the current trunk version) apparently defines #define BOOST_ANY_INCLUDED instead of #define BOOST_ANY_HPP, leading to this situation. Could you also add the other define to your custom header or is there a more appropriate way for me or you to deal with this? Best, Dee |
#3
|
|||
|
|||
Thanks, we'll modify the included header so it doesn't conflict with boost.
|
#4
|
|||||
|
|||||
Quote:
Quote:
Quote:
Code:
std::list< viz::ref_ptr< MySensor > > m_sensors; Quote:
Quote:
Code:
PYTHON_BEGIN_RUN_CODE PyObject *pyExt = Python_GetExtensionObject(GetID()); if(pyExt) { PyObject *pyReturn = PyObject_CallMethod(pyExt,"myupdate"); PYTHON_FLUSHERROR; Py_XDECREF(pyReturn); Py_DECREF(pyExt); } PYTHON_END_RUN_CODE |
#5
|
|||
|
|||
Hi Farshizzo,
Thank you for all the detailed information! I still have some questions though: Quote:
Code:
std::list< osg::ref_ptr< MySensor > > m_sensors; Quote:
Code:
Traceback (most recent call last): File "<string>", line 11, in <module> File "C:\dat\C\projects\Vizard dll\testCustomNode.py", line 58, in <module> stim.setStimSpec('GDcl') File "DNstimuli.py", line 45, in setStimSpec self.command(1,stimSpec) File "C:\Program Files\WorldViz\Vizard4\python\viz.py", line 6837, in command return _ipcSend(_VIZ_CMDEXTNODE,self.id,command,mesg,x,y,z,w) TypeError: command must be an int If setup a debug breakpoint on this first call after the raised exception (self.command(1,stimSpec)), and try to step into it, i get this output: Code:
C:\Program Files\WorldViz\Vizard4\python\vizbdb.py:410: RuntimeWarning: tp_compare didn't return -1 or -2 for exception if id in ids: Traceback (most recent call last): File "<string>", line 11, in <module> File "C:\dat\C\projects\Vizard dll\testCustomNode.py", line 58, in <module> stim.setStimSpec('GDcl') File "DNstimuli.py", line 45, in setStimSpec self.command(1,stimSpec) File "DNstimuli.py", line 45, in setStimSpec self.command(1,stimSpec) File "C:\Program Files\WorldViz\Vizard4\python\vizbdb.py", line 254, in trace_debug self.wait_for_input(frame,None) File "C:\Program Files\WorldViz\Vizard4\python\vizbdb.py", line 436, in wait_for_input id,data = self.wait_for_message(_INPUT_MESSAGES) File "C:\Program Files\WorldViz\Vizard4\python\vizbdb.py", line 410, in wait_for_message if id in ids: RuntimeError: testing Other things I tried: - doing data.set( PYTHON_RETURN_OBJECT, PYTHON_INT(-1)); or data.set(PYTHON_RETURN_OBJECT, NULL); after the call to PyErr_SetString did not help (inspired by some reading of how error states should be communicated from Python). - try/except around the call where the exception is raised. This didn't do anything, as expected when the exception goes unnoticed. What am I missing? Thanks for your help! |
#6
|
|||
|
|||
Quote:
Quote:
|
#7
|
|||
|
|||
Quote:
When try to send an exception from my python plugin as follows Code:
PyErr_SetString(PyExc_RuntimeError, "errorstring"); data.set( PYTHON_RETURN_OBJECT, NULL); I always get a TypeError instead of the exception i'm trying to communicate. The stacktrace always ends like this: Code:
File "C:\Program Files (x86)\WorldViz\Vizard4\python\viz.py", line 7381, in command return _ipcSend(_VIZ_CMDEXTNODE,self.id,command,mesg,x,y,z,w) TypeError: command must be an int I'm not sure what this typeerror is referring to, as my command is correct, it works without error when not trying to return an exception. Am I doing something wrong? Best and thanks, Dee |
#8
|
|||
|
|||
Can you post the full traceback? It looks like you are using passing an invalid parameter to the command method. As the traceback says, the first argument must be an int, and you are most likely passing some other type.
|
|
|