Paste Code
Paste Blends
Paste Images
# So lets go do some face selecting in Blender 3D using the python api.
# I will give a few very simple examples

# BE AWARE THAT FOR THESE EXAMPLES YOU MUST HAVE A MESH SELECTED AND IN OBJECT MODE!
# AND FOR TESTING USE ONE OF THE EXAMPLES AT A TIME.

# First import bpy to get access to well... everything in blender
import bpy

# Now we want to get the active object
# To do this we go through bpy.context... because that is basicly "what you are working on right now"
# bpy.data could work too, but then you'd need to do more work to find your current active object
ob = bpy.context.active_object



# SELECTING ALL FACES

# Lets loop through all the faces in the mesh
for f in ob.data.faces:

# Set select to true
f.select = True



# DESELECTING ALL FACES

# Lets loop through all the faces in the mesh
for f in ob.data.faces:

# Set select to false
f.select = False



# SELECTING EVERY OTHER FACE

# Lets loop through all the faces in the mesh
for i, f in enumerate(ob.data.faces):

# See if the current iteration/number i is odd or even
if i % 2:
# Set select to true
f.select = True
else:
f.select = False



# SELECTING FACES WITH THEIR CENTRE ABOVE 0.0 ON THE Z AXIS

# Lets loop through all the faces in the mesh
for f in ob.data.faces:

# See if the current face's centre is above 0.0 on the Z axis
if f.center[2] > 0.0:
# Set select to true
f.select = True
else:
f.select = False



# SELECTING FACES POINTING UP

# Import the math and mathtutils so we can work with vectors and such
import math, mathutils

# Make a vector (direction) pointing up
up = mathutils.Vector((0.0,0.0,1.0))

# Lets loop through all the faces in the mesh
for f in ob.data.faces:

# If the angle between up and the face's normal (direction) is smaller than 45...
# The face must be pointing up
# To compare the angle we need 45 degrees in radians, not in degrees!
# Math with angles is usually all in radians
if f.normal.angle(up) < math.radians(45):
# Set select to true
f.select = True
else:
f.select = False

  1. # So lets go do some face selecting in Blender 3D using the python api.
  2. # I will give a few very simple examples
  3.  
  4. # BE AWARE THAT FOR THESE EXAMPLES YOU MUST HAVE A MESH SELECTED AND IN OBJECT MODE!
  5. # AND FOR TESTING USE ONE OF THE EXAMPLES AT A TIME.
  6.  
  7. # First import bpy to get access to well... everything in blender
  8. import bpy
  9.  
  10. # Now we want to get the active object
  11. # To do this we go through bpy.context... because that is basicly "what you are working on right now"
  12. # bpy.data could work too, but then you'd need to do more work to find your current active object
  13. ob = bpy.context.active_object
  14.  
  15.  
  16.  
  17. # SELECTING ALL FACES
  18.  
  19. # Lets loop through all the faces in the mesh
  20. for f in ob.data.faces:
  21.        
  22.         # Set select to true
  23.         f.select = True
  24.        
  25.        
  26.        
  27. # DESELECTING ALL FACES
  28.  
  29. # Lets loop through all the faces in the mesh
  30. for f in ob.data.faces:
  31.        
  32.         # Set select to false
  33.         f.select = False
  34.        
  35.        
  36.        
  37. # SELECTING EVERY OTHER FACE
  38.  
  39. # Lets loop through all the faces in the mesh
  40. for i, f in enumerate(ob.data.faces):
  41.        
  42.         # See if the current iteration/number i is odd or even
  43.         if i % 2:
  44.                 # Set select to true
  45.                 f.select = True
  46.         else:
  47.                 f.select = False
  48.                
  49.                
  50.                
  51. # SELECTING FACES WITH THEIR CENTRE ABOVE 0.0 ON THE Z AXIS
  52.  
  53. # Lets loop through all the faces in the mesh
  54. for f in ob.data.faces:
  55.        
  56.         # See if the current face's centre is above 0.0 on the Z axis
  57.         if f.center[2] > 0.0:
  58.                 # Set select to true
  59.                 f.select = True
  60.         else:
  61.                 f.select = False
  62.                
  63.                
  64.                
  65. # SELECTING FACES POINTING UP
  66.  
  67. # Import the math and mathtutils so we can work with vectors and such
  68. import math, mathutils
  69.  
  70. # Make a vector (direction) pointing up
  71. up = mathutils.Vector((0.0,0.0,1.0))
  72.  
  73. # Lets loop through all the faces in the mesh
  74. for f in ob.data.faces:
  75.        
  76.         # If the angle between up and the face's normal (direction) is smaller than 45...
  77.         # The face must be pointing up
  78.         # To compare the angle we need 45 degrees in radians, not in degrees!
  79.         # Math with angles is usually all in radians
  80.         if f.normal.angle(up) < math.radians(45):
  81.                 # Set select to true
  82.                 f.select = True
  83.         else:
  84.                 f.select = False
  85.                
  86.                
go to heaven