Thursday, August 27, 2009

Deforming a surface


import py2rhino as p2r

srf = p2r.obj.NurbsSurface("98599908-7024-4864-b9e9-a5cf20cd5804")
control_points = srf.prop.pnts()

cir = p2r.obj.Circle("25309c07-d705-4041-bd87-aba1389d79e6")
cen = cir.prop.center_pnt()

new_control_points = []
for cp in control_points:

#get the distance from the circle to the control point
vec = p2r.util.vector.create(cen, cp)
dist = p2r.util.vector.length(vec)

#move the control point and save it in the list
moved_point = (cp[0], cp[1], dist)
new_control_points.append(moved_point)

#print the points
for i in new_control_points:
print i

#create a new surface
dim = srf.prop.pnt_count()
p2r.obj.NurbsSurface.create_by_control_pnt_grid(dim, new_control_points, (1,5))

1 comment:

  1. I've got a error at line 7,
    what does for cp in control_points:
    TypeError: 'NoneType' object is not iterable
    mean???

    ReplyDelete