Thread: Sdk
View Single Post
Old 05-23-2011, 09:44 AM
farshizzo farshizzo is offline
WorldViz Team Member
Join Date: Mar 2003
Posts: 2,849
Originally Posted by dcnieho View Post
Looking at the code more (and the C++ implementation of viz::Data), 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)
That was the idea with the viz::Data structure. Currently you are limited to passing the fixed arguments through the Python interface though. Eventually we would like to expose the ability to pass more complex data types through Python.

Originally Posted by dcnieho View Post
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?
The new interface allows you to return arbitrary Python objects from the command method, so you can return anything you wish to signal an error. If you want to raise a Python exception from your plugin, then you can use the Python PyErr_SetString function to raise an exception.

Originally Posted by dcnieho View Post
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?
No, but you can internally save a reference to them. This is what most of the built-in plugins do. For example, the extension class can keep a list of sensor objects created by it:
std::list< viz::ref_ptr< MySensor > > m_sensors;
Originally Posted by dcnieho View Post
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?
The viz::Event object passed to the plugins only provides the frame information described in the docs. The X, Y, Z arguments are not used for update events.

Originally Posted by dcnieho View Post
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?
If you want Python code to run every frame, then you can use the existing Python methods of registering an update function. You can also call methods of the extensions Python interface from within the C++ code. For example, if you added a method called myupdate to the extension Python interface, then the following code could be used to call it:
  PyObject *pyExt = Python_GetExtensionObject(GetID());
  if(pyExt) {
    PyObject *pyReturn = PyObject_CallMethod(pyExt,"myupdate");
Reply With Quote