Guest User

Untitled

a guest
Jan 13th, 2019
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.25 KB | None | 0 0
  1. import bpy
  2.  
  3. card_x = 80
  4. card_y = 10
  5. card_z = 135
  6.  
  7. card_margin_x = 20
  8. card_margin_z = 20
  9.  
  10. grid_x = 8 #22
  11. grid_z = 2 #5
  12.  
  13. backplate_x = (card_x + card_margin_x) * grid_x + card_margin_x
  14. backplate_y = 30
  15. backplate_z = (card_z + card_margin_z) * grid_z + card_margin_z
  16.  
  17. backplate_glass_x = backplate_x
  18. backplate_glass_y = 1
  19. backplate_glass_z = backplate_z
  20.  
  21. def draw_backplate():
  22.     bpy.ops.mesh.primitive_cube_add(location=(0, 0, 0), radius=1)
  23.     bpy.ops.transform.resize(value=(backplate_x, backplate_y, backplate_z))
  24.    
  25.     backplate = bpy.context.scene.objects.active
  26.     backplate.name = "Backplate"
  27.     return backplate
  28.  
  29. def carve_cards(backplate):
  30.     loc_x = -backplate_x + card_x + 2 * card_margin_x
  31.     loc_y = backplate_y
  32.     loc_z = -backplate_z + card_z + 2 * card_margin_z
  33.  
  34.     bpy.ops.mesh.primitive_cube_add(location=(loc_x, loc_y, loc_z), radius=1)
  35.     bpy.ops.transform.resize(value=(card_x, 2 * card_y, card_z))
  36.     carve_cards = bpy.context.scene.objects.active
  37.  
  38.     cards_x_modifier = carve_cards.modifiers.new(name="CardsXArray", type="ARRAY")
  39.     cards_x_modifier.fit_type = "FIXED_COUNT"
  40.     cards_x_modifier.count = grid_x
  41.     cards_x_modifier.use_relative_offset = True
  42.     cards_x_modifier.relative_offset_displace = ((card_x + card_margin_x) / card_x, 0, 0)
  43.    
  44.     cards_z_modifier = carve_cards.modifiers.new(name="CardsZArray", type="ARRAY")
  45.     cards_z_modifier.fit_type = "FIXED_COUNT"
  46.     cards_z_modifier.count = grid_z
  47.     cards_z_modifier.use_relative_offset = True
  48.     cards_z_modifier.relative_offset_displace = (0, 0, (card_z + card_margin_z) / card_z)
  49.    
  50.     backplate_modifier = backplate.modifiers.new(name="BackplateBoolean", type="BOOLEAN")
  51.     backplate_modifier.operation = "DIFFERENCE"
  52.     backplate_modifier.object = carve_cards
  53.    
  54.     bpy.context.scene.objects.active = backplate
  55.     bpy.ops.object.modifier_apply(modifier=backplate_modifier.name)
  56.     bpy.data.objects.remove(carve_cards, True)
  57.  
  58. def draw_cards():
  59.     loc_x = -backplate_x + card_x + 2 * card_margin_x
  60.     loc_y = backplate_y - card_y
  61.     loc_z = -backplate_z + card_z + 2 * card_margin_z
  62.  
  63.     bpy.ops.mesh.primitive_cube_add(location=(loc_x, loc_y, loc_z), radius=1)
  64.     bpy.ops.transform.resize(value=(card_x, card_y, card_z))
  65.     cards = bpy.context.scene.objects.active
  66.     cards.name = "Cards"
  67.  
  68.     cards_x_modifier = cards.modifiers.new(name="CardsXArray", type="ARRAY")
  69.     cards_x_modifier.fit_type = "FIXED_COUNT"
  70.     cards_x_modifier.count = grid_x
  71.     cards_x_modifier.use_relative_offset = True
  72.     cards_x_modifier.relative_offset_displace = ((card_x + card_margin_x) / card_x, 0, 0)
  73.    
  74.     cards_z_modifier = cards.modifiers.new(name="CardsZArray", type="ARRAY")
  75.     cards_z_modifier.fit_type = "FIXED_COUNT"
  76.     cards_z_modifier.count = grid_z
  77.     cards_z_modifier.use_relative_offset = True
  78.     cards_z_modifier.relative_offset_displace = (0, 0, (card_z + card_margin_z) / card_z)
  79.    
  80.     return cards
  81.    
  82. def draw_backplate_glass():
  83.     bpy.ops.mesh.primitive_cube_add(location=(0, backplate_y + backplate_glass_y, 0), radius=1)
  84.     bpy.ops.transform.resize(value=(backplate_glass_x, backplate_glass_y, backplate_glass_z))
  85.    
  86.     backplate_glass = bpy.context.scene.objects.active
  87.     backplate_glass.name = "Backplate Glass"
  88.     return backplate_glass
  89.  
  90. def main():
  91.     backplate = draw_backplate()
  92.     carve_cards(backplate)
  93.     #draw_cards()
  94.     draw_backplate_glass()
  95.    
  96. main()
Advertisement
Add Comment
Please, Sign In to add comment