Paste Code
Paste Blends
Paste Images
# First import bpy to get access to well... everything in blender
from bpy import *
import bpy
import math, mathutils, random

class generativeModelingPJ(bpy.types.Panel):
bl_label = 'Generative Modeling Project'
bl_space_type = 'VIEW_3D'
bl_region_type = "TOOLS"

def draw(self, context):
layout = self.layout

row = layout.row()
row.label("----------------------------------------------------------")

row = layout.row()
row.prop(scn, "ABC")

row = layout.row()
row.prop(scn, "DEF")

row = layout.row()
row.label("----------------------------------------------------------")


# Set Up Parameters --------------------------------------->
bMainLevel = 3
bStepAngle = 30
bModLevel = 3.0
bModRate = 10.0

pMainLevel = 0.3
pStepAngle = 1.0
pModLevel = 1.0
pModRate = 5.0

sRot = 0
sAngle = 0
# Set Up Parameter(END) -----------------------------------<

# Extrude One Step ---------------------------------------->
def transStep(dA, sA, rA, axis_x, axis_y, axis_z):
bpy.ops.transform.shrink_fatten(value=dA, 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=(sA, sA, sA), 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)

# Get the mesh
me = ob.data
# Loop through the faces to find the center
for f in me.faces:
if f.select == True:
center = f.center
if center[0] > 0.0:
rotDir = 1.0
else:
rotDir = -1.0

bpy.ops.transform.rotate(value=(rA*rotDir,), axis=(axis_x, axis_y, axis_z), 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), release_confirm=False)

# TransformFaces(Multi Step) ------------------------------------------------------->
def transformFaces(vGroup, mainLevel, stepNum, stepDist, stepRot, startAngle, stepAngle, modLevel, modRate, axis):
# Make sure nothing is selected
bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.mesh.select_all(action='DESELECT')

# Select the vertex group
selPart(vGroup)

# 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):

# If this face is selected~
if ob.data.faces[i].select == True:

# 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()

bpy.ops.object.vertex_group_remove(all=False)

# AND NOW WE CAN DO OUR STUFF... little test example follows
t = startAngle
oldRatio = 1.0
# Shape
for i in range(stepNum):

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')

newRatio = mainLevel*(math.sin(math.radians(t)+modLevel*math.sin(math.radians(t+modRate)))+2.0)/oldRatio
dA = stepDist
sA = newRatio
rA = math.sin(math.radians(t*2))*stepRot
axis_x = axis[0]
axis_y = axis[1]
axis_z = axis[2]
transStep(dA, sA, rA, axis_x, axis_y, axis_z)
t = t + stepAngle
oldRatio = oldRatio*newRatio

# transformFaces!(END) --------------------------------------------------<

# bodyShape ------------------------------------------------------>
def bodyShape(vGroup, mainLevel, stepNum, stepDist, stepRot, startAngle, stepAngle, modLevel, modRate, axis):
newGroup = ob.vertex_groups.new(vGroup)
bpy.ops.object.mode_set(mode='OBJECT')

# 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[1] > -0.1:
# Set select to true
f.select = True
else:
f.select = False

bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.object.vertex_group_set_active(group=vGroup)
bpy.ops.object.vertex_group_assign(new=False)

transformFaces(vGroup, mainLevel, stepNum, stepDist, stepRot, startAngle, stepAngle, modLevel, modRate, axis)
bpy.ops.mesh.select_all(action='DESELECT')
# bodyShape(END) ---------------------------------------------------<

# select faces from Groups --------------------------------------------->
def selPart(vGroup):
bpy.ops.object.vertex_group_set_active(group=vGroup)
bpy.ops.object.vertex_group_select()
bpy.ops.object.vertex_group_remove(all=False)
# select faces from Groups (END)----------------------------------------<

# cell subdivide --------------------------------------------->
def cellSubdiv():
bpy.ops.object.modifier_add(type='SUBSURF')
bpy.ops.object.mode_set(mode='OBJECT')
bpy.ops.object.modifier_apply(apply_as='DATA', modifier="Subsurf")
# cell subdivide (END)----------------------------------------<

# assignFaces ----------------------------------------------->
def assignFaces(vGroup, xMin, xMax, yMin, yMax, zMin, zMax):
newGroup = ob.vertex_groups.new(vGroup)
bpy.ops.object.mode_set(mode='OBJECT')

for f in ob.data.faces:

if f.center[0] > xMin and f.center[0] < xMax and f.center[1] > yMin and f.center[1] < yMax and f.center[2] > zMin and f.center[2] < zMax:
f.select = True
else:
f.select = False

bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.object.vertex_group_set_active(group=vGroup)
bpy.ops.object.vertex_group_assign(new=False)
bpy.ops.mesh.select_all(action='DESELECT')
# assignFaces (END)------------------------------------------<

# assignFacesAngle--------------------------------------------->
def assignFacesAngle(vGroup, fAngleMin, fAngleMax, yMin, yMax):
newGroup = ob.vertex_groups.new(vGroup)
bpy.ops.object.mode_set(mode='OBJECT')

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(fAngleMin) and f.normal.angle(up) < math.radians(fAngleMax) and f.center[1] > yMin and f.center[1] < yMax :
# Set select to true
f.select = True
else:
f.select = False

bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.object.vertex_group_set_active(group=vGroup)
bpy.ops.object.vertex_group_assign(new=False)
bpy.ops.mesh.select_all(action='DESELECT')
# assignFacesAngle(END)--------------------------------------<

# Generate Object ----------------------------------------->
# -- Set Up(START) ------------------------------------------>
bpy.ops.mesh.primitive_plane_add(view_align=False, enter_editmode=False, location=(0, 0, 0), rotation=(0, 0, 0), layers=(True, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False))
bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.transform.rotate(value=(-1.5708,), axis=(-1, -2.22045e-16, -4.93038e-32), constraint_axis=(False, False, False), constraint_orientation='LOCAL', 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.05, 1, 0.05), 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)
bpy.ops.object.mode_set(mode='OBJECT')

# 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

# 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')

# Get the screen areas we are working in right now
areas = bpy.context.screen.areas

# Loop through all the areas
for area in areas:

# See if the current area is a 3D view
if area.type == 'VIEW_3D':

# Set the pivot point to individual origins
area.active_space.pivot_point = 'INDIVIDUAL_ORIGINS'

# -- Set Up(END) ------------------------------------------<


# bodyShape(vGroup, mainLevel, stepNum, stepDist, stepRot, startAngle, stepAngle, modLevel, modRate, axisArray)
bodyShape('body', bMainLevel, 12, -0.5, sRot/10, sAngle, bStepAngle, bModLevel, bModRate, [-1, -2.22045e-16, -0])
bpy.ops.object.mode_set(mode='OBJECT')

cellSubdiv()
# spine
#transformFaces(vGroup, mainLevel, stepNum, stepDist, stepRot, startAngle, stepAngle, modLevel, modRate, axis)
#assignFaces('spine', -5.0, 5.0, 2.5, 20.0, 0.0, 10.0)
#transformFaces('spine', 0.3, 10, -0.2, -0.5, sAngle, 10, 5, 20, [-2.22045e-16, -1, -0])
assignFacesAngle('arm', 0, 45, 2.5, 20.0)
assignFacesAngle('horn', 0, 45, 0.5, 1.5)
assignFacesAngle('leg', 135, 180, 2.0, 4.0)

transformFaces('arm', pMainLevel, 10, -0.2, sRot/10, sAngle, pStepAngle*6, pModLevel*5, pModRate*4, [-2.22045e-16, -1, -0])
transformFaces('horn', pMainLevel, 4, -0.1, sRot/10, sAngle, pStepAngle*8, pModLevel*5, pModRate*4, [-2.22045e-16, -1, -0])
transformFaces('leg', pMainLevel, 10, -0.2, sRot/10, sAngle, -pStepAngle*5, pModLevel*2, pModRate*2, [-2.22045e-16, -1, -0])

bpy.ops.object.modifier_add(type='SUBSURF')
bpy.ops.object.modifier_add(type='SUBSURF')
bpy.ops.object.mode_set(mode='OBJECT')

#fileName = '/Users/shige/Documents/BlenderPJ/GMP_model3/A_Life_'+str(sRot)+'_'+str(sAngle)
#fileName = '/Users/shige/Documents/BlenderPJ/GMP_model/A_Life_sRot_-10_10_2_sAngle_0_180_15)'

# Save the current file! (with a specific fileName)
# bpy.ops.wm.save_as_mainfile(filepath=fileName, check_existing=False, compress=True)

#bpy.ops.object.delete()
  1. # First import bpy to get access to well... everything in blender
  2. from bpy import *
  3. import bpy
  4. import math, mathutils, random
  5.  
  6. class generativeModelingPJ(bpy.types.Panel):
  7.         bl_label = 'Generative Modeling Project'
  8.         bl_space_type = 'VIEW_3D'
  9.         bl_region_type = "TOOLS"
  10.        
  11.         def draw(self, context):
  12.                 layout = self.layout
  13.                
  14.                 row = layout.row()
  15.                 row.label("----------------------------------------------------------")
  16.                
  17.                 row = layout.row()
  18.                 row.prop(scn, "ABC")
  19.                
  20.                 row = layout.row()
  21.                 row.prop(scn, "DEF")
  22.                
  23.                 row = layout.row()
  24.                 row.label("----------------------------------------------------------")
  25.                
  26.  
  27. # Set Up Parameters     --------------------------------------->
  28. bMainLevel = 3
  29. bStepAngle = 30
  30. bModLevel = 3.0
  31. bModRate =      10.0
  32.  
  33. pMainLevel = 0.3
  34. pStepAngle = 1.0
  35. pModLevel = 1.0
  36. pModRate = 5.0
  37.  
  38. sRot = 0
  39. sAngle = 0
  40. # Set Up Parameter(END) -----------------------------------<
  41.        
  42. # Extrude One Step ---------------------------------------->
  43. def transStep(dA, sA, rA, axis_x, axis_y, axis_z):
  44.         bpy.ops.transform.shrink_fatten(value=dA, 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)
  45.         bpy.ops.transform.resize(value=(sA, sA, sA), 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)
  46.        
  47.         # Get the mesh
  48.         me = ob.data
  49.         # Loop through the faces to find the center
  50.         for f in me.faces:
  51.                 if f.select == True:
  52.                         center = f.center
  53.         if center[0] > 0.0:
  54.                 rotDir = 1.0
  55.         else:
  56.                 rotDir = -1.0
  57.        
  58.         bpy.ops.transform.rotate(value=(rA*rotDir,), axis=(axis_x, axis_y, axis_z), 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), release_confirm=False)
  59.        
  60. # TransformFaces(Multi Step) ------------------------------------------------------->
  61. def transformFaces(vGroup, mainLevel, stepNum, stepDist, stepRot, startAngle, stepAngle, modLevel, modRate, axis):
  62.         # Make sure nothing is selected
  63.         bpy.ops.object.mode_set(mode='EDIT')
  64.         bpy.ops.mesh.select_all(action='DESELECT')
  65.        
  66.         # Select the vertex group
  67.         selPart(vGroup)
  68.        
  69.         # Go into object mode so that we are sure we have the current list of faces
  70.         bpy.ops.object.mode_set(mode='OBJECT')
  71.  
  72.         # Make a nice list to keep the vertex groups in
  73.         groupList = []
  74.  
  75.         # Now loop through all the faces
  76.         for i, f in enumerate(ob.data.faces):
  77.                
  78.                 # If this face is selected~
  79.                 if ob.data.faces[i].select == True:
  80.  
  81.                         # Create a new vertex group!
  82.                         newGroup = ob.vertex_groups.new('mygroup')
  83.                         groupList.append(newGroup)
  84.  
  85.                         # Get all the vertices in the current face and add them to the new group
  86.                         for v in f.vertices:
  87.                                 newGroup.add([v], 1.0, 'REPLACE')
  88.                        
  89.         # Now we loop through the groups and do what we want.
  90.         for g in groupList:
  91.  
  92.                 # Make sure nothing is selected
  93.                 bpy.ops.object.mode_set(mode='EDIT')
  94.                 bpy.ops.mesh.select_all(action='DESELECT')
  95.  
  96.                 # Make the group in our list the active one
  97.                 ob.vertex_groups.active_index = g.index
  98.  
  99.                 # Select all the verts in the active group
  100.                 bpy.ops.object.vertex_group_select()
  101.  
  102.                 bpy.ops.object.vertex_group_remove(all=False)
  103.  
  104.                 # AND NOW WE CAN DO OUR STUFF... little test example follows
  105.                 t = startAngle
  106.                 oldRatio = 1.0
  107.                 # Shape
  108.                 for i in range(stepNum):
  109.      
  110.                         bpy.ops.mesh.extrude(type='REGION')
  111.                        
  112.                         # An added trick... remove the extruded face from all vertex groups after the first extrusion (i == 0)
  113.                         # This way it can't get extruded again
  114.                         # Because the edge of the first face can be part of multiple groups
  115.                         if not i:
  116.                                 bpy.ops.object.vertex_group_remove_from(all=True)
  117.                        
  118.                         bpy.ops.object.mode_set(mode='OBJECT')
  119.                         bpy.ops.object.mode_set(mode='EDIT')
  120.                        
  121.                         newRatio = mainLevel*(math.sin(math.radians(t)+modLevel*math.sin(math.radians(t+modRate)))+2.0)/oldRatio
  122.                         dA = stepDist
  123.                         sA = newRatio
  124.                         rA = math.sin(math.radians(t*2))*stepRot
  125.                         axis_x = axis[0]
  126.                         axis_y = axis[1]
  127.                         axis_z = axis[2]
  128.                         transStep(dA, sA, rA, axis_x, axis_y, axis_z)
  129.                         t = t + stepAngle
  130.                         oldRatio = oldRatio*newRatio
  131.        
  132. # transformFaces!(END) --------------------------------------------------<
  133.  
  134. # bodyShape ------------------------------------------------------>
  135. def bodyShape(vGroup, mainLevel, stepNum, stepDist, stepRot, startAngle, stepAngle, modLevel, modRate, axis):
  136.         newGroup = ob.vertex_groups.new(vGroup)
  137.         bpy.ops.object.mode_set(mode='OBJECT')
  138.        
  139.         # Lets loop through all the faces in the mesh
  140.         for f in ob.data.faces:
  141.        
  142.                 # See if the current face's centre is above 0.0 on the Z axis
  143.                 if f.center[1] > -0.1:
  144.                         # Set select to true
  145.                         f.select = True
  146.                 else:
  147.                         f.select = False
  148.                
  149.         bpy.ops.object.mode_set(mode='EDIT')                   
  150.         bpy.ops.object.vertex_group_set_active(group=vGroup)
  151.         bpy.ops.object.vertex_group_assign(new=False)
  152.        
  153.         transformFaces(vGroup, mainLevel, stepNum, stepDist, stepRot, startAngle, stepAngle, modLevel, modRate, axis)
  154.         bpy.ops.mesh.select_all(action='DESELECT')
  155. # bodyShape(END) ---------------------------------------------------<
  156.  
  157. # select faces from Groups --------------------------------------------->
  158. def selPart(vGroup):
  159.         bpy.ops.object.vertex_group_set_active(group=vGroup)
  160.         bpy.ops.object.vertex_group_select()
  161.         bpy.ops.object.vertex_group_remove(all=False)
  162. # select faces from Groups (END)----------------------------------------<
  163.        
  164. # cell subdivide --------------------------------------------->
  165. def cellSubdiv():
  166.         bpy.ops.object.modifier_add(type='SUBSURF')
  167.         bpy.ops.object.mode_set(mode='OBJECT')
  168.         bpy.ops.object.modifier_apply(apply_as='DATA', modifier="Subsurf")
  169. # cell subdivide (END)----------------------------------------<
  170.  
  171. # assignFaces ----------------------------------------------->
  172. def assignFaces(vGroup, xMin, xMax, yMin, yMax, zMin, zMax):
  173.         newGroup = ob.vertex_groups.new(vGroup)
  174.         bpy.ops.object.mode_set(mode='OBJECT')
  175.        
  176.         for f in ob.data.faces:
  177.                
  178.                 if f.center[0] > xMin and f.center[0] < xMax and f.center[1] > yMin and f.center[1] < yMax and f.center[2] > zMin and f.center[2] < zMax:
  179.                         f.select = True
  180.                 else:
  181.                         f.select = False       
  182.                                        
  183.         bpy.ops.object.mode_set(mode='EDIT')                   
  184.         bpy.ops.object.vertex_group_set_active(group=vGroup)
  185.         bpy.ops.object.vertex_group_assign(new=False)
  186.         bpy.ops.mesh.select_all(action='DESELECT')
  187. # assignFaces (END)------------------------------------------<
  188.  
  189. # assignFacesAngle--------------------------------------------->
  190. def assignFacesAngle(vGroup, fAngleMin, fAngleMax, yMin, yMax):
  191.         newGroup = ob.vertex_groups.new(vGroup)
  192.         bpy.ops.object.mode_set(mode='OBJECT')
  193.        
  194.         up = mathutils.Vector((0.0,0.0,1.0))
  195.  
  196.         # Lets loop through all the faces in the mesh
  197.         for f in ob.data.faces:
  198.                 # If the angle between up and the face's normal (direction) is smaller than 45...
  199.                 # The face must be pointing up
  200.                 # To compare the angle we need 45 degrees in radians, not in degrees!
  201.                 # Math with angles is usually all in radians
  202.                 if f.normal.angle(up) > math.radians(fAngleMin) and f.normal.angle(up) < math.radians(fAngleMax) and f.center[1] > yMin and f.center[1] < yMax :
  203.                         # Set select to true
  204.                         f.select = True
  205.                 else:
  206.                         f.select = False
  207.                        
  208.         bpy.ops.object.mode_set(mode='EDIT')                   
  209.         bpy.ops.object.vertex_group_set_active(group=vGroup)
  210.         bpy.ops.object.vertex_group_assign(new=False)
  211.         bpy.ops.mesh.select_all(action='DESELECT')
  212. # assignFacesAngle(END)--------------------------------------<
  213.                
  214. # Generate Object ----------------------------------------->
  215. # -- Set Up(START) ------------------------------------------>
  216. bpy.ops.mesh.primitive_plane_add(view_align=False, enter_editmode=False, location=(0, 0, 0), rotation=(0, 0, 0), layers=(True, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False))
  217. bpy.ops.object.mode_set(mode='EDIT')
  218. bpy.ops.transform.rotate(value=(-1.5708,), axis=(-1, -2.22045e-16, -4.93038e-32), constraint_axis=(False, False, False), constraint_orientation='LOCAL', 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)
  219. bpy.ops.transform.resize(value=(0.05, 1, 0.05), 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)
  220. bpy.ops.object.mode_set(mode='OBJECT')
  221.  
  222. # Now we want to get the active object
  223. # To do this we go through bpy.context... because that is basicly "what you are working on right now"
  224. # bpy.data could work too, but then you'd need to do more work to find your current active object
  225. ob = bpy.context.active_object
  226.  
  227. # A new trick... lets go into edit mode and deselect everything ('SELECT' works too)
  228. bpy.ops.object.mode_set(mode='EDIT')
  229. bpy.ops.mesh.select_all(action='DESELECT')
  230.  
  231. # Get the screen areas we are working in right now
  232. areas = bpy.context.screen.areas
  233.  
  234. # Loop through all the areas
  235. for area in areas:
  236.  
  237.         # See if the current area is a 3D view
  238.         if area.type == 'VIEW_3D':
  239.  
  240.                 # Set the pivot point to individual origins
  241.                 area.active_space.pivot_point = 'INDIVIDUAL_ORIGINS'
  242.  
  243. # -- Set Up(END) ------------------------------------------<
  244.  
  245.        
  246. # bodyShape(vGroup, mainLevel, stepNum, stepDist, stepRot, startAngle, stepAngle, modLevel, modRate, axisArray)
  247. bodyShape('body', bMainLevel, 12, -0.5, sRot/10, sAngle, bStepAngle, bModLevel, bModRate, [-1, -2.22045e-16, -0])
  248. bpy.ops.object.mode_set(mode='OBJECT')
  249.        
  250. cellSubdiv()
  251. # spine
  252. #transformFaces(vGroup, mainLevel, stepNum, stepDist, stepRot, startAngle, stepAngle, modLevel, modRate, axis)
  253. #assignFaces('spine', -5.0, 5.0, 2.5, 20.0, 0.0, 10.0)
  254. #transformFaces('spine', 0.3, 10, -0.2, -0.5, sAngle, 10, 5, 20, [-2.22045e-16, -1, -0])
  255. assignFacesAngle('arm', 0, 45, 2.5, 20.0)
  256. assignFacesAngle('horn', 0, 45, 0.5, 1.5)
  257. assignFacesAngle('leg', 135, 180, 2.0, 4.0)
  258.        
  259. transformFaces('arm', pMainLevel, 10, -0.2, sRot/10, sAngle, pStepAngle*6, pModLevel*5, pModRate*4, [-2.22045e-16, -1, -0])
  260. transformFaces('horn', pMainLevel, 4, -0.1, sRot/10, sAngle, pStepAngle*8, pModLevel*5, pModRate*4, [-2.22045e-16, -1, -0])
  261. transformFaces('leg', pMainLevel, 10, -0.2, sRot/10, sAngle, -pStepAngle*5, pModLevel*2, pModRate*2, [-2.22045e-16, -1, -0])
  262.        
  263. bpy.ops.object.modifier_add(type='SUBSURF')
  264. bpy.ops.object.modifier_add(type='SUBSURF')
  265. bpy.ops.object.mode_set(mode='OBJECT')
  266.        
  267. #fileName = '/Users/shige/Documents/BlenderPJ/GMP_model3/A_Life_'+str(sRot)+'_'+str(sAngle)
  268. #fileName = '/Users/shige/Documents/BlenderPJ/GMP_model/A_Life_sRot_-10_10_2_sAngle_0_180_15)'
  269.  
  270. # Save the current file! (with a specific fileName)            
  271. # bpy.ops.wm.save_as_mainfile(filepath=fileName, check_existing=False, compress=True)
  272.        
  273. #bpy.ops.object.delete()
  274.  
go to heaven