Need Help! Problem using Rhino Python to create dynamic grid of points


#1

Hi, I’m working on writing code that will make a rectangular grid of points and have them be manipulable and moveable relative to each other. What I’m envisioning is that there would be a number of “anchor points”(say 5 points along the perimeter of the grid) that when I move them, the rest of the grid points will move according to their distance from the anchor points. So, if I move an anchor point, the farther a grid point is from that anchor, the less it will move. I’ve started some lines of code to make the grid and how to move a point, but I have no idea how to tackle the rest. I imagine I would need to sort the collection of grid points by their distances from the anchor points, which would have to be excluded from that list (or would it be a dictionary?) And the function would work through the list of points and evaluate them with some expression (like 1/x) and create vectors to move them.
Can anybody help or offer advice?

My first attempts:

####creating a grid of points that responds to manipulating individual vertices
####an initial point is moved and the remaining points are subsequently affected

import rhinoscriptsyntax as rs
import math

#creates the grid of points
grid = []
origin = rs.GetPoint("Select the origin of the grid.")
origin = rs.AddPoint(origin)
x = range(0,8)
y = range(1,8)
for i in x:
    row = rs.CopyObject(origin, [i,0,0])
    for i in y:
        column = rs.CopyObject(row, [0,i,0])

#moves the initial point
def move_point():
    point = rs.GetObject("Select a point to move.", 1)
    new_point = rs.GetPoint("Select where to move the point.", point)
    rs.MoveObject(point, new_point - rs.PointCoordinates(point))

move_point()

(Dale Fugier) #2

Hi Carlos,

Something like this might be better prototypes in Grasshopper, as it has facilities to update objects based on the modification of a single object. You should have no problem creating a grid of points on a script. Its getting them to object based on the changes to one that might be somewhat challenging if you expect this to happen automatically (without user intervention).

  • Dale

#3

Thank you! I started trying to design it in Grasshopper now.