I try to generate Cables with the Blender Python API.
I got it mostly working but there is one detail I would like to change.
I randomised the vertices of a Nurbs Path with
bpy.ops.transform.vertex_random but the problem with that is that the vertices also get randomised in Z direction but I want them to be "flat" cables laying on the ground.
Has anyone a solution to this? Every kind of help is highly appreciated.
Thank you very much.
import bpy import math import random import bmesh #define number of Cables numberOfCables = 5 count = 0 #clean scene (delete all objects inside def clean_scene(): for things in bpy.data.objects: bpy.data.objects.remove(things) clean_scene() #bpy.ops.object.select_all(action='SELECT') #bpy.ops.object.delete(use_global=False, confirm=False) #Main Programm for i in range(numberOfCables): #define random values for location and size X = random.uniform(0,5) Y = random.uniform(0,5) randomRadius = random.randrange(15,50,5)/10000 #random thickness ranging from 3mm to 8mm randomLength = random.uniform(0.3,1) #random length ranging from 30cm to 1m randomSeed = random.uniform(0,10) #print(randomRadius) #create Nurbs_Path def create_Nurbs(): bpy.ops.curve.primitive_nurbs_path_add(radius = randomRadius, enter_editmode = True, location=(X,Y,1)) return bpy.context.object obj = create_Nurbs() #randomly place vertecies to have different "cables" bpy.ops.transform.vertex_random(offset=.5, uniform=5, normal=5, seed=randomSeed, wait_for_input=True) bpy.ops.object.editmode_toggle()