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 GMP_Panel(bpy.types.Panel):
bl_label = "Generative Modeling"
bl_space_type = "VIEW_3D"
bl_region_type = "TOOLS"

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

scn = bpy.context.scene

row = layout.row()

row.operator( "bpt.generate_op" )

class GMP_Operator(bpy.types.Operator):
bl_idname = "bpt.generate_op"
bl_label = "Generate"

def execute(self, context):
# Do 8 operations
clearAndSetNewObj()

operation1()
operation2()
operation3()
operation4()
operation5()
operation6()
operation7()
operation8()

return {'FINISHED'}

def register():
bpy.utils.register_class( GMP_Operator )
bpy.utils.register_class( GMP_Panel )

def unregister():
bpy.utils.register_class( GMP_Operator )
bpy.utils.register_class( GMP_Panel )


# Add first cube
bpy.ops.mesh.primitive_cube_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.add_named(linked=False, name="NewOrigin")

# SubSurf and Apply
bpy.ops.object.modifier_add(type='SUBSURF')
bpy.ops.object.modifier_apply(apply_as='DATA', modifier="Subsurf")

# clearAndSetNewObj
def clearAndSetNewObj():
bpy.ops.object.select_inverse()
bpy.ops.object.delete()
bpy.ops.object.select_all(action='TOGGLE')

# Move Selected Object to Center(0, 0, 0) ------------------
bpy.ops.transform.translate(value=(0, 0, 0), constraint_axis=(False, False, False), constraint_orientation='GLOBAL', 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), texture_space=False, release_confirm=False)

# op.1
def operation1():
bpy.ops.object.select_name(name="Cube", extend=False)

bpy.ops.object.duplicate_move(OBJECT_OT_duplicate={"linked":False, "mode":'TRANSLATION'}, TRANSFORM_OT_translate={"value":(-5, 5, 0), "constraint_axis":(False, False, False), "constraint_orientation":'GLOBAL', "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), "texture_space":False, "release_confirm":False})

ob = bpy.context.active_object
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[2] < -0.5:
# 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.object.mode_set(mode='OBJECT')

# op.2
def operation2():
bpy.ops.object.select_name(name="Cube", extend=False)

bpy.ops.object.duplicate_move(OBJECT_OT_duplicate={"linked":False, "mode":'TRANSLATION'}, TRANSFORM_OT_translate={"value":(0, 5, 0), "constraint_axis":(False, False, False), "constraint_orientation":'GLOBAL', "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), "texture_space":False, "release_confirm":False})

ob = bpy.context.active_object
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[0] > 0.5 or f.center[0] < -0.5):
# 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.object.mode_set(mode='OBJECT')

# op.3
def operation3():
bpy.ops.object.select_name(name="Cube", extend=False)

bpy.ops.object.duplicate_move(OBJECT_OT_duplicate={"linked":False, "mode":'TRANSLATION'}, TRANSFORM_OT_translate={"value":(5, 5, 0), "constraint_axis":(False, False, False), "constraint_orientation":'GLOBAL', "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), "texture_space":False, "release_confirm":False})

# op.4
def operation4():
bpy.ops.object.select_name(name="Cube", extend=False)

bpy.ops.object.duplicate_move(OBJECT_OT_duplicate={"linked":False, "mode":'TRANSLATION'}, TRANSFORM_OT_translate={"value":(-5, 0, 0), "constraint_axis":(False, False, False), "constraint_orientation":'GLOBAL', "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), "texture_space":False, "release_confirm":False})

# op.5
def operation5():
bpy.ops.object.select_name(name="Cube", extend=False)

bpy.ops.object.duplicate_move(OBJECT_OT_duplicate={"linked":False, "mode":'TRANSLATION'}, TRANSFORM_OT_translate={"value":(5, 0, 0), "constraint_axis":(False, False, False), "constraint_orientation":'GLOBAL', "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), "texture_space":False, "release_confirm":False})

# op.6
def operation6():
bpy.ops.object.select_name(name="Cube", extend=False)

bpy.ops.object.duplicate_move(OBJECT_OT_duplicate={"linked":False, "mode":'TRANSLATION'}, TRANSFORM_OT_translate={"value":(-5, -5, 0), "constraint_axis":(False, False, False), "constraint_orientation":'GLOBAL', "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), "texture_space":False, "release_confirm":False})

# op.7
def operation7():
bpy.ops.object.select_name(name="Cube", extend=False)

bpy.ops.object.duplicate_move(OBJECT_OT_duplicate={"linked":False, "mode":'TRANSLATION'}, TRANSFORM_OT_translate={"value":(0, -5, 0), "constraint_axis":(False, False, False), "constraint_orientation":'GLOBAL', "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), "texture_space":False, "release_confirm":False})

# op.8
def operation8():
bpy.ops.object.select_name(name="Cube", extend=False)

bpy.ops.object.duplicate_move(OBJECT_OT_duplicate={"linked":False, "mode":'TRANSLATION'}, TRANSFORM_OT_translate={"value":(5, -5, 0), "constraint_axis":(False, False, False), "constraint_orientation":'GLOBAL', "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), "texture_space":False, "release_confirm":False})

bpy.ops.object.modifier_add(type='SUBSURF')
bpy.ops.object.modifier_apply(apply_as='DATA', modifier="Subsurf")

if __name__ == '__main__':

register()
  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 GMP_Panel(bpy.types.Panel):
  7.         bl_label = "Generative Modeling"
  8.         bl_space_type = "VIEW_3D"
  9.         bl_region_type = "TOOLS"
  10.        
  11.         def draw(self, context):
  12.                 layout = self.layout
  13.                
  14.                 scn = bpy.context.scene
  15.                
  16.                 row = layout.row()
  17.                
  18.                 row.operator( "bpt.generate_op" )
  19.                
  20. class GMP_Operator(bpy.types.Operator):
  21.         bl_idname = "bpt.generate_op"
  22.         bl_label = "Generate"
  23.  
  24.         def execute(self, context):
  25.                 # Do 8 operations
  26.                 clearAndSetNewObj()
  27.                
  28.                 operation1()
  29.                 operation2()
  30.                 operation3()
  31.                 operation4()
  32.                 operation5()
  33.                 operation6()
  34.                 operation7()
  35.                 operation8()
  36.                
  37.                 return {'FINISHED'}
  38.  
  39. def register():
  40.         bpy.utils.register_class( GMP_Operator )
  41.         bpy.utils.register_class( GMP_Panel )
  42.  
  43. def unregister():
  44.         bpy.utils.register_class( GMP_Operator )
  45.         bpy.utils.register_class( GMP_Panel )
  46.  
  47.  
  48. # Add first cube
  49. bpy.ops.mesh.primitive_cube_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))
  50.  
  51. bpy.ops.object.add_named(linked=False, name="NewOrigin")
  52.  
  53. # SubSurf and Apply
  54. bpy.ops.object.modifier_add(type='SUBSURF')
  55. bpy.ops.object.modifier_apply(apply_as='DATA', modifier="Subsurf")
  56.  
  57. # clearAndSetNewObj
  58. def clearAndSetNewObj():
  59.         bpy.ops.object.select_inverse()
  60.         bpy.ops.object.delete()
  61.         bpy.ops.object.select_all(action='TOGGLE')
  62.        
  63.         # Move Selected Object to Center(0, 0, 0) ------------------
  64.         bpy.ops.transform.translate(value=(0, 0, 0), constraint_axis=(False, False, False), constraint_orientation='GLOBAL', 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), texture_space=False, release_confirm=False)
  65.  
  66. # op.1
  67. def operation1():
  68.         bpy.ops.object.select_name(name="Cube", extend=False)
  69.  
  70.         bpy.ops.object.duplicate_move(OBJECT_OT_duplicate={"linked":False, "mode":'TRANSLATION'}, TRANSFORM_OT_translate={"value":(-5, 5, 0), "constraint_axis":(False, False, False), "constraint_orientation":'GLOBAL', "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), "texture_space":False, "release_confirm":False})
  71.  
  72.         ob = bpy.context.active_object
  73.         newGroup = ob.vertex_groups.new('vGroup')
  74.         bpy.ops.object.mode_set(mode='OBJECT')
  75.        
  76.         # Lets loop through all the faces in the mesh
  77.         for f in ob.data.faces:
  78.        
  79.                 # See if the current face's centre is above 0.0 on the Z axis
  80.                 if f.center[2] < -0.5:
  81.                         # Set select to true
  82.                         f.select = True
  83.                 else:
  84.                         f.select = False
  85.                
  86.         bpy.ops.object.mode_set(mode='EDIT')                   
  87.         bpy.ops.object.vertex_group_set_active(group='vGroup')
  88.         bpy.ops.object.vertex_group_assign(new=False)
  89.         bpy.ops.object.mode_set(mode='OBJECT')
  90.                
  91. # op.2
  92. def operation2():
  93.         bpy.ops.object.select_name(name="Cube", extend=False)
  94.  
  95.         bpy.ops.object.duplicate_move(OBJECT_OT_duplicate={"linked":False, "mode":'TRANSLATION'}, TRANSFORM_OT_translate={"value":(0, 5, 0), "constraint_axis":(False, False, False), "constraint_orientation":'GLOBAL', "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), "texture_space":False, "release_confirm":False})
  96.  
  97.         ob = bpy.context.active_object
  98.         newGroup = ob.vertex_groups.new('vGroup')
  99.         bpy.ops.object.mode_set(mode='OBJECT')
  100.        
  101.         # Lets loop through all the faces in the mesh
  102.         for f in ob.data.faces:
  103.        
  104.                 # See if the current face's centre is above 0.0 on the Z axis
  105.                 if (f.center[0] > 0.5 or f.center[0] < -0.5):
  106.                         # Set select to true
  107.                         f.select = True
  108.                 else:
  109.                         f.select = False
  110.                
  111.         bpy.ops.object.mode_set(mode='EDIT')                   
  112.         bpy.ops.object.vertex_group_set_active(group='vGroup')
  113.         bpy.ops.object.vertex_group_assign(new=False)
  114.         bpy.ops.object.mode_set(mode='OBJECT')
  115.  
  116. # op.3
  117. def operation3():
  118.         bpy.ops.object.select_name(name="Cube", extend=False)
  119.  
  120.         bpy.ops.object.duplicate_move(OBJECT_OT_duplicate={"linked":False, "mode":'TRANSLATION'}, TRANSFORM_OT_translate={"value":(5, 5, 0), "constraint_axis":(False, False, False), "constraint_orientation":'GLOBAL', "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), "texture_space":False, "release_confirm":False})
  121.  
  122. # op.4
  123. def operation4():
  124.         bpy.ops.object.select_name(name="Cube", extend=False)
  125.  
  126.         bpy.ops.object.duplicate_move(OBJECT_OT_duplicate={"linked":False, "mode":'TRANSLATION'}, TRANSFORM_OT_translate={"value":(-5, 0, 0), "constraint_axis":(False, False, False), "constraint_orientation":'GLOBAL', "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), "texture_space":False, "release_confirm":False})
  127.  
  128. # op.5
  129. def operation5():
  130.         bpy.ops.object.select_name(name="Cube", extend=False)
  131.  
  132.         bpy.ops.object.duplicate_move(OBJECT_OT_duplicate={"linked":False, "mode":'TRANSLATION'}, TRANSFORM_OT_translate={"value":(5, 0, 0), "constraint_axis":(False, False, False), "constraint_orientation":'GLOBAL', "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), "texture_space":False, "release_confirm":False})
  133.  
  134. # op.6
  135. def operation6():
  136.         bpy.ops.object.select_name(name="Cube", extend=False)
  137.  
  138.         bpy.ops.object.duplicate_move(OBJECT_OT_duplicate={"linked":False, "mode":'TRANSLATION'}, TRANSFORM_OT_translate={"value":(-5, -5, 0), "constraint_axis":(False, False, False), "constraint_orientation":'GLOBAL', "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), "texture_space":False, "release_confirm":False})
  139.  
  140. # op.7
  141. def operation7():
  142.         bpy.ops.object.select_name(name="Cube", extend=False)
  143.  
  144.         bpy.ops.object.duplicate_move(OBJECT_OT_duplicate={"linked":False, "mode":'TRANSLATION'}, TRANSFORM_OT_translate={"value":(0, -5, 0), "constraint_axis":(False, False, False), "constraint_orientation":'GLOBAL', "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), "texture_space":False, "release_confirm":False})
  145.  
  146. # op.8
  147. def operation8():
  148.         bpy.ops.object.select_name(name="Cube", extend=False)
  149.  
  150.         bpy.ops.object.duplicate_move(OBJECT_OT_duplicate={"linked":False, "mode":'TRANSLATION'}, TRANSFORM_OT_translate={"value":(5, -5, 0), "constraint_axis":(False, False, False), "constraint_orientation":'GLOBAL', "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), "texture_space":False, "release_confirm":False})
  151.  
  152.         bpy.ops.object.modifier_add(type='SUBSURF')
  153.         bpy.ops.object.modifier_apply(apply_as='DATA', modifier="Subsurf")
  154.  
  155. if __name__ == '__main__':
  156.  
  157.         register()
  158.  
go to heaven