On Mar 12, 2012, at 9:06 PM, Vik wrote: > How I can work with Element of Scene in Python?
Python support in 2.x series has been lacking after the aggressive cleanups made (2.0 was largely a cleanup), but we've been slowly improving it as needed (we need it for the websocket server module, and the Blender integration thing needs it too). Currently there is no new clean all-saving solution to the boost Ptr problem, but we've just worked around by adding some *Raw getters back -- but only in a branch, and only in PythonScriptModule, to keep the core clean. That is in the websocket branch: https://github.com/realXtend/naali/tree/websocket That branch basically only has py support additions and the Python written websocket server itself, so is safe to pull to your version. Is easy with git, do ask if you need help with that. Supposing you are building your own Tundra. If not, I guess I'll have to fix these for you for next release :p > I can call for example > el=tundra.Scene().MainCameraScene().GetEntityByName(entityName) > But I can't use obtained element el at all - no attributes. The websocket branch has a commit that gives you exactly that: "restore scene.GetEntityByNameRaw for py, as there is no EntityPtr handling (yet). this sufficed for websocket server to work now" https://github.com/realXtend/naali/commit/35a2a688062043c17aaf8be34444b1f666b619a7 It is 2 lines of trivial code, so I hope you see how easy it is to add other similar things where you need them, for now: QObject *TundraInstanceDecorator::GetEntityByNameRaw(Scene *scene, const QString &name) { return scene->GetEntityByName(name).get(); } With that technique the *Raw workaround thing is in the optional Python support module only, so we can even put them upstream to have in reX releases etc. if it's really needed. But idea has been to make a generic solution for all Ptrs: > I understand that el is EntityPtr, not Entity as for example method > GetEntityRaw(id) return. > How i can convert EntityPtr to Entity in Python? > And method GetEntityByNameRaw() is obsolete now? If automatic conversion of Boost-Ptr to normal pointer is not possible in the Python API (no one has afaik tried it yet), we can perhaps expose the boost get() method to py so that you would do: entityptr = scene.GetEntityByName("myent") entity = entityptr.get() This would be a bit annoying but ok (given we can do the pointer handling correctly). If that is somehow not possible perhaps a function ptrGet(somePtr) is possible. If you have some c++ skills, feel free to try - patches are welcome. If not, please tell, so I or someone else here (Erno?) can try those. We have been a little unsure of the need of Python support otherwise, so it is very interesting to hear that you are using it. There are some cases where it is more suitable than e.g. Javascript, I think mostly related to system integration things or anything where you need to use existing py libs. Also others just prefer it as the language is nicer. Would be nice to hear something about your use case if possible, but you don't have to tell of course. > And example of plugin "apitests.py" does not work: > PythonScript: **** Python ApiRunner.testScene() failed **** > PythonScript: SceneAPI has no attribute named 'GetDefaultSceneRaw' Yep that one is just not ported to 2.x, works in 1.x. ~Toni -- http://groups.google.com/group/realxtend http://www.realxtend.org
