I am trying to create an drive a shape key using Python. I used this answer to create a shape key: Creating shape keys using Python I have been able to use this answer to create a shape key in Python and I can modify it in the shape key panel.
I would like to be able to change the shape key value in a custom menu or panel, so I tried this answer to add a driver: Python: drive a shape key with scripting
The driver Python script works if I create a shape key in Blender using the GUI, but I can not get it to work if I create the shape key using Python. I tried to incorporate the corrections in the comments related to creating the shape key, but I still can not use the shape key driver to change the value of a shape key created in Python.
Here is the code I am using the create the shape key:
import bpy import bmesh context = bpy.context obj = context.object # add a shape key to the active object # now set up shape key in Blender mesh=obj.data sk_basis = obj.shape_key_add(name='Basis',from_mix=False) sk_basis.interpolation = 'KEY_LINEAR' obj.data.shape_keys.use_relative = False # create new shape key sk = obj.shape_key_add(name='Deform',from_mix=False) sk.interpolation = 'KEY_LINEAR' sk.slider_min = 1 sk.slider_max = 2 bpy.ops.object.mode_set(mode='EDIT') bm=bmesh.new() bm=bmesh.from_edit_mesh(mesh) bm.faces.ensure_lookup_table() for face in bm.faces: # make sure the zeros are actually zero by rounding curr_normal=[round(face.normal*1000)/1000,round(face.normal*1000)/1000,round(face.normal*1000)/1000] if curr_normal==[0,0,1]: # find the top face print('this is the face: ',face.index) for vert in face.verts: vert.co.z=vert.co.z+2 bmesh.update_edit_mesh(mesh,True) bm.free() bpy.ops.object.mode_set(mode='OBJECT')
Can anyone tell me why the value of a this shape key created in Python can not be changed using a shape key custom property driver.