<CODE>
# 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
# MAKE SURE WE ARE IN OBJECT MODE FOR SELECTING
bpy.ops.object.mode_set(mode='OBJECT')
# 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
# MAKE SURE WE ARE IN EDIT MODE FOR EXTRUDE AND TRANSLATE
bpy.ops.object.mode_set(mode='EDIT')
# Extrude the selection (do not move it)
bpy.ops.mesh.extrude(type='FACES')
# Move the selection (always relative to the normal)
# bpy.ops.transform.translate(0.1)
bpy.ops.transform.shrink_fatten(value=-0.1, mirror=False, proportional='DISABLED', proportional_edit_falloff='SMOOTH', proportional_size=1, snap=False, snap_target='CLOSEST', snap_point=(0, 0, 0), snap_align=False, snap_normal=(0, 0, 0), release_confirm=False)
</CODE>
And, I got this result.
Add subSurf modifier.
Next, I'd like to resize each selected, extruded faces on Pivot='Individual Origins'. But now, I couldn't find the option in
<CODE>
bpy.ops.transform.resize(value=(0.5, 0.5, 0.5), constraint_axis=(False, False, False), constraint_orientation='GLOBAL', mirror=False, proportional=bpy.context.tool_settings.proportional_edit, proportional_edit_falloff=bpy.context.tool_settings.proportional_edit_falloff, proportional_size=1, snap=bpy.context.tool_settings.use_snap, snap_target=bpy.context.tool_settings.snap_target, snap_point=(0, 0, 0), snap_align=False, snap_normal=(0, 0, 0), release_confirm=False)
</CODE>
hmmm, what is the answer?
No comments:
Post a Comment