Skip to content

Instantly share code, notes, and snippets.

@zeffii
Created June 12, 2015 18:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zeffii/38b80cc0a3014caf616b to your computer and use it in GitHub Desktop.
Save zeffii/38b80cc0a3014caf616b to your computer and use it in GitHub Desktop.
import bpy
'''
this could will go along and record for every point the positions of the set of knot + handles,
and check against the previous set. If all match the previous set, the index is recorded and the
loop is broken, then in the segment us selected solo and segment removed. This operation can be
repeated automatically untill no seqential duplicates are found.
'''
import mathutils
from mathutils import Vector
def check_similarity(old_set, new_set, distance=0.0001):
if None in old_set:
return False
else:
for co_old, co_new in zip(old_set, new_set):
if (co_old-co_new).length < distance:
continue
else:
return False
# reaches here only if all old/new coordinates where closer than 'distance'.
return True
obj = bpy.context.active_object
splines = obj.data.splines
old_set = None, None, None
# A Curve data-type can hold multiple disjoint curves/splines
for idx, spline in enumerate(splines):
for cidx, bp in enumerate(spline.bezier_points):
new_set = (bp.co, bp.handle_left, bp.handle_right)
if check_similarity(old_set, new_set):
print(idx, cidx)
bp.select_control_point = True
else:
old_set = new_set
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment