1
$\begingroup$

I need to modify an object (for example rotate it) in edit mode, thanks to a script:

from math import pi
import bpy

obj = bpy.data.objects['my_object']
# go into edit mode
bpy.context.scene.objects.active = obj
bpy.ops.object.mode_set(mode='EDIT', toggle=False)

bpy.ops.transform.rotate(value=pi/2, axis=(False, False, True))

bpy.ops.object.mode_set(mode='OBJECT', toggle=False)

but no rotation is done. If I comment out :

# go into edit mode
#bpy.context.scene.objects.active = obj
#bpy.ops.object.mode_set(mode='EDIT', toggle=False)

bpy.ops.transform.rotate(value=pi/2, axis=(False, False, True))

#bpy.ops.object.mode_set(mode='OBJECT', toggle=False)

it's working but I want a modified object in edit mode, not in object mode.

(like you do in toggling "tab", pressing "r" than the axis you want and rotate the object).

$\endgroup$

1 Answer 1

2
$\begingroup$

Okay, I forgot to select all the mesh after toggling to edit mode:

it's working now:

from math import pi
import bpy

obj = bpy.data.objects['my_obj']
# go into edit mode
bpy.context.scene.objects.active = obj
bpy.ops.object.mode_set(mode='EDIT', toggle=False)
bpy.ops.mesh.select_all(action='SELECT')
bpy.ops.transform.rotate(value=pi/2, axis=(False, False, True))
bpy.ops.object.mode_set(mode='OBJECT', toggle=False)
$\endgroup$
1
  • $\begingroup$ +1 for posting an answer to your own question - good SE practice once in a while :-) $\endgroup$
    – uhoh
    Commented Aug 29, 2017 at 9:55

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