Using a StringVectorPtr


12-02-2006 23:11:54

How do I use StringVectorPtr in pyOgre? I specifically am trying to do this:

manager = ogre.ResourceGroupManager.getSingleton()
for mesh in manager.findResourceNames( "mygroup", "*.mesh" ):
manager.declareResource( mesh, "Mesh", "mygroup" )

But since findResourceNames() returns a StringVectorPtr, I can't iterate over it pythonically. So I tried:

manager = ogre.ResourceGroupManager.getSingleton()
meshes = manager.findResourceNames( "mygroup", "*.mesh" )
for i in range(len(meshes)):
manager.declareResource( meshes[i], "Mesh", "mygroup" )

But despite the pydocs saying otherwise, StringVectorPtrs don't have a __len__. Trying to add .get() for the StringVector itself causes a segfault.

So what's the proper way to do this? Or should I just stay away from trying to use these methods in python?


13-02-2006 01:42:57

You could try:

vp = ogre.StringVectorPtr(manager.findResourceNames( "mygroup", "*.mesh" ))

This thread might help you:


23-06-2006 23:29:45


vp = ogre.StringVectorPtr(manager.findResourceNames( "mygroup", "*.mesh" ))

Doesn't work either. Has anyone else had any luck with this?


24-06-2006 09:51:08

I used the .get() for the StringVector in the mesh viewer and cegui demos (method 3) and it seemed to work fine.

meshList = ogre.ResourceGroupManager.getSingleton().findResourceNames("General","*.mesh")

print "Iterator 1------------------"
# a closed iterator is safe in the following example.
# the next() method will throw a StopIteration
# exception as needed
i = meshList.get().iterator()
while True:
except: pass

print "Iterator 2------------------"
# an open iterator always need to be checked,
# or it will crash at the C++ side

i = meshList.get()
current = i.begin()
end = i.end()
while (current != end):

print "Iterator 3------------------"
i = meshList.get()
meshes = [ i.__getitem__(j) for j in range(i.size()) ]
for j in meshes:
print j


26-06-2006 23:50:59

Thanks dermont, worked great!