How to bpy.ops.transform.resize in edit mode using pivot?

Hello:

On object mode, with the pivot center selected at the cursor, the object scales correctly, moving toward the cursor as reduced.

bpy.ops.transform.resize(value=(0.95, 0.95, 0.95))

In edit mode, it always is reduced against the median point of the selected faces even with the pivot at the cursor. How can I make it to behave like in object mode?

I need to use Edit mode because I just want to resize an extruded part of the object.

Thanks in advance for any help.

The context override seems to work, applying the principles found here by Garrett:

you can get a resize from the pivot point in edit mode following:

  1. Set active Viewport’s pivot to 3d cursor
  2. Set up a context override function (copied from the link above, thanks!)
import bpy


def get_override(area_type, region_type):
    for area in bpy.context.screen.areas: 
        if area.type == area_type:             
            for region in area.regions:                 
                if region.type == region_type:                    
                    override = {'area': area, 'region': region} 
                    return override
    #error message if the area or region wasn't found
    raise RuntimeError("Wasn't able to find", region_type," in area ", area_type,
                        "
 Make sure it's open while executing script.")

#we need to override the context of our operator    
override = get_override( 'VIEW_3D', 'WINDOW' )


3.When applying transforms pass the override context as the first parameter

bpy.ops.transform.resize(override,value=(0.95, 0.95, 0.95))

Hope that helps!

1 Like

Hope I don’t break any rules by necrobumping, but just wanted to thank you for this Shiprex! Been struggling with it for hours and your snippet solved all of my problems. Happy holidays!