I'm trying to generate random rock shapes and then export the objects as .obj. If I enter what's in the following script one line at a time in the console all the objects come out looking different, but when running the script with the loop I end up several that are exact copies.
import bpy
import os
from random import randrange, uniform
mat = bpy.data.materials['Material']
bpy.data.materials["Material"].node_tree.nodes["Principled BSDF"].inputs[0].default_value = (0.02, 0.02, 0.02, 1)
for x in range(5):
frand = uniform(1,3)
# Generate synthetic shape
bpy.ops.mesh.add_mesh_rock(preset_values='1', scale_X=(0.5, 1.25), skew_X=-0.5, scale_Y=(0.5, 1.25), skew_Y=-0.5, scale_Z=(0.5, 1.25), skew_Z=-0.5, use_scale_dis=False, scale_fac=(1, 1, 1), deform=frand, rough=2, detail=3, display_detail=3, smooth_fac=2, smooth_it=2, use_generate=True, use_random_seed=True, user_seed=1)
# Add material
obj = bpy.context.active_object
obj.data.materials.append(mat)
# Filepath for OBJ
blend_file_path = bpy.data.filepath
directory = os.path.dirname(blend_file_path)
target_file = os.path.join(directory, 'GeneratedShapes/myfile%s.obj' % x)
# Export as OBJ
bpy.ops.export_scene.obj(filepath=target_file)
# Delete object
bpy.ops.object.delete(use_global=False)