I’m trying to write a custom file exporter, and I’ve run into a bit of a snag when trying to export the UV information. Here is the relevant code snippet:
for tface in self.mesh.tessface_uv_textures['UVMap'].data: uvs = tface.uv_raw; file.write(struct.pack('<%sf' % len(uvs), *uvs);
self.mesh is a mesh I got from the active context. I was successfully able to export the vertices, so I know that part isn’t the problem.
When I try to run the script, blender tells me there is an error on the second line in the snippet:
Traceback (most recent call last):
File “C:\Program Files\Blender Foundation\Blender\2.65\scripts\addons\io_mesh_mbin\exporter.py”, line 97, in execu
# Write the file data
File “C:\Program Files\Blender Foundation\Blender\2.65\scripts\addons\io_mesh_mbin\exporter.py”, line 33, in write
for uv in tface.uv:
TypeError: ‘MeshTextureFace’ object is not iterable
Line 33 is in the snippet above, and line 97 starts here:
# Write the file data fileHeader.write(file); fileBody.write(file);
I’ll admit, I’m new to Python. However, I’m pretty sure that I’m not iterating over MeshTextureFace but am instead iterating over the uv_raw array in that object. I’ve put that code snippet into Blender’s python console (changing “self.mesh” to bpy.data.mesh.whatever and “file.write” to “print”), and it worked as expected.
I have no idea what the problem is. If anyone could help me out I’d really appreciate it and sorry if this isn’t enough info.
I’m using Blender 2.65.0