The script (my version) is buggy. You must select the mesh then run script for it to work. And the last shape key does not get closed, you have to do it manually. I just intended it to show the functionality.
#*****************************Mike-White 2-25-11**********************************
# reading imported file & creating keys
def spltr():
f=open(scn.fpath) # importing file
f.readline() # reading the 1st line that we don"t need
prev_line=""
for line in f:
# removing new lines
lsta = re.split("
+", line)
# building a list of frames & shapes indexes
lst = re.split(":? ", lsta[0])
frm = int(lst[0])
ThisFrame = str(frm)
LastPhnm = prev_line
print (' ')
print (' ')
print (' ')
print ('The current frame is: ' + ThisFrame)
print
# creating keys and setting the previous line argument for the crtkey function
if lst[1]=="AI" and AI=="on":
crtkey(AIphnm, frm, LastPhnm)
prev_line=('AI')
elif lst[1]=="O" and O=="on":
crtkey(Ophnm, frm, LastPhnm)
prev_line=('O')
elif lst[1]=="E" and E=="on":
crtkey(Ephnm, frm, LastPhnm)
prev_line=('E')
elif lst[1]=="U" and U=="on":
crtkey(Uphnm, frm, LastPhnm)
prev_line=('U')
elif lst[1]=="etc" and etc=="on":
crtkey(etcphnm, frm, LastPhnm)
prev_line=('etc')
elif lst[1]=="L" and L=="on":
crtkey(Lphnm, frm, LastPhnm)
prev_line=('L')
elif lst[1]=="WQ" and WQ=="on":
crtkey(WQphnm, frm, LastPhnm)
prev_line=('WQ')
elif lst[1]=="MBP" and MBP=="on":
crtkey(MBPphnm, frm, LastPhnm)
prev_line=('MBP')
elif lst[1]=="FV" and FV=="on":
crtkey(FVphnm, frm, LastPhnm)
prev_line=('FV')
elif lst[1]=="rest" and rest=="on":
crtkey(restphnm, frm, LastPhnm)
prev_line=('rest')
# creating keys with offset, and ease in
def crtkey(phoneme, Skey, LastPhoneme):
objSK=obj.data.shape_keys
obj.active_shape_key_index=phoneme
offst=scn['offset'] # offset value
skVlu=scn['skscale'] # shape key value
frmIn=scn['easeIn'] # ease in value
frmOut=scn['easeOut'] # ease out value
# Inserting Ease in Keyframe for Current Shape
obj.active_shape_key.value=0.0
objSK.keys[phoneme].keyframe_insert("value",
-1, offst+Skey-frmIn, "Lipsync")
# Inserting Main Keyframe for Current Shape
obj.active_shape_key.value=skVlu
objSK.keys[phoneme].keyframe_insert("value",
-1, offst+Skey, "Lipsync")
#Outputting feedback to the Console
somevar=('Added Keys to: ' + obj.active_shape_key.name)
print (somevar)
print ('Drumroll Please...... The......Last....Key....Was: ' + LastPhoneme)
#Check if Hold Keys is Activated and if so plot keys without holds
HoldKeys=scn['holdKeys']
if HoldKeys==1:
print ('Key was held')
if HoldKeys==0:
obj.active_shape_key.value=0.0
objSK.keys[phoneme].keyframe_insert("value",
-1, offst+Skey+frmOut, "Lipsync")
else:
# Inserting Ease out Keyframe for just First Shape Key
if LastPhoneme == '':
obj.active_shape_key.value=0.0
objSK.keys[phoneme].keyframe_insert("value",
-1, offst+Skey+frmOut, "Lipsync")
if LastPhoneme=="AI" and AI=="on":
lastkey(AIphnm, Skey)
elif LastPhoneme=="O" and O=="on":
lastkey(Ophnm, Skey)
elif LastPhoneme=="E" and E=="on":
lastkey(Ephnm, Skey)
elif LastPhoneme=="U" and U=="on":
lastkey(Uphnm, Skey)
elif LastPhoneme=="etc" and etc=="on":
lastkey(etcphnm, Skey)
elif LastPhoneme=="L" and L=="on":
lastkey(Lphnm, Skey)
elif LastPhoneme=="WQ" and WQ=="on":
lastkey(WQphnm, Skey)
elif LastPhoneme=="MBP" and MBP=="on":
lastkey(MBPphnm, Skey)
elif LastPhoneme=="FV" and FV=="on":
lastkey(FVphnm, Skey)
elif LastPhoneme=="rest" and rest=="on":
lastkey(restphnm, Skey)
# creating Holdkeys with offset, and ease out
def lastkey(HoldPhoneme, LastKey):
objSK=obj.data.shape_keys
obj.active_shape_key_index=HoldPhoneme
offst=scn['offset'] # offset value
skVlu=scn['skscale'] # shape key value
frmIn=scn['easeIn'] # ease in value
frmOut=scn['easeOut'] # ease out value
# Inserting Hold Keyframe for Last Shape
obj.active_shape_key.value=skVlu
objSK.keys[HoldPhoneme].keyframe_insert("value",
-1, offst+LastKey-frmIn, "Lipsync")
# Inserting Ease out Keyframe for Last Shape
obj.active_shape_key.value=0.0
objSK.keys[HoldPhoneme].keyframe_insert("value",
-1, offst+LastKey, "Lipsync")
#*****************************Mike-White 2-25-11**********************************
As you can see, the code just makes use of the prev_line to check what the previous key was, while running through the for loop and the list.