0
$\begingroup$

I would like to change the bone scale for a material. I want to change the specified bone to scale -1 for XYZ as shown in the video below.

I have drawn a script to try it out as shown below, but I can't figure out how to change it to a negative scale.

import bpy

rightbonelist= ['rightshoulder_bb_', 'rightarm_bb_', 'rightforearm_bb_', 'righthand_bb_', 'righthandmiddle1_bb_', 'righthandmiddle2_bb_', 'righthandmiddle3_bb_', 'righthandmiddle4_bb_', 'righthandindex1_bb_', 'righthandindex2_bb_', 'righthandindex3_bb_', 'righthandindex4_bb_', 'righthandring1_bb_', 'righthandring2_bb_', 'righthandring3_bb_', 'righthandring4_bb_', 'righthandpinky1_bb_', 'righthandpinky2_bb_', 'righthandpinky3_bb_', 'righthandpinky4_bb_', 'righthandthumb1_bb_', 'righthandthumb2_bb_', 'righthandthumb3_bb_', 'righthandthumb4_bb_', 'rightupleg_bb_', 'rightleg_bb_', 'rightfoot_bb_', 'righttoebase_bb_']
bpy.ops.object.mode_set(mode='EDIT')


mat = bpy.context.object.matrix_world
for bone in bpy.context.active_object.data.edit_bones:
    if bone.name in rightbonelist:
        tail = bone.tail @ mat *-1
        print(tail)
        head = bone.head @ mat *-1
        print(head)
        bone.tail = tail
        bone.head = head 

Does anyone know how?

enter image description here

$\endgroup$

1 Answer 1

0
$\begingroup$

Now that I know how to do it, I would like to answer my own question.

I needed to override the pivot point of the operator. (In this case, "bpy.context.scene.tool_settings.transform_pivot_point = 'INDIVIDUAL_ORIGINS' ")

Here is the script for the override and modification It only applies to bones named "right".

import bpy


def get_override(area_type, region_type):
    for area in bpy.context.screen.areas: 
        if area.type == area_type:             
            for region in area.regions:                 
                if region.type == region_type:                    
                    override = {'area': area, 'region': region} 
                    return override
    #error message if the area or region wasn't found
    raise RuntimeError("Wasn't able to find 's open while executing script.")


# Save pivot point
save_pivot_point = bpy.context.scene.tool_settings.transform_pivot_point

bpy.context.scene.tool_settings.transform_pivot_point = 'INDIVIDUAL_ORIGINS'
#we need to override the context of our operator    
override = get_override( 'VIEW_3D', 'WINDOW' )
 
lists=[i for i in bpy.context.object.data.edit_bones if "right" in i.name]

bpy.ops.armature.select_all(action='DESELECT')


for i in lists:
    i.select = True
    i.select_tail = True
    i.select_head = True


bpy.ops.transform.resize(override,value=(-1, -1, -1))

# Restore pivot point
bpy.context.scene.tool_settings.transform_pivot_point = save_pivot_point

enter image description here

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .