Surface Subdivision in RhinoPython

Surface subdiviision

This generates a subdivision based on any 4-corner surface and names the panels. It also creates tabs, should you want to unroll it for fabrication. The panels are, in addition, named for reference.

#script written by Adolfo Nadal

#import rhinoscriptcontext 

import rhinoscriptsyntax as rss


#calculate the normal on the surface with a given scalefactor

def calcNormalWithSize(srf,uParam,vParam,size,ptBase):

    ptNorm = rss.SurfaceNormal(srf,(uParam,vParam))

    ptNorm = rss.VectorScale(ptNorm,size)

    ptNorm = rss.VectorAdd(ptNorm,ptBase)

    return ptNorm


#get surface from user: filter 8 for surfaces

srf = rss.GetObject("Please select a surface",8)


#get a series of subdivisions

divU = rss.GetInteger("Please enter number of subdivisions in U direction",5,2,100)

divV = rss.GetInteger("Please enter number of subdivisions in V direction",5,2,100)


#enter your desired tab size

tabSize = rss.GetReal("Please enter tab size",2,0.1,10)


#populate the surface with points

#-surface domain

domU = rss.SurfaceDomain(srf,0)

domV = rss.SurfaceDomain(srf,1)


print (domU)

print (domV)


#enter variables that contain surface domain

#max will be the second value, therefore [1]

domUMax = domU[1]

domUMin = domU[0]

domVMax = domV[1]

domVMin = domV[0]


#calculate the stepSize

stepU = (domUMax-domUMin)/divU

stepV = (domVMax-domVMin)/divV




counter = 0

#create points on surface

for i in range(divU+1):

    for j in range(divV+1):


            #-evaluate surface

            uParam = i*stepU

            vParam = j*stepV

            pt1Coord = rss.EvaluateSurface(srf,uParam,vParam)

            pt2Coord = rss.EvaluateSurface(srf,uParam-stepU,vParam)

            pt3Coord = rss.EvaluateSurface(srf,uParam-stepU,vParam-stepV)

            pt4Coord = rss.EvaluateSurface(srf,uParam,vParam-stepV)


            #obtain middle points

            ptMid12Coord = rss.EvaluateSurface(srf,uParam-stepU/2,vParam)

            ptMid23Coord = rss.EvaluateSurface(srf,uParam-stepU,vParam-stepV/2)

            ptMid34Coord = rss.EvaluateSurface(srf,uParam-stepU/2,vParam-stepV)

            ptMid41Coord = rss.EvaluateSurface(srf,uParam,vParam-stepV/2)


            #add the point on the surface

            #pt = rss.AddPoint(ptCoord)

            #add components to the surface

            polyPt = (pt1Coord,pt2Coord,pt3Coord,pt4Coord,pt1Coord)

            #poly = rss.AddPolyline(polyPt)


            #Add segments ON the surface

            crv1 = rss.AddInterpCrvOnSrf(srf,(pt1Coord,pt2Coord))

            crv2 = rss.AddInterpCrvOnSrf(srf,(pt2Coord,pt3Coord))

            crv3 = rss.AddInterpCrvOnSrf(srf,(pt3Coord,pt4Coord))

            crv4 = rss.AddInterpCrvOnSrf(srf,(pt4Coord,pt1Coord))


            #join curve segments into one and delete segments (true)

            crvs = (crv1,crv2,crv3,crv4)

            joinCrv = rss.JoinCurves(crvs,True)


            #calculate normals!!!

            #beware, vectors in rhino are by default 0-based (0,0,0)

            #1st calculate normal

            #2nd scale (if desired)

            #3rd move (by adding)

            ptN1Coord = calcNormalWithSize(srf,uParam,vParam,tabSize,pt1Coord)

            ptMidN12Coord = calcNormalWithSize(srf,uParam-stepU/2,vParam,tabSize,ptMid12Coord)

            ptMidN23Coord = calcNormalWithSize(srf,uParam-stepU,vParam-stepV/2,tabSize,ptMid23Coord)

            ptMidN34Coord = calcNormalWithSize(srf,uParam-stepU/2,vParam-stepV,tabSize,ptMid34Coord)

            ptMidN41Coord = calcNormalWithSize(srf,uParam,vParam-stepV/2,tabSize,ptMid41Coord)


            #verify that it works





            #visualize normal


            #add tabs to the model

            triaTab1Pts = (pt1Coord,pt2Coord,ptMidN12Coord)

            triaTab2Pts = (pt2Coord,pt3Coord,ptMidN23Coord)

            triaTab3Pts = (pt3Coord,pt4Coord,ptMidN34Coord)

            triaTab4Pts = (pt4Coord,pt1Coord,ptMidN41Coord)


            tab1Srf = rss.AddSrfPt(triaTab1Pts)

            tab2Srf = rss.AddSrfPt(triaTab2Pts)

            tab3Srf = rss.AddSrfPt(triaTab3Pts)

            tab4Srf = rss.AddSrfPt(triaTab4Pts)


            basePts = (pt1Coord,pt2Coord,pt3Coord,pt4Coord)

            baseSrf = rss.AddSrfPt(basePts)


            #join to create a single polysurface object

            srfs = (tab1Srf,tab2Srf,tab3Srf,tab4Srf,baseSrf)

            basePolySrf = rss.JoinSurfaces(srfs,True)




            ptCtCoord = rss.EvaluateSurface(srf,uParam-stepU/2,vParam-stepV/2)


            counter = counter +1


            #create panels



Search Site

archi·o·logics survey

I am interested in: