0
$\begingroup$

How to prevent bevel shape rotation in extrusion operations?

I would like the final shape to remain "parallel" to the XY plane.

At the end of the extrusion (Due to the change of Z along the path) my profile shape has rotated: enter image description here

Here is my code

def create_rectangular_curve(objname, lenX, lenY):
    # create the Curve and the spline
    ratioY=lenY/lenX
    mycurve = bpy.data.curves.new(objname, type='CURVE')
    mycurve.dimensions = '2D'
    spline = mycurve.splines.new(type='POLY')
    #add points to the spline
    spline.points.add(4)
    spline.points[0].co=(-lenX/2,-lenY/2,0,1)
    spline.points[1].co=(lenX/2,-lenY/2,0,1)
    spline.points[2].co=(lenX/2,lenY/2,0,1)
    spline.points[3].co=(-lenX/2,lenY/2,0,1)
    spline.points[4].co=(-lenX/2,-lenY/2,0,1)    
    #create Object
    myobject = bpy.data.objects.new(objname, mycurve)
    bpy.context.scene.collection.objects.link(myobject)
    return myobject

def create_saw_curve(objname, nbPeriode, sizeX, sizeY):
    # create the curve and the spline
    ratioY=sizeY/sizeX
    mycurve = bpy.data.curves.new(objname, type='CURVE')
    mycurve.dimensions = '3D'
    spline = mycurve.splines.new(type='BEZIER')
    #add points to the spline
    spline.bezier_points.add(nbPeriode*4)
    #the first one
    spline.bezier_points[0].co=(0,0,-1)
    spline.bezier_points[0].handle_left =(-1,-ratioY,-1)
    spline.bezier_points[0].handle_right =(1,ratioY,-1)
    #the others points
    for i in range(1, nbPeriode*4,4):
        spline.bezier_points[i].co=(i*sizeX,sizeY,0)
        spline.bezier_points[i].handle_left =(i*sizeX-1,sizeY-ratioY,0)
        spline.bezier_points[i].handle_right =(i*sizeX+1,sizeY-ratioY,0)
        spline.bezier_points[i+1].co=((i+1)*sizeX,0,1)
        spline.bezier_points[i+1].handle_left =((i+1)*sizeX-1,ratioY,1)
        spline.bezier_points[i+1].handle_right =((i+1)*sizeX+1,-ratioY,1)
        spline.bezier_points[i+2].co=((i+2)*sizeX,-sizeY,0)
        spline.bezier_points[i+2].handle_left =((i+2)*sizeX-1,-sizeY+ratioY,0)
        spline.bezier_points[i+2].handle_right =((i+2)*sizeX+1,-sizeY+ratioY,0)
        spline.bezier_points[i+3].co=((i+3)*sizeX,0,-1)
        spline.bezier_points[i+3].handle_left =((i+3)*sizeX-1,-ratioY,-1)
        spline.bezier_points[i+3].handle_right =((i+3)*sizeX+1,ratioY,-1)
    #create Object
    myobject = bpy.data.objects.new(objname, mycurve)
    bpy.context.scene.collection.objects.link(myobject)
    return myobject

profileObject = create_rectangular_curve("profil", 4, 2)
curveObject = create_saw_curve('saw_curve',2,10,20)
curveObject.data.bevel_object = profileObject
curveObject.data.use_fill_caps = True 
curveObject.data.bevel_mode = 'OBJECT'
$\endgroup$
3
  • 2
    $\begingroup$ Hello, I 'm sure this a duplicate : use curveObject.data.twist_mode = 'Z_UP' $\endgroup$
    – Gorgious
    May 27, 2021 at 22:03
  • $\begingroup$ Thanks Gorious, it's working, that is what i wanted !! What sould i do to closed the question ? $\endgroup$
    – Goulven
    May 28, 2021 at 10:36
  • $\begingroup$ You can keep the question up, it might help other people :) $\endgroup$
    – Gorgious
    May 28, 2021 at 11:57

0

Browse other questions tagged .