strange results from scripted shape keys on a curve

running this script you can see the first few handles shoot off to infinity.
Also the handles do not appear in the shapekey.data list of beziers.


import bpy, random, sys
for o in bpy.data.objects: o.selected=False
bpy.context.scene.update()
scn = bpy.context.scene
data = bpy.data.curves.new(name='brain', type='CURVE')
for i in range(2):
	spline = data.splines.new('BEZIER')
	bez = spline.bezier_points[-1]
	bez.co.x = i * 0.4
	for j in range(3):
		x = i * 0.4; y = j * 0.1
		spline.bezier_points.add()
		bez = spline.bezier_points[-1]
		bez.co.x = x
		bez.co.y = y
		bez.handle1.x = i * 0.4 + random.uniform(-.1,.1)
		bez.handle1.y = j * 0.1 + random.uniform(-.1,.1)
		bez.handle2.x = i * 0.4 + random.uniform(-.1,.1)
		bez.handle2.y = j * 0.1 + random.uniform(-.1,.1)

		bez.selected_control_point = bez.selected_handle1 = bez.selected_handle2 = True

		# and 2 = Vector, what is bez.radius?

bpy.context.scene.update()

		
obj = bpy.data.objects.new(name='brain', object_data=data)
bpy.context.scene.objects.link(obj)
bpy.context.scene.objects.active = obj

print( dir(obj.data) )
print( obj.data.shape_keys )

bpy.ops.object.shape_key_add()

print( dir(obj.data.shape_keys) )
sk = obj.data.shape_keys
sk.relative = True
print ( dir(sk.keys) )
print ( sk.keys )

bias = sk.keys[0]
print ( dir(bias) )
print (bias.name, bias.relative_key)

print ( bias.data )

bpy.ops.object.shape_key_add()
bpy.context.scene.update()

## modify the first shape key data - strange results when then shape is viewed, handles go off into infinity
shape = sk.keys[-1]
for i,bez in enumerate( shape.data ):
	bbez = bias.data[ i ]
	#bez.co.x = 1.0
	#bez.co.y = .0
	#bez.co.z = .0
	print( bbez.co, bez.co )
	bez.co.x = -bbez.co.x
	bez.co.y = -bbez.co.y
	bez.co.z = -bbez.co.z


I tried it but it gives me an error @ line 5 saying " AttributeError: ‘bpy_prop_collection’ object has no attribute ‘new’ ". I may be doing something wrong, may be - NOT… :eek: but I wanna ask you if it is an old script translated for 2.5 or do you have a copy of this for 2.4x? Or similar - to creating/adding shape kays by Python ONLY ??? :spin:

Regards,

I think there’s an old coding bug in the curve-shapekeys
http://projects.blender.org/tracker/?func=detail&atid=498&aid=21498&group_id=9

Regards

@ciriaco - It tells me that ShapeKeys_Circle_bug.blend is made by 2.5 :frowning: Can you send a link to the script, if 2.49?

Regards,

@goathead
The first problem is in the last for. It’wrong