import bpy
import random
class RandomRotate(bpy.types.Operator):
"""RandomRotate"""
bl_idname = "object.random_rotate"
bl_label = "Random Rotate"
bl_options = {'REGISTER','UNDO'}
i = bpy.props.IntProperty(
name="iterations",
description="iterations of randomness",
default=10,
)
amount = bpy.props.FloatProperty(
name="Amount",
description="Amount",
default=1,
)
@classmethod
def poll(cls, context):
return context.active_object is not None and context.mode == 'EDIT_MESH'
def execute(self, context):
bpy.ops.object.vertex_group_add()
bpy.ops.object.vertex_group_assign()
a=5
for i in range(1, self.i+1):
bpy.ops.mesh.select_random(seed=i, action='DESELECT')
bpy.ops.transform.rotate(value=self.amount, axis=((0.5-random.random())*self.amount, (0.5-random.random())*self.amount, (0.5-random.random())*self.amount), constraint_orientation='NORMAL')
bpy.ops.object.vertex_group_select()
bpy.ops.object.vertex_group_remove(all=False)
return {'FINISHED'}
def register():
bpy.utils.register_class(RandomRotate)
def unregister():
bpy.utils.unregister_class(RandomRotate)
if __name__ == "__main__":
register()
The thing is it needs to run from 3d viewport to get the the rotation pivot setting from it’s context so it needs to be an operator. If you type Random Rotate into space bar menu in edit mode after running the script you will have an operator that will rotate the selected faces randomly. The controls for x y and z rotation are not working as I expected, but I don’t have time to look into it at the moment, you can control the amount from the f6 menu or the history panel or whatever it’s correct name is…
Edit: OK, its a silly mistake, controls of separate x,y and z rotation will not work unless I loop through all the selected faces, but I do not know a simple way of doing it without Bmesh so I hope this is going to be enough. I am correcting it to only have amount control.