0
$\begingroup$

I am attempting to automate my process of getting models from DAZ Studio and changing them to be similar to MMD format that is commonly used for a game called VRChat. This is my first time using python and coding blender. My current issues are as follows.

Issues

Not deleting Materials

Unable to order shape keys

Unable to delete materials vertices

Unable to order materials

import bpy

#Get the selected object
selected_object = bpy.context.object

#Get object's Shapekeys
shape_keys = selected_object.data.shape_keys.key_blocks

#Loops through shapekeys and replace the names
for key in shape_keys:
    key.name = key.name.replace("Genesis8Male__PHMTeethGap","vrc.v_sil")
    key.name = key.name.replace("head__eCTRLvW","vrc.v_pp")
    key.name = key.name.replace("head__eCTRLvF","vrc.v_ff")
    key.name = key.name.replace("head__eCTRLvTH","vrc.v_th")
    key.name = key.name.replace("head__eCTRLvT","vrc.v_dd")
    key.name = key.name.replace("head__eCTRLvK","vrc.v_kk")
    key.name = key.name.replace("head__eCTRLvSH","vrc.v_ch")
    key.name = key.name.replace("head__eCTRLvS","vrc.v_ss")
    key.name = key.name.replace("head__eCTRLvM","vrc.v_nn")
    key.name = key.name.replace("head__eCTRLvER","vrc.v_rr")
    key.name = key.name.replace("head__eCTRLvAA","vrc.v_aa")
    key.name = key.name.replace("head__eCTRLvEE","vrc.v_e")
    key.name = key.name.replace("head__eCTRLvIH","vrc.v_ih")
    key.name = key.name.replace("head__eCTRLvOW","vrc.v_oh")
    key.name = key.name.replace("head__eCTRLvUW","vrc.v_ou")
    key.name = key.name.replace("head__eCTRLSmileOpenFullFace_HD","Smile")
    key.name = key.name.replace("head__eCTRLAngry_HD","Anger")
    key.name = key.name.replace("head__eCTRLShock_HD","Hachu Eye")
    key.name = key.name.replace("head__eCTRLEyesClosedR","Wink Right")
    key.name = key.name.replace("head__eCTRLEyesClosedL","Wink")
    key.name = key.name.replace("Genesis8Male__HFS_Head_17_Cat","CatHead_Head")
    key.name = key.name.replace("Genesis8MaleEyelashes__HFS_Head_17_Cat","CatHead_Lashes")
    key.name = key.name.replace("head__eCTRLEyesClosed","Blink")
    key.name = key.name.replace("Genesis8Male__HFS_Legs_05_Pawed","Paws")
    key.name = key.name.replace("Genesis8Male__PHMEyesPupilsSlit","SlitEyes")

ob=selected_object
sk = ob.data.shape_keys

#Materials
for material in bpy.data.materials:
    material.name = material.name.replace("EyeSocket","Face")
    material.name = material.name.replace("Face.001","Face")
    material.name = material.name.replace("EyeMoisture","Delete1")
    material.name = material.name.replace("Toenails","Legs")
    material.name = material.name.replace("Fingernails","Arms")
    material.name = material.name.replace("Legs.001","Legs")
    material.name = material.name.replace("Sclera","Eyes")
    material.name = material.name.replace("Cornea","Delete2")

for material in bpy.data.materials:
    if(material.name=='Delete1'):
        bpy.ops.object.editmode_toggle()
        bpy.ops.object.material_slot_select()
        bpy.ops.mesh.delete(type='VERT')
        bpy.ops.object.editmode_toggle()
    if(material.name=='Delete2'):
        bpy.ops.object.editmode_toggle()
        bpy.ops.object.material_slot_select()
        bpy.ops.mesh.delete(type='VERT')
        bpy.ops.object.editmode_toggle()
    bpy.ops.object.material_slot_remove_unused()

#ShapeKeys  
kingKey=bpy.data.shape_keys["Key.001"].key_blocks          
for shape in ob.data.shape_keys.key_blocks:
    if (shape.name=='vrc.v_aa'):
        shape.value=1.0
        selected_object.shape_key_add(from_mix=True)
        shape.value=0.0
        for key in shape_keys:
             key.name = key.name.replace("Key","Aah")
    if (shape.name=='Aah'):
        shape.value=1.0
        kingKey["vrc.v_aa"].value = 1
        selected_object.shape_key_add(from_mix=True)
        kingKey["vrc.v_aa"].value = 0
        shape.value=0.0
        for key in shape_keys:
             key.name = key.name.replace("Key","Aah 2")
    if (shape.name=='vrc.v_ch'):
        shape.value=1.0
        selected_object.shape_key_add(from_mix=True)
        shape.value=0.0
        for key in shape_keys:
             key.name = key.name.replace("Key","Ch")
    if (shape.name=='vrc.v_ou'):
        shape.value=1.0
        selected_object.shape_key_add(from_mix=True)
        shape.value=0.0
        for key in shape_keys:
             key.name = key.name.replace("Key","U")
    if (shape.name=='vrc.v_e'):
        shape.value=1.0
        selected_object.shape_key_add(from_mix=True)
        shape.value=0.0
        for key in shape_keys:
             key.name = key.name.replace("Key","E")
    if (shape.name=='vrc.v_oh'):
        shape.value=1.0
        selected_object.shape_key_add(from_mix=True)
        shape.value=0.0
        for key in shape_keys:
             key.name = key.name.replace("Key","Oh")
    if (shape.name=='vrc.v_nn'):
        shape.value=1.0
        selected_object.shape_key_add(from_mix=True)
        shape.value=0.0
        for key in shape_keys:
             key.name = key.name.replace("Key","Hmm")
    if (shape.name=='vrc.v_pp'):
        shape.value=1.0
        selected_object.shape_key_add(from_mix=True)
        shape.value=0.0
        for key in shape_keys:
             key.name = key.name.replace("Key","Wa")
    if (shape.name=='CatHead_Head'):
        shape.value=1.0
        kingKey["CatHead_Lashes"].value = 1
        selected_object.shape_key_add(from_mix=True)
        kingKey["CatHead_Lashes"].value = 0
        shape.value=0.0
        for key in shape_keys:
             key.name = key.name.replace("Key","CatHead")
    if (shape.name=='Genesis8Male__PHMEyesPupilsDilate'):
        shape.value=0.15
        kingKey["Genesis8Male__CTRLEyesIrisSize"].slider_min = -1.0
        kingKey["Genesis8Male__CTRLEyesIrisSize"].value = -1.0
        selected_object.shape_key_add(from_mix=True)
        kingKey["Genesis8Male__CTRLEyesIrisSize"].value = 0.0
        shape.value=0.0
        for key in shape_keys:
             key.name = key.name.replace("Key","HorrorChild!")
    if (shape.name=='CatHead'):
        shape.value=1.0
        kingKey["Paws"].value=0.5
        selected_object.shape_key_add(from_mix=True)
        kingKey["Paws"].value=0.0
        shape.value=0.0
        for key in shape_keys:
            key.name = key.name.replace("Key","Full_Cat")

Code

https://pastebin.com/atrfgdQg

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.