1
$\begingroup$

I am trying to scale a group of vertices. I changed the pivot point to 3D cursor. I placed the cursor on of the corners of the square. I want to scale the vertices about this corner. When done in GUI, using the shortcut s+x (to scale along x direction) and a factor of 0.3, I get the following desired result. enter image description here

When I try the same from a script, by placing the 3D cursor on the same corner and then do a bpy.ops.transform.resize(value=(0.3, 0.3, 0.3)) (or (0.3,0,0)), I get the result of what would have been if the cursor was at the centre (median) of the line as shown in the second figure.

enter image description here

Can someone tell why this difference?

$\endgroup$

1 Answer 1

4
$\begingroup$

It's a context issue and you need to Override the Context

The pivot point is a member of the 3D_VIEW space. In code below would be area.spaces.active.pivot_point Example of overriding the context which "fools" the operator into thinking it is being run from the 3D view, not the text editor.

import bpy
context = bpy.context
override = context.copy() # dictionary of context

for area in context.screen.areas:
    if area.type == 'VIEW_3D':
        override["area"] = area
        override["space_data"] = area.spaces.active
        override["region"] = area.regions[-1] # rule of thumb r.type == 'WINDOW'
        break

bpy.ops.transform.resize(override,
                         value=(0.3, 1, 1),
                         constraint_axis=(True, False, False))
$\endgroup$
0

You must log in to answer this question.

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