# Index Error: bpy_prop_collection[index]: index 0 out of range, size 0

So, here's the code i'm trying to implement:

import bpy

ob = bpy.data.objects

#create an output file
import os
file = open(os.path.splitext(bpy.data.filepath)[0] + ".txt", 'w')

for objects in ob:
#get vertices, normals, and texCoords
if(ob[objects.name].type == 'MESH'):
for face in ob[objects.name].data.polygons:
for vert, loop in zip(face.vertices, face.loop_indices):
coord = ob[objects.name].data.vertices[vert].co
normal = ob[objects.name].data.vertices[vert].normal
layers = ob[objects.name].data.uv_layers
for MeshUVLoopLayer in layers:
#the problem is here
uv = ob[objects.name].data.uv_layers[MeshUVLoopLayer.name].data[loop].uv
file.write("v {co.x} {co.y} {co.z}\nvn {n.x} {n.y} {n.z}\nvt {uv.x} {uv.y}\n".format(co=coord, n=normal, uv=uv))


this was working when i wasn't doing the for loop and it was '...uv_layers.active', but when i replaced it with what it is now i get this error.

i know the bpy_prop_collection isn't empty it should have two items in it and i checked it with the console using bpy.data.objects["Suzanne"].data.uv_layers.items() and it came out with UVMap and UVMap.001. Suzanne is the only object in the scene, plus it checks the objects first if they're meshes.

Any ideas, on what's causing the error? Or what i'm obviously doing wrong, but am completely oblivious to?

• Your code works fine for me. It creates a text file containing all vertices, normals and texure coordinates, even when I have mutliple objects and non-mesh objects in the scene. Jan 24, 2015 at 10:14
• why won't it work for me, then? :( that's exactly what it's supposed to do but i get an error. Jan 24, 2015 at 10:16
• I don't know, maybe you could upload your .blend file so we can check it. A good place to upload your blends is pasteall.org/blend Jan 24, 2015 at 10:17
• not really sure how to use that site, but i think this is the link: monkey.blen Jan 24, 2015 at 10:19
• Yep, that's the correct link. Again, your script works fine for me, so I can not reporduce the error. I only had to comment out the last two lines where you were checking for an armature. This may sound like a noob suggestion, but have you tried to just reopen Blender or restart your PC? Jan 24, 2015 at 10:23