Wednesday, April 25, 2012

TESSELATE SURFACE TO RECTANGLES




#SCRIPT ABOUT TESSELATING SURFACE TO RECTANGLES###

import rhinoscriptsyntax as rs

from math import*
from System.Drawing import Color

def SampleSurface(StrSurf,IntUDivisions,IntVDivisions):
    ListUDomain = rs.SurfaceDomain(StrSurf,0)
    ListVDomain = rs.SurfaceDomain(StrSurf,1)
   
    FloatUStep = (ListUDomain[1]-ListUDomain[0])/IntUDivisions
    FloatVStep = (ListVDomain[1]-ListVDomain[0])/IntVDivisions
   
    PtsList=[]
   
    for i in rs.frange(ListUDomain[0],ListUDomain[1]+FloatUStep,FloatUStep):
        TempList = []
        for j in rs.frange(ListVDomain[0],ListVDomain[1]+FloatVStep,FloatVStep):
            TempList.append(rs.EvaluateSurface(StrSurf, i , j ))
        PtsList.append(TempList)
   
    rs.AddPoint(PtsList[0][0])
     #i need to know which element within my lists i want to get
   
    for i in range (0,len(PtsList)):
        for j in range(0,len(PtsList[i])):
            Pts = rs.AddPoint(PtsList[i][j])
            NewLay01 = rs.AddLayer("Points",Color.HotPink)
            Pts02Lay = rs.ObjectLayer(Pts,"Points")
    return PtsList


StrSurf = rs.GetObject("get surface",8)

IntUDivisions = 10
IntVDivisions = 20

ListOfPoints = SampleSurface(StrSurf,IntUDivisions,IntVDivisions)

for i in range(0,len(ListOfPoints)-1):
    for j in range(0,len(ListOfPoints[i])-1):
        Pt01 = ListOfPoints[i][j]
        Pt02 = ListOfPoints[i+1][j]
        Pt03 = ListOfPoints[i+1][j+1]
        Pt04 = ListOfPoints[i][j+1]
        Patch = rs.AddPolyline([Pt01,Pt02,Pt03,Pt04,Pt01])
        NewLay03 = rs.AddLayer("Polylines",Color.DarkTurquoise)
        PoLineLay = rs.ObjectLayer(Patch,"Polylines")

No comments:

Post a Comment