Skip to content

Instantly share code, notes, and snippets.

@lowteq
Created March 13, 2020 14:41
Show Gist options
  • Save lowteq/48d1b3cb2a7d8e0f03f71f7d41a5fa58 to your computer and use it in GitHub Desktop.
Save lowteq/48d1b3cb2a7d8e0f03f71f7d41a5fa58 to your computer and use it in GitHub Desktop.
import bpy
def pivotpointchange(pivotpoint):
for area in bpy.context.screen.areas:
if area.type == 'VIEW_3D':
area.spaces[0].pivot_point = pivotpoint
def currentpivotpoint():
for area in bpy.context.screen.areas:
if area.type == 'VIEW_3D':
return area.spaces[0].pivot_point
def get_override(area_type, region_type):
for area in bpy.context.screen.areas:
if area.type == area_type:
for region in area.regions:
if region.type == region_type:
override = {'area': area, 'region': region}
return override
#error message if the area or region wasn't found
raise RuntimeError("Wasn't able to find", region_type," in area ", area_type,
"\n Make sure it's open while executing script.")
bl_info = {
"name": "FaceEXShapekey",
"author": "lowteq",
"version": (1, 0),
"blender": (2, 78, 0),
"location": "3D View > Mesh",
"description": "Create extra shapekeys for faces",
"warning": "",
"support": "TESTING",
"wiki_url": "",
"tracker_url": "",
"category": "User Interface"
}
class FaceEXShapekey(bpy.types.Operator):
bl_idname = "object.faceexshapekey"
bl_label = "Face EX Shapekey"
bl_description = "Create extra shapekeys for faces"
bl_options = {'REGISTER', 'UNDO'}
def execute(self, context):
duplicateFlag = True
innerOffset = 0.05
innerScale = 0.5
surfOffset = 0.001
surfScale = 1.00
if bpy.context.mode != "EDIT_MESH":
print("must run in EDITMODE")
exit()
obj = bpy.context.object
obj.active_shape_key_index = 0
if duplicateFlag:
bpy.ops.mesh.duplicate()
override = get_override("VIEW_3D","WINDOW")
pivotPointTemp = currentpivotpoint()
pivotpointchange('INDIVIDUAL_ORIGINS')
bpy.ops.transform.translate(value=(0, innerOffset, 0), constraint_axis=(False, True, False), constraint_orientation='GLOBAL', mirror=False, proportional='DISABLED')
bpy.ops.transform.resize(override,value=(innerScale, innerScale, innerScale), constraint_axis=(False, False, False), constraint_orientation='GLOBAL', mirror=False, proportional='DISABLED')
exshapekey = obj.shape_key_add(name="Ex",from_mix=False)
index = len(obj.data.shape_keys.key_blocks) - 1
bpy.context.object.active_shape_key_index = index
obj.data.shape_keys.key_blocks[exshapekey.name].value = 1
bpy.ops.transform.resize(override,value=(1/innerScale, 1/innerScale, 1/innerScale), constraint_axis=(False, False, False), constraint_orientation='GLOBAL', mirror=True, proportional='DISABLED')
bpy.ops.transform.translate(value=(0, -(innerOffset+surfOffset), 0), constraint_axis=(False, True, False), constraint_orientation='GLOBAL', mirror=True, proportional='DISABLED')
bpy.ops.transform.resize(override,value=(surfScale, surfScale, surfScale), constraint_axis=(False, False, False), constraint_orientation='GLOBAL', mirror=True, proportional='DISABLED')
obj.data.shape_keys.key_blocks[exshapekey.name].value = 0
pivotpointchange(pivotPointTemp)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment