2
$\begingroup$

My code is:

human_obj=bpy.data.objects["Armature"]

When I scale it with the command human_obj.scale=(1,1,1) the object remains at its original location. However, when I scale it with factors (1,2,1) or (2,1,1), the object will move to a new coordinate location based on the amount of scaling I've done in the x or y axis.

How can I scale the object so that it stays in the same location after scaling? It does not matter if I do this scaling in edit mode. When I return to object mode, it will jump to a new location for any scaling of x or y != 1

$\endgroup$

3 Answers 3

4
$\begingroup$

Your pivot center point is the only point that is unchanged when scaling. By default this pivot center point is the object origin. In order for your human object to not move, the center point must be either at the foot or at the barycenter of it (it depends on what you mean by "remain at its original location")

To do that you can use the 3d cursor as the pivot point and set its location to the point unchanged point (foot or barycenter)

bpy.context.area.spaces[1].pivot_point='CURSOR'
bpy.context.scene.cursor_location = pos #where pos is the unaltered point
$\endgroup$
1
  • $\begingroup$ AttributeError: 'SpaceTimeline' object has no attribute 'pivot_point' in Blender 2.79 $\endgroup$
    – user61607
    Commented Sep 26, 2019 at 13:21
3
$\begingroup$

You need to set the origin to the object center before apply scaling.

# Apply the transform
bpy.data.objects[obj_name].data.transform(mathutils.Matrix((
    (transform[0], transform[4], transform[8], transform[12]),
    (transform[1], transform[5], transform[9], transform[13]),
    (transform[2], transform[6], transform[10], transform[14]),
    (transform[3], transform[7], transform[11], transform[15]))))
bpy.data.objects[obj_name].data.update()
# Resize the object
bpy.ops.object.origin_set(type='ORIGIN_GEOMETRY')
bpy.data.objects[obj_name].scale = (scale, scale, scale)

Hope the above code helps!

Tested in Blender 2.79.

$\endgroup$
0
$\begingroup$

One possible explanation is that the original center of your mesh was changed. This happen when you move your mesh WHILE in edit mode. Try to use the command line with a simple cube to see if you have same issue.

$\endgroup$

You must log in to answer this question.

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