3
$\begingroup$

How do I scale or rotate the selected verts of a mesh using blender python?

$\endgroup$
7
$\begingroup$

Relevant sections of the api documentation:


# See Text Editor -> Templates -> Python -> Simple Bmesh Editmode
# This example assumes we have a mesh object in edit-mode

import bpy
import bmesh
import math
import mathutils

# Get the active mesh
obj = bpy.context.edit_object
me = obj.data


# Get a BMesh representation
bm = bmesh.from_edit_mesh(me)
face = bm.faces.active


# Modify the BMesh, can do anything here...

# Rotate - (global)
center = bpy.context.scene.cursor_location
rot = mathutils.Euler((math.radians(45), 0.0, 0.0)).to_matrix()
bmesh.ops.rotate(
            bm,
            cent=bpy.context.scene.cursor_location,
            matrix=rot,
            verts=face.verts,
            space=obj.matrix_world
            )

# Scale - (local) - no space matrix passed
scale = mathutils.Vector((2.0, 1.0, 1.0))
bmesh.ops.scale(
            bm,
            vec=scale,
            verts=face.verts
            )

# Show the updates in the viewport
# and recalculate n-gon tessellation.
bmesh.update_edit_mesh(me, True)
$\endgroup$
  • $\begingroup$ Do you have any idea how I can rotate the selected face along his local axis and not around the cursor? $\endgroup$ – Bert VdB Jul 19 '14 at 21:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.