Grasshopper

algorithmic modeling for Rhino

import math
import rhinoscriptsyntax as rs


pts=rs.GetObjects('pickpoints',1)
for i in range(len(pts)):
     i[0]=0.5
     print(i)
      

pts is points i choose.i wanna the first number in "i",becoming 0.5,but it fails,i dont know the reason..

Views: 271

Replies to This Discussion

Hi Carcassi,

"i" is going to be 0, 1, 2, .. len(pts).  You have an array of points "pts". So pts[0] will be the id of the first point and so on.  Now I assume you would like to reset the "x" value of each point to be 0.5.

Here is how you can rewrite your code sample

import math
import rhinoscriptsyntax as rs

pts_ids = rs.GetObjects('pick points',rs.filter.point)
for i in range(len(pts_ids)):
  point = rs.PointCoordinates(pts_ids[i])
  if point:
    print point
    point[0] = 0.5
    print point


#another way to write the loop:
for id in pts_ids:
  point = rs.PointCoordinates(id)
  if point:
    print point
    point[0] = 0.5
    print point

I hope this helps

i remember U r the mcneel egineer?

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service