Using a StringVectorPtr

gehn

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?

viblo2

13-02-2006 01:42:57

You could try:

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

This thread might help you: http://www.ogre3d.org/phpBB2addons/viewtopic.php?t=192

mthorn

23-06-2006 23:29:45

Using

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


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

dermont

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()
try:
while True:
print i.next()
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 current.next()


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

mthorn

26-06-2006 23:50:59

Thanks dermont, worked great!