Thanks Dolf, Your code worked.
I have to think more and more. But now We have short holidays in Japan, (We called 'Golden Week' but as you know 'Husbands' has no free time in Holidays!) So, I'll get some time to think code next week. (T_T)
<CODE>
#Let's make a completely new script where we create a series of vertex groups, that we assign faces to.
#So the idea is... for every "extrusion" we want to do... we create a vertex group.
# Just like before we loop through all the faces
import bpy
ob = bpy.context.active_object
# A new trick... lets go into edit mode and deselect everything ('SELECT' works too)
bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.mesh.select_all(action='DESELECT')
# Go into object mode so that we are sure we have the current list of faces
bpy.ops.object.mode_set(mode='OBJECT')
# Make a nice list to keep the vertex groups in
groupList = []
# Now loop through all the faces
for i, f in enumerate(ob.data.faces):
# The following is the same as i % 5 == 0, but faster.
if not i % 5:
# Create a new vertex group!
newGroup = ob.vertex_groups.new('mygroup')
groupList.append(newGroup)
# Get all the vertices in the current face and add them to the new group
for v in f.vertices:
newGroup.add([v], 1.0, 'REPLACE')
# Now we loop through the groups and do what we want.
for g in groupList:
# Make sure nothing is selected
bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.mesh.select_all(action='DESELECT')
# Make the group in our list the active one
ob.vertex_groups.active_index = g.index
# Select all the verts in the active group
bpy.ops.object.vertex_group_select()
# AND NOW WE CAN DO OUR STUFF... little test example follows
# Lets extrude/shrink/scale 5 times (hacky non commented code)
for i in range(5):
bpy.ops.mesh.extrude(type='REGION')
# An added trick... remove the extruded face from all vertex groups after the first extrusion (i == 0)
# This way it can't get extruded again
# Because the edge of the first face can be part of multiple groups
if not i:
bpy.ops.object.vertex_group_remove_from(all=True)
bpy.ops.object.mode_set(mode='OBJECT')
bpy.ops.object.mode_set(mode='EDIT')
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)
bpy.ops.transform.resize(value=(0.8, 0.8, 0.8), constraint_axis=(False, False, False), constraint_orientation='GLOBAL', mirror=False, proportional='DISABLED', proportional_edit_falloff='SMOOTH', proportional_size=0.0762767, snap=False, snap_target='CLOSEST', snap_point=(0, 0, 0), snap_align=False, snap_normal=(0, 0, 0), texture_space=False, release_confirm=False)
</CODE>
No comments:
Post a Comment