Paste Code
Paste Blends
Paste Images
import bpy
import random

'''
Press "Run Script" to generate a new avatar

'''

def main():
print("-"*12)
reset_scene()

#generate a random_pass_index for magic_colors material

random_index = random.randint(0, 10)

create_body_part("body",0,random_index)
create_body_part("head",3,random_index)
create_body_part("eye",2,random_index)
create_body_part("mouth",0,random_index)

#set_random_pass_index()

def create_body_part(part,height,random_index=1):

#get s random mesh from a certain type
mesh = get_random_mesh_by_type(part)

bpy.ops.object.add(type="MESH")
ob = bpy.context.object
bpy.ops.object.modifier_add()

ob.name = part
ob.data = mesh
ob.modifiers[0].levels =2

ob.location = [0,0,height]

ob.pass_index = random_index

print ("created a body part "+mesh.name)

def get_random_mesh_by_type(type):
meshes = bpy.data.meshes
cool_meshes = []

# on selectionne seuelement les mesh d'un type voulu
for mesh in meshes :
if mesh.name.startswith(type):
cool_meshes.append(mesh)
#print("yeah" + mesh.name)
print(cool_meshes)

max = len(cool_meshes)

x = random.randint(0, max-1)

me = cool_meshes[x]

print("Your random %s is %s " % (type.upper(),me.name))

return me


def reset_scene():
objects_on_1st_layer = [ob for ob in bpy.context.scene.objects if ob.layers[0]]

for ob in objects_on_1st_layer:
ob.select = True

bpy.ops.object.delete()

main()
  1. import bpy
  2. import random
  3.  
  4. '''
  5. Press "Run Script" to generate a new avatar
  6.  
  7. '''
  8.  
  9. def main():
  10.     print("-"*12)
  11.     reset_scene()
  12.  
  13.     #generate a random_pass_index for magic_colors material
  14.    
  15.     random_index = random.randint(0, 10)
  16.  
  17.     create_body_part("body",0,random_index)
  18.     create_body_part("head",3,random_index)
  19.     create_body_part("eye",2,random_index)
  20.     create_body_part("mouth",0,random_index)
  21.    
  22.     #set_random_pass_index()
  23.    
  24. def create_body_part(part,height,random_index=1):
  25.    
  26.     #get s random mesh from a certain type
  27.     mesh = get_random_mesh_by_type(part)
  28.  
  29.     bpy.ops.object.add(type="MESH")
  30.     ob = bpy.context.object
  31.     bpy.ops.object.modifier_add()
  32.  
  33.     ob.name = part
  34.     ob.data = mesh
  35.     ob.modifiers[0].levels =2
  36.  
  37.     ob.location = [0,0,height]
  38.    
  39.     ob.pass_index = random_index
  40.        
  41.     print ("created a body part "+mesh.name)    
  42.  
  43. def get_random_mesh_by_type(type):
  44.     meshes = bpy.data.meshes
  45.     cool_meshes = []
  46.    
  47.     # on selectionne seuelement les mesh d'un type voulu
  48.     for mesh in meshes :
  49.         if mesh.name.startswith(type):
  50.             cool_meshes.append(mesh)
  51.             #print("yeah" + mesh.name)
  52.     print(cool_meshes)
  53.    
  54.     max = len(cool_meshes)
  55.    
  56.     x = random.randint(0, max-1)
  57.  
  58.     me = cool_meshes[x]
  59.  
  60.     print("Your random %s is %s " % (type.upper(),me.name))
  61.  
  62.     return me
  63.  
  64.  
  65. def reset_scene():
  66.     objects_on_1st_layer = [ob for ob in bpy.context.scene.objects if ob.layers[0]]
  67.    
  68.     for ob in objects_on_1st_layer:
  69.         ob.select = True
  70.    
  71.     bpy.ops.object.delete()
  72.    
  73. main()
  74.  
go to heaven