# Deform a mesh object in a random manner in Blender using Python

I want to convert simple plane (left) into randomly deform plane (right) using python scripting. The intented deformation should be in x,y dimension. Anybody has idea, I am newbei in blender-python.

myobj = bpy.context.active_object
bpy.ops.object.mode_set(mode='EDIT')
selected_vertices = [i.co for i in myobj.data.vertices if i.select]

for i in selected_vertices:
bpy.ops.transform.translate(value = i*random.uniform(-1,1), constraint_axis=(True, True, False), constraint_orientation='GLOBAL', mirror=False, proportional='DISABLED', proportional_edit_falloff='SMOOTH', proportional_size=1, release_confirm=True)

• This is a very board question. Keep in mind that this is not a forum. We need specific, clear questions if we are to give useful answers. We can't teach you Python, or Blender. But we can help! Please describe what you've tried, what hasn't worked, and exactly what's going wrong. – Matt Jun 24 '16 at 13:39
• Oops.... "board" = "broad" – Matt Jun 24 '16 at 14:04

Using bmesh on an edit mesh (run in edit mode)

import bpy
import bmesh
from mathutils import Vector
from random import uniform
context = bpy.context
obj = context.edit_object
mesh = obj.data
delta = 0.2
# get a bmesh
bm = bmesh.from_edit_mesh(mesh)
for v in bm.verts:
if not v.select:
continue
v.co.xy += Vector([uniform(-delta, delta) for axis in "xy"])
#update.
bmesh.update_edit_mesh(mesh)


bpy.ops.transform.translate will translate all selected vertices. Using it in the loop as you had it, if all verts are selected would move all verts a random amount for each vert. (or nowhere for any vert with a 0 coordinate) You would need to copy the selection, deselect all, select them individually transform the single vert, deselect etc. Also remember scalar vector multiplication needs to be scalar * vector.