2
$\begingroup$

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

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

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')
$\endgroup$
  • $\begingroup$ 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? $\endgroup$ – jim Apr 20 '15 at 22:58
  • $\begingroup$ 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 $\endgroup$ – Chebhou Apr 20 '15 at 23:05
  • $\begingroup$ if you want you can disable Inherit_scale in the bone tab and remove if not bone.parent to get what you want $\endgroup$ – Chebhou Apr 20 '15 at 23:07
  • $\begingroup$ with this script, if I were to export the object as BVH is the scaling preserved? $\endgroup$ – jim Apr 20 '15 at 23:08
  • $\begingroup$ sorry i have no experience with BVH exporting : ( , you can try the second method and export a simple armature $\endgroup$ – Chebhou Apr 20 '15 at 23:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.