Scaling objects with data modification

I am fairly new to blender and am wondering how does one scale the objects in blender via python script.

Currently I am simply changing the scale of the object via bpy.data.objects[NAME].scale however, this is not what I want to do as it only visually shrink the object.

I also tried to change the length of each bone individually, however, even though the length of the bone changed, the head and tail of the bone did not change. Also something worth mentioning, I am working with a hand. This ended up giving me a hand with tiny bones but not connected due to the bone's head remaining the same.

I would like the bones in the armature object to actually shrink/grow as well, since I am exporting this object later as BVH and would like to preserve the scaling.

Thanks

• how are "the bones in the object" ? is the object an armature or a mesh parented to an armature ? – Chebhou Apr 20 '15 at 22:27
• its just an armature, no mesh involved. – jim Apr 20 '15 at 22:31
• loop through bones and scale one by one – Chebhou Apr 20 '15 at 22:33
• i know how to loop through the bones, but to scale the bone, what do you call? bpy.ops.transform.resize? – jim Apr 20 '15 at 22:36

this is simple script for scaling all bones in the active armature :

import bpy
ob = bpy.context.object
bpy.ops.object.mode_set(mode='POSE')

for bone in ob.pose.bones:
if not bone.parent : # since children inherit scale no need to scale them
bone.scale *=0.5

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


to remove scale inheritence :

for bone in ob.data.bones:
if bone.parent :
bone.use_inherit_scale = False

#scale all bones
bpy.ops.object.mode_set(mode='POSE')
for bone in ob.pose.bones:
bone.scale *=0.5
bpy.ops.object.mode_set(mode='OBJECT')


scaling in edit mode :

import mathutils
bpy.ops.object.mode_set(mode='EDIT')

mat = mathutils.Matrix.Scale(0.5, 3)

for bone in ob.data.edit_bones:
bone.transform(mat,  scale = True, roll = False)

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

• This changes the hand visually, but when i get an individual bone's length it's still the same as before without the scale. Am i doing something wrong? – jim Apr 20 '15 at 22:58
• the children bones are in the local space of there parent , so if the parent is scaled by half the world of the child is scaled by half , it's length is the same but visually it's half what it was – Chebhou Apr 20 '15 at 23:05
• if you want you can disable Inherit_scale in the bone tab and remove if not bone.parent to get what you want – Chebhou Apr 20 '15 at 23:07
• with this script, if I were to export the object as BVH is the scaling preserved? – jim Apr 20 '15 at 23:08
• sorry i have no experience with BVH exporting : ( , you can try the second method and export a simple armature – Chebhou Apr 20 '15 at 23:10