Scanning mesh for two sided faces

Hi all,

I’m updating my script (written for 2.49b) to be compliant with 2.5x. I’m stuck with “twoside” toggle detection.

Here is a part of the code I used in 2.49:


if f.mode & Blender.Mesh.FaceModes['TWOSIDE']: 
    (this means we detected face with "twoside" on 
else: 
    (something else) 

f is face off course. The script was testing each and every face of the mesh and was checking if it has TWOSIDE flag on.

Can you give me an example of how I should do it in 2.5x API?

OK, I’ve finally figured out it by myself. :cool:

This could be interesting for some of you, so below I present a demo code which scans all the faces in the current mesh:


import bpy

# Let's use the current cube
mesh = bpy.data.meshes["Cube"]

# make sure we are in the object mode
bpy.ops.object.mode_set(mode='OBJECT')

for i, face in enumerate(mesh.faces):
    uf = mesh.uv_textures.active.data[i]
    img = uf.image
    print ("image = " + str(uf.image.name))
    two = uf.use_twoside
    print ("two_side = " +  str(two))

The key is to use uv_textures.active.data[i] and go through all the faces by incrementing variable i. There’s also one very important part - the script needs to go into object mode to perform this operation. That’s why I included the line which switches to object mode.