H3D.org Forum Index Programming Issues
Routing from C++ to Python Fields | Register To Post |
| Threaded | Newest First | Previous Topic | Next Topic | Bottom |
| Poster | Thread |
|---|---|
| GBaitson | Posted on: 2010/1/26 18:46 |
Quite a regular ![]() ![]() Joined: 2009/5/19 From: National Digital Research Centre Posts: 25 |
Routing from C++ to Python Fields Hi all,
Would someone be able to help with a small problem please. I am working on trying to route fields from C++ to Python. I can get it to work using X3D (as below) But when trying to do this is C++ (as below), the build crashes and won't run It could have something got to do with the "getField" method of the PythonScript. We've noticed that the getField method returns a Field pointer, whereas Route requires an AutoPointer. Do we have to use a method that returns an auto pointer or do we have to cast the return type of another method as an auto pointer? If so, what method/function would return a PythonScript field that we can route to? Also, is there a way to see if the PythonScript is actually being loaded and that the variables/fields are accessible within the C++ file> Any comments would be greatly appreciated |
| karlu | Posted on: 2010/1/27 8:02 |
Guru ![]() ![]() Joined: 2004/12/2 From: Sweden Posts: 585 |
Re: Routing from C++ to Python Fields Could it be that the Python script has never actually executed when you try to find its fields and therefore is not fully initialized? Try calling initialize and maybe also traverseSG.
|
| Markus | Posted on: 2010/1/27 8:17 |
Webmaster ![]() ![]() Joined: 2006/3/27 From: SenseGraphics Posts: 1531 |
Re: Routing from C++ to Python Fields Use:
ps->url->setValue( "Python.py" ); setURLBase will not do what you think it does. |
| GBaitson | Posted on: 2010/1/27 12:34 |
Quite a regular ![]() ![]() Joined: 2009/5/19 From: National Digital Research Centre Posts: 25 |
Re: Routing from C++ to Python Fields Thanks for your replies,
Eventually got it working, it was a mixture of both of your comments. In using H3D2.1, the 'setValue' method was looking for a vector of MFStrings. Upon creating a vector of MFString it was complaining that it wouldn't allow the conversion from const std::vector<_Ty> to const std::vector<_Ty> &, which I couldn't figure out exactly how to fix this. So, I came across the method 'setValueFromString' which allowed the string path of the python file to be specified. Once this is specified, we then initialize the PythonScript. So below is the piece of code that works |
| Markus | Posted on: 2010/2/3 8:17 |
Webmaster ![]() ![]() Joined: 2006/3/27 From: SenseGraphics Posts: 1531 |
Re: Routing from C++ to Python Fields Just to make a small correction, setValue does does not require a vector of MFStrings, but a vector of std:string.
So my code was incorrect, it should have been: Where did you read that it required a vector of MFStrings? |
| Threaded | Newest First | Previous Topic | Next Topic | Top |
| Register To Post | |





