I manually deleted an object from outliner but my python code still finds that object. Is this because we need to somehow "update" or "synch" the blender's display component with its actual data base?
Thanks!
My python code use bpy.data.curves[0].splines[0] to find the object (a bezier curve). I deleted the first BezierCurve from outliner then added a new BezierCurve object. Then I ran the code through the built-in scripting window. That is when I noticed the operation occurred on the originally deleted BezierCurve.
import mathutils
import bpy
# by zeffi
# https://github.com/zeffii/rawr/blob/master/blender/scripts/addons_contrib/curve_normalize_spline.py
def get_points(spline, clean=True):
knots = spline.bezier_points
if len(knots) < 2:
return
# verts per segment
r = spline.resolution_u + 1
# segments in spline
segments = len(knots)
print("segments = %d"%segments)
if not spline.use_cyclic_u:
segments -= 1
master_point_list = []
for i in range(segments):
inext = (i + 1) % len(knots)
knot1 = knots[i].co
handle1 = knots[i].handle_right
handle2 = knots[inext].handle_left
knot2 = knots[inext].co
bezier = knot1, handle1, handle2, knot2, r
points = mathutils.geometry.interpolate_bezier(*bezier)
master_point_list.extend(points)
# some clean up to remove consecutive doubles, this could be smarter...
if clean:
old = master_point_list
good = [v for i, v in enumerate(old[:-1]) if not old[i] == old[i+1]]
good.append(old[-1])
return good
return master_point_list
spline = bpy.data.curves[0].splines[0]
points = get_points(spline)
for i in points:
bpy.ops.mesh.primitive_uv_sphere_add(size=0.05,location=i)
__python code__?, ¿are you usingbpyorbge? i asumme is bpy but, ¿where in your__python code__finds__that object__? ¿when your__python code__run? – Strapicarus Oct 30 '17 at 01:07bpy.data.collections may or may not be linked to any object or to any scene in the file. Referencing them by index IMO is never a good idea. Suggest usingspline = context.object.data.splines[0]ie select the curve object as context and run script. – batFINGER Oct 30 '17 at 16:00