Basic python scrip to make body armature

import bpy

import math

def create_armature(name=”BasicHumanRig”):

  bpy.ops.object.armature_add()

  armature = bpy.context.object

  armature.name = name

  armature.data.name = name

  return armature

def edit_mode():

  bpy.ops.object.mode_set(mode=’EDIT’)

def pose_mode():

  bpy.ops.object.mode_set(mode=’POSE’)

def object_mode():

  bpy.ops.object.mode_set(mode=’OBJECT’)

def create_bone(armature, bone_name, head, tail, parent=None):

  edit_bones = armature.data.edit_bones

  bone = edit_bones.new(bone_name)

  bone.head = head

  bone.tail = tail

  if parent:

    bone.parent = edit_bones[parent]

  return bone

def create_rig():

  armature = create_armature()

  edit_mode()

   

  # Spine

  root = create_bone(armature, “Root”, (0, 0, 0), (0, 0, 1))

  spine = create_bone(armature, “Spine”, (0, 0, 1), (0, 0, 2), parent=”Root”)

  chest = create_bone(armature, “Chest”, (0, 0, 2), (0, 0, 3), parent=”Spine”)

  head = create_bone(armature, “Head”, (0, 0, 3), (0, 0, 4), parent=”Chest”)

   

  # Arms

  shoulder_l = create_bone(armature, “Shoulder.L”, (0.5, 0, 3), (0.75, 0, 3.5), parent=”Chest”)

  upper_arm_l = create_bone(armature, “UpperArm.L”, (0.75, 0, 3.5), (1.25, 0, 3), parent=”Shoulder.L”)

  lower_arm_l = create_bone(armature, “LowerArm.L”, (1.25, 0, 3), (1.75, 0, 2.5), parent=”UpperArm.L”)

  hand_l = create_bone(armature, “Hand.L”, (1.75, 0, 2.5), (2, 0, 2.5), parent=”LowerArm.L”)

   

  shoulder_r = create_bone(armature, “Shoulder.R”, (-0.5, 0, 3), (-0.75, 0, 3.5), parent=”Chest”)

  upper_arm_r = create_bone(armature, “UpperArm.R”, (-0.75, 0, 3.5), (-1.25, 0, 3), parent=”Shoulder.R”)

  lower_arm_r = create_bone(armature, “LowerArm.R”, (-1.25, 0, 3), (-1.75, 0, 2.5), parent=”UpperArm.R”)

  hand_r = create_bone(armature, “Hand.R”, (-1.75, 0, 2.5), (-2, 0, 2.5), parent=”LowerArm.R”)

   

  # Legs

  upper_leg_l = create_bone(armature, “UpperLeg.L”, (0.3, 0, 1), (0.3, 0, 0.5), parent=”Root”)

  lower_leg_l = create_bone(armature, “LowerLeg.L”, (0.3, 0, 0.5), (0.3, 0, 0.1), parent=”UpperLeg.L”)

  foot_l = create_bone(armature, “Foot.L”, (0.3, 0, 0.1), (0.3, 0.3, 0), parent=”LowerLeg.L”)

   

  upper_leg_r = create_bone(armature, “UpperLeg.R”, (-0.3, 0, 1), (-0.3, 0, 0.5), parent=”Root”)

  lower_leg_r = create_bone(armature, “LowerLeg.R”, (-0.3, 0, 0.5), (-0.3, 0, 0.1), parent=”UpperLeg.R”)

  foot_r = create_bone(armature, “Foot.R”, (-0.3, 0, 0.1), (-0.3, 0.3, 0), parent=”LowerLeg.R”)

   

  object_mode()

  pose_mode()

   

  return armature

# Run the rig creation function

create_rig()

Leave a comment

Your email address will not be published. Required fields are marked *