From 310fe129b3743d9092788d5b8efe813d1fbcc1cd Mon Sep 17 00:00:00 2001 From: jacopods Date: Tue, 13 Feb 2018 17:22:30 -0500 Subject: [PATCH] Center, rotate the keyboard forward and scale to reasonable size --- import_keyboard.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/import_keyboard.py b/import_keyboard.py index b387a2c..1fc9776 100644 --- a/import_keyboard.py +++ b/import_keyboard.py @@ -456,6 +456,12 @@ def read(filepath): scn = bpy.context.scene scn.display_settings.display_device = "None" + bpy.ops.group.create(name="Keyboard") + + keyboard_empty = bpy.data.objects.new("Keyboard_whole", None) + keyboard_empty.location = (0,0,0) + scn.objects.link(keyboard_empty) + # set width and height of keyboard width = 0 height = 0 @@ -1224,6 +1230,16 @@ def read(filepath): empty.select = True bpy.ops.object.delete(use_global=False) + new_obj_tl.select = True + new_switch.select = True + + scn.objects.active = keyboard_empty + bpy.ops.object.parent_set(type="OBJECT") + + # deselect everything + for obj in scn.objects: + obj.select = False + # set the keyboard width and height if it was smaller than the # current width if key["x"] + key["w"] + 0.05 > width: @@ -1330,10 +1346,25 @@ def read(filepath): bpy.ops.object.join() # name the case side5.name = "Case" + + scn.objects.active = keyboard_empty + bpy.ops.object.parent_set(type="OBJECT") + + # This assumes 1 blender unit = 10cm + blender_scaling = .1905 + keyboard_empty.scale = (blender_scaling,blender_scaling,blender_scaling) + keyboard_empty.rotation_euler[2] = pi + keyboard_empty.location = (-blender_scaling*width*0.5,blender_scaling*height*0.5,blender_scaling*0.5) + # deselect everything for obj in scn.objects: obj.select = False + keyboard_empty.select = True + scn.objects.active = keyboard_empty + bpy.ops.object.transform_apply(location=True, scale=True, rotation=True) + bpy.ops.object.delete(use_global=False) + side5.select = True scn.objects.active = side5 # bevel the corners