0
$\begingroup$

I'd appreciate any help with this simple script that I cannot get to work properly for Blender 2.8+

All I want to do is to take a selected NURBS path as input, and create a new NURBS path that is essentially identical to the input, except all of the vertices have been "rotated" around it, by a specific number of places. This is because I've got an open curve, but I want to control where the opening, the gap between the first and last vertices, is located along the curve.

The script basically works, the vertices are correctly rotated when the curve object is in edit mode. But when switched to object mode, all the vertices disappear.

Here is the script, and a link to the blend file. The example can be run by selecting the braids_curve object and running the script. It creates braids_curve_out, which will be invisible. Switching it to edit mode shows that the vertices correctly coincide.

Blend file

Appreciate any help determining what critical piece I am missing.

import bpy

# how much we want to rotate the vertices by, in vertex offsets
offset = 280

# use the selected NURBS path object as source
sourceObj = bpy.context.active_object
if sourceObj and sourceObj.type == 'CURVE':
    
    # create the new path and rename it, based on the source object
    bpy.ops.curve.primitive_nurbs_path_add()
    newObj = bpy.context.active_object
    newObj.name = sourceObj.name + "_out"
    
    # get the vertex count of the source object
    sourcePoints = sourceObj.data.splines[ 0 ].points
    sourceLength = len( sourcePoints )

    # make the new object's count the same as the source object's count
    newObjLength = len( newObj.data.splines[ 0 ].points )
    newObj.data.splines[ 0 ].points.add( sourceLength - newObjLength )

    # move around the source object    
    for index in range( sourceLength ):

        # calculate the index of the offset vertex        
        moduloIndex = ( index + offset ) % sourceLength
        
        # set the offset vertex
        newObj.data.splines[ 0 ].points[ index ].co = sourcePoints[ moduloIndex ].co

else:
    print ( 'no selected curve object' )
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.