enter image description here

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
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)
  • $\begingroup$ 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. $\endgroup$ – Matt Jun 24 '16 at 13:39
  • $\begingroup$ Oops.... "board" = "broad" $\endgroup$ – 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:
    v.co.xy += Vector([uniform(-delta, delta) for axis in "xy"])

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.

| improve this answer | |

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.