0
$\begingroup$

I'm new to all of this and I tried creating a script that redo's certain actions on converting and editing a model in 1 click.

It currently seems to just always crash near the end and I got no clue how to solve or where I've possible gone wrong since cutting it apart and trying to find out what crashes it doesn't seem to work, as it'll work that way.

I'll provide a crash log alongside the script itself

Script:

import bpy

#clear Empties
bpy.ops.object.select_all(action='DESELECT')
objects = bpy.context.scene.objects

for obj in objects:
    obj.select_set(obj.type == "EMPTY")
    bpy.ops.object.delete()
    bpy.ops.object.select_all(action='DESELECT')

    
#Clear Rotations
objects = bpy.context.scene.objects

for obj in objects:
    obj.select_set(obj.type == "ARMATURE")
    bpy.ops.object.rotation_clear(clear_delta=False)
    bpy.ops.object.select_all(action='DESELECT')


#Clear Unwanted Meshes
bpy.data.objects['EffectMesh'].select_set(True)
bpy.data.objects['EyeStar'].select_set(True)
bpy.ops.object.delete()
bpy.ops.object.select_all(action='DESELECT')


#Fix Model + BoneView
bpy.context.scene.combine_mats = False
bpy.ops.cats_armature.fix()
bpy.context.object.display_type = 'WIRE'

#Pose Bones
bpy.ops.object.posemode_toggle()
Shoulder = bpy.data.objects['Armature'].pose.bones['Left shoulder'].bone
bpy.context.object.data.bones.active = Shoulder
Shoulder.select = True
bpy.ops.transform.rotate(value=-0.274017, orient_axis='Y', orient_type='GLOBAL', orient_matrix=((1, 0, 0), (0, 1, 0), (0, 0, 1)), orient_matrix_type='GLOBAL', constraint_axis=(False, True, False), mirror=False, use_proportional_edit=False, proportional_edit_falloff='SMOOTH', proportional_size=1, use_proportional_connected=False, use_proportional_projected=False)
bpy.ops.transform.rotate(value=-0.011476, orient_axis='Z', orient_type='GLOBAL', orient_matrix=((1, 0, 0), (0, 1, 0), (0, 0, 1)), orient_matrix_type='GLOBAL', constraint_axis=(False, False, True), mirror=False, use_proportional_edit=False, proportional_edit_falloff='SMOOTH', proportional_size=1, use_proportional_connected=False, use_proportional_projected=False)
Shoulder.select = False
Arm = bpy.data.objects['Armature'].pose.bones['Left arm'].bone
bpy.context.object.data.bones.active = Arm
Arm.select = True
bpy.ops.transform.rotate(value=-0.704481, orient_axis='Y', orient_type='GLOBAL', orient_matrix=((1, 0, 0), (0, 1, 0), (0, 0, 1)), orient_matrix_type='GLOBAL', constraint_axis=(False, True, False), mirror=False, use_proportional_edit=False, proportional_edit_falloff='SMOOTH', proportional_size=1, use_proportional_connected=False, use_proportional_projected=False)
bpy.ops.transform.rotate(value=-0.0112589, orient_axis='Z', orient_type='GLOBAL', orient_matrix=((1, 0, 0), (0, 1, 0), (0, 0, 1)), orient_matrix_type='GLOBAL', constraint_axis=(False, False, True), mirror=False, use_proportional_edit=False, proportional_edit_falloff='SMOOTH', proportional_size=1, use_proportional_connected=False, use_proportional_projected=False)
Shoulder.select = True
bpy.ops.pose.copy()
bpy.ops.pose.paste(flipped=True)
Shoulder.select = False
Arm.select = False


Leg = bpy.data.objects['Armature'].pose.bones['Left leg'].bone
bpy.context.object.data.bones.active = Leg
Leg.select = True
bpy.ops.transform.rotate(value=-0.0225851, orient_axis='Y', orient_type='GLOBAL', orient_matrix=((1, 0, 0), (0, 1, 0), (0, 0, 1)), orient_matrix_type='GLOBAL', constraint_axis=(False, True, False), mirror=False, use_proportional_edit=False, proportional_edit_falloff='SMOOTH', proportional_size=1, use_proportional_connected=False, use_proportional_projected=False)
bpy.ops.transform.rotate(value=-0.00868026, orient_axis='X', orient_type='GLOBAL', orient_matrix=((1, 0, 0), (0, 1, 0), (0, 0, 1)), orient_matrix_type='GLOBAL', constraint_axis=(True, False, False), mirror=False, use_proportional_edit=False, proportional_edit_falloff='SMOOTH', proportional_size=1, use_proportional_connected=False, use_proportional_projected=False)
Leg.select = False
Knee = bpy.data.objects['Armature'].pose.bones['Left knee'].bone
bpy.context.object.data.bones.active = Knee
Knee.select = True
bpy.ops.transform.rotate(value=-0.0687629, orient_axis='X', orient_type='GLOBAL', orient_matrix=((1, 0, 0), (0, 1, 0), (0, 0, 1)), orient_matrix_type='GLOBAL', constraint_axis=(True, False, False), mirror=False, use_proportional_edit=False, proportional_edit_falloff='SMOOTH', proportional_size=1, use_proportional_connected=False, use_proportional_projected=False)
bpy.ops.transform.rotate(value=0.0944914, orient_axis='X', orient_type='GLOBAL', orient_matrix=((1, 0, 0), (0, 1, 0), (0, 0, 1)), orient_matrix_type='GLOBAL', constraint_axis=(True, False, False), mirror=False, use_proportional_edit=False, proportional_edit_falloff='SMOOTH', proportional_size=1, use_proportional_connected=False, use_proportional_projected=False, release_confirm=True)
Leg.select = True
bpy.ops.pose.copy()
bpy.ops.pose.paste(flipped=True)
Leg.select = False
Knee.select = False
bpy.context.area.ui_type = 'VIEW_3D'
bpy.ops.cats_manual.pose_to_rest()


#Generate A Shape Key
bpy.ops.object.select_all(action='DESELECT')
bpy.data.objects['Body'].select_set(True)
bpy.data.shape_keys["Key.002"].key_blocks["Mouth_A01"].value = 1.0
bpy.data.objects['Body'].shape_key_add(name="A", from_mix=True)
bpy.data.shape_keys["Key.002"].key_blocks["Mouth_A01"].value = 0.0


#Generate O Shape Key
bpy.ops.object.select_all(action='DESELECT')
bpy.data.objects['Body'].select_set(True)
bpy.data.shape_keys["Key.002"].key_blocks["Mouth_Open01"].value = 0.5
bpy.data.shape_keys["Key.002"].key_blocks["Mouth_A01"].value = 0.5
bpy.data.objects['Body'].shape_key_add(name="O", from_mix=True)
bpy.data.shape_keys["Key.002"].key_blocks["Mouth_Open01"].value = 0.0
bpy.data.shape_keys["Key.002"].key_blocks["Mouth_A01"].value = 0.0


#Generate CH Shape Key
bpy.ops.object.select_all(action='DESELECT')
bpy.data.objects['Body'].select_set(True)
bpy.data.shape_keys["Key.002"].key_blocks["Mouth_Angry02"].value = 1.0
bpy.data.objects['Body'].shape_key_add(name="I", from_mix=True)
bpy.data.shape_keys["Key.002"].key_blocks["Mouth_Angry02"].value = 0.0
bpy.ops.cats_viseme.create()
bpy.ops.object.select_all(action='DESELECT')


#Fix Eye Bones
ob = bpy.data.objects['Armature']
armature = ob.data
bpy.ops.object.mode_set(mode='EDIT')
def select_bone(bone):
    bone.select = False
    bone.select_head = False
    bone.select_tail = True

def move_bone(bone):
    bone.select = True
    bone.select_head = True
    bone.select_tail = True   
    
select_bone(armature.edit_bones["+EyeBone_L_A02"])
bpy.ops.transform.rotate(value=-1.5708, orient_axis='X', orient_type='GLOBAL', orient_matrix=((1, 0, 0), (0, 1, 0), (0, 0, 1)), orient_matrix_type='GLOBAL', constraint_axis=(True, False, False), mirror=False, use_proportional_edit=False, proportional_edit_falloff='SMOOTH', proportional_size=1, use_proportional_connected=False, use_proportional_projected=False)
bpy.ops.transform.rotate(value=-0.401426, orient_axis='Y', orient_type='GLOBAL', orient_matrix=((1, 0, 0), (0, 1, 0), (0, 0, 1)), orient_matrix_type='GLOBAL', constraint_axis=(False, True, False), mirror=False, use_proportional_edit=False, proportional_edit_falloff='SMOOTH', proportional_size=1, use_proportional_connected=False, use_proportional_projected=False)
armature.edit_bones["+EyeBone_L_A02"].roll = 0
bpy.ops.armature.select_all(action='DESELECT')
select_bone(armature.edit_bones["+EyeBone_R_A02"])
bpy.ops.transform.rotate(value=-1.5708, orient_axis='X', orient_type='GLOBAL', orient_matrix=((1, 0, 0), (0, 1, 0), (0, 0, 1)), orient_matrix_type='GLOBAL', constraint_axis=(True, False, False), mirror=False, use_proportional_edit=False, proportional_edit_falloff='SMOOTH', proportional_size=1, use_proportional_connected=False, use_proportional_projected=False)
bpy.ops.transform.rotate(value=0.401426, orient_axis='Y', orient_type='GLOBAL', orient_matrix=((1, 0, 0), (0, 1, 0), (0, 0, 1)), orient_matrix_type='GLOBAL', constraint_axis=(False, True, False), mirror=False, use_proportional_edit=False, proportional_edit_falloff='SMOOTH', proportional_size=1, use_proportional_connected=False, use_proportional_projected=False)
armature.edit_bones["+EyeBone_R_A02"].roll = 0
bpy.ops.armature.select_all(action='DESELECT')
move_bone(armature.edit_bones["+EyeBone_L_A02"])
move_bone(armature.edit_bones["+EyeBone_R_A02"])
bpy.ops.transform.translate(value=(0, 0.0213011, 0), orient_axis_ortho='X', orient_type='GLOBAL', orient_matrix=((1, 0, 0), (0, 1, 0), (0, 0, 1)), orient_matrix_type='GLOBAL', constraint_axis=(False, True, False), mirror=False, use_proportional_edit=False, proportional_edit_falloff='SMOOTH', proportional_size=1, use_proportional_connected=False, use_proportional_projected=False)
bpy.ops.object.mode_set(mode='OBJECT')


Error Log: Pastebin

$\endgroup$
1

0

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.