 # Rhinoscript: spread rectangle pattern along irregular surface

As you see in the image, I am trying to spread rectangles along an irregular surface that was formed by more than 4 curves (lines). The problem is I can spread rectangles in a small area and not through all the surface.
My script is:

``````# construct rectangle pattern on a floor 2D plan
# Nabil Mohareb
import rhinoscriptsyntax as rs

def startPattern(surface, pattU, pattV):
# dictionary of the points
ptMTX = {}
# get domain of the surface
udomain = rs.SurfaceDomain(surface,0)
vdomain = rs.SurfaceDomain(surface,1)
# calculate the steps ofr U (X) & V (Y), distance of the grid
stepU = (udomain  - udomain )/pattU
stepV = (vdomain  - vdomain )/pattV

#plot points on surface
for i in range (pattU+1):
for j in range (pattV+1):
#define u & v in terms of steps values, i, j
u = udomain + stepU*i
v = vdomain + stepV*j
# diviede the surface and draw points on surfaces
point = rs.EvaluateSurface (surface, u, v)
if rs.IsPointOnSurface(surface, point) != False:
# write the points in the dictionary
ptMTX [(i,j)] = point
#loop to create geometry
for i in range (6,12):    #(6,12) # this is the problem, what range should I use?
for j in range (6,12):# the numbers are just playing around, but I think this is the problem
if i>0 and j>0:
#add surface to the small rectangles
# find the center of the small rectangle and add point to it
center = rs.SurfaceAreaCentroid(smlSurf)

def main():
#select the plan lines
plane = rs.GetObjects('select curves please', rs.filter.curve)
pattU = rs.GetInteger('write U (x) value', 12)
pattV = rs.GetInteger('write V (y) value', 12)
#join the plan lines
planeJoined= rs.JoinCurves(plane)
#convert plane to surface

# call the function
startPattern(surface, pattU, pattV)

main ()
``````

Hello,

I think you need to use `pattU` and `pattV` for your range values.

If you put your curve and surface generating code inside a `try...except KeyError` block then it should only generate surfaces where the four corners are in your `ptMTX` dictionary.

Hope this helps - I have not tried it !

-Graham

Thank you Graham for your kind reply, I will try to use try…except keyError block and come back to you
best wishes