2026-01-01
This commit is contained in:
@@ -0,0 +1,101 @@
|
||||
import bpy
|
||||
from mathutils import Vector
|
||||
|
||||
def create_settings_bone():
|
||||
"""
|
||||
Creates a new bone under the armature, parents it to the 'root' bone,
|
||||
and sets the bone colors to Theme Color Set 11.
|
||||
"""
|
||||
# Get the active object (should be an armature)
|
||||
armature_obj = bpy.context.active_object
|
||||
|
||||
if not armature_obj or armature_obj.type != 'ARMATURE':
|
||||
print("Error: Please select an armature object")
|
||||
return
|
||||
|
||||
# Enter Edit Mode
|
||||
bpy.context.view_layer.objects.active = armature_obj
|
||||
bpy.ops.object.mode_set(mode='EDIT')
|
||||
|
||||
armature = armature_obj.data
|
||||
|
||||
# Find the 'root' bone
|
||||
root_bone = None
|
||||
for bone in armature.edit_bones:
|
||||
if bone.name.lower() == 'root':
|
||||
root_bone = bone
|
||||
break
|
||||
|
||||
if not root_bone:
|
||||
print("Error: 'root' bone not found in armature")
|
||||
bpy.ops.object.mode_set(mode='OBJECT')
|
||||
return
|
||||
|
||||
# Find the root bone collection
|
||||
root_collection = None
|
||||
for collection in armature.collections:
|
||||
if collection.name.lower() == 'root':
|
||||
root_collection = collection
|
||||
break
|
||||
|
||||
# Create a new bone named 'Settings'
|
||||
new_bone = armature.edit_bones.new('Settings')
|
||||
|
||||
# Position the new bone at y = 0.5
|
||||
new_bone.head = Vector((0, 0.5, 0))
|
||||
new_bone.tail = Vector((0, 0.5, 0.5))
|
||||
|
||||
# Parent the new bone to the root bone
|
||||
new_bone.parent = root_bone
|
||||
|
||||
# Switch to Object Mode to add bone to collection
|
||||
bpy.ops.object.mode_set(mode='OBJECT')
|
||||
|
||||
# Add the new bone to the root collection
|
||||
if root_collection:
|
||||
# Get the bone data
|
||||
bone_data = armature.bones['Settings']
|
||||
# Add to root collection
|
||||
root_collection.assign(bone_data)
|
||||
print("Settings added to Root bone collection")
|
||||
|
||||
# Switch to Pose Mode to set bone colors
|
||||
bpy.ops.object.mode_set(mode='POSE')
|
||||
|
||||
# Get the pose bone
|
||||
pose_bone = armature_obj.pose.bones['Settings']
|
||||
|
||||
# Set bone color to Theme Color Set 11
|
||||
pose_bone.color.palette = 'THEME11'
|
||||
|
||||
# Set bone color custom (for viewport display)
|
||||
pose_bone.bone.color.palette = 'THEME11'
|
||||
|
||||
# Return to Object Mode
|
||||
bpy.ops.object.mode_set(mode='OBJECT')
|
||||
|
||||
# Go into Pose Mode and select Settings bone
|
||||
bpy.ops.object.mode_set(mode='POSE')
|
||||
|
||||
# Deselect all bones first
|
||||
bpy.ops.pose.select_all(action='DESELECT')
|
||||
|
||||
# Select the Settings bone
|
||||
pose_bone = armature_obj.pose.bones['Settings']
|
||||
pose_bone.bone.select = True
|
||||
armature_obj.data.bones.active = pose_bone.bone
|
||||
|
||||
# Create widget for the Settings bone
|
||||
bpy.ops.bonewidget.create_widget()
|
||||
|
||||
# Set the custom shape wire width to 1
|
||||
armature_obj.pose.bones['Settings'].custom_shape_wire_width = 1
|
||||
|
||||
# Return to Object Mode
|
||||
bpy.ops.object.mode_set(mode='OBJECT')
|
||||
|
||||
print("Settings created successfully and parented to root bone")
|
||||
print("Bone colors set to Theme Color Set 11")
|
||||
print("Widget created for Settings bone")
|
||||
|
||||
create_settings_bone()
|
||||
Reference in New Issue
Block a user