I am attempting to make cords using python in Blender 2.8
Currently, I have successfully made it work when using a normal bezier curve that I modify along with a circle I added. (see image below)
My issue on a spline that I add points to and combine into a curve seems to have an issue where it will not run the bevel-using-shape option unless it is run in separate code, or done by hand. (see images below)
I'll also include my code which shouldn't need any adjustments to test. The only issue is the last line that bevels.
Thanks in advance!
#Import python import bpy #Import vectors from mathutils import Vector #Import math allows access to things like pi import math as m #___________________________________COIL-SHAPED Start: This Script Allows a Coil-shaped spline #Create a circle spline/bezier circle | in the center ofthe world bpy.ops.curve.primitive_bezier_circle_add(radius=0.15, enter_editmode=False, location=(0, 0, 0)) #rename it for obj in bpy.context.selected_objects: obj.name = "Coil_Circle" obj.data.name = "Coil_Circle" # a list of coordinates for the vertices of the spline to follow coords_list = [[0,0,0], ] #This is how to reference a specific part of the list #coords_list = [0,0,0] #Variables for the coil shape to follow # n = how many to make n = 33 # r = the distance between each one | also can be considered how whide the coil will be r = 2 # the distance vertically from the ground z = 0 # for loop through n for i in range(1,n+1): #Add a new spot into our list coords_list.append([0,0,0]) #create an angle using pi that allows for rotation angle = ((i-1)*4*m.pi)/n #the x position change of the new point x = r*m.cos(angle) #the y position of the new point y = r*m.sin(angle) #the z position (vertical) z = 0.01*i #Assign the position to the list coords_list[i] = [x,y,z] # make a new curve crv = bpy.data.curves.new('crv', 'CURVE') crv.dimensions = '3D' # make a new spline in that curve spline = crv.splines.new(type='NURBS') # a spline point for each point spline.points.add(len(coords_list)-1) # theres already one point by default # assign the point coordinates to the spline points for p, new_co in zip(spline.points, coords_list): p.co = (new_co + [1.0]) # (add nurbs weight) # make a new object with the curve obj = bpy.data.objects.new('Coil_Delete', crv) # link the points to complete the spline curve bpy.context.scene.collection.objects.link(obj) # Deselect all bpy.ops.object.select_all(action='DESELECT') #Select the curve bpy.data.objects['Coil_Delete'].select_set(True) #rename it for obj in bpy.context.selected_objects: obj.name = "Coil_Curve" obj.data.name = "Coil_Curve" #____________________________________________________This line does not seem to work when combined with this code #select our circle as the geometry bevel object bpy.context.object.data.bevel_object = bpy.data.objects["Coil_Circle"] #Apply the modifier #Delete circle reference #___________________________________COIL-SHAPED END