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$
4
  • $\begingroup$ how are "the bones in the object" ? is the object an armature or a mesh parented to an armature ? $\endgroup$ Commented Apr 20, 2015 at 22:27
  • $\begingroup$ its just an armature, no mesh involved. $\endgroup$ Commented Apr 20, 2015 at 22:31
  • $\begingroup$ loop through bones and scale one by one $\endgroup$ Commented Apr 20, 2015 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$ Commented Apr 20, 2015 at 22:36

2 Answers 2

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$
18
  • $\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$ Commented Apr 20, 2015 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$ Commented Apr 20, 2015 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$ Commented Apr 20, 2015 at 23:07
  • $\begingroup$ with this script, if I were to export the object as BVH is the scaling preserved? $\endgroup$ Commented Apr 20, 2015 at 23:08
  • $\begingroup$ sorry i have no experience with BVH exporting : ( , you can try the second method and export a simple armature $\endgroup$ Commented Apr 20, 2015 at 23:10
0
$\begingroup$

For BVH export using the Python API, there is a global_scale parameter that you can apply with some scaling factor to the export function. See API doc.

$\endgroup$

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.