Hexagonal Grid on Surface [Python Scripting]

Hexagonal Grid on Surface Python Scripting

#Generate Hexagonal Grid on surface
#Jeremy Luebker 2013.04.08
#jluebker.wordpress.com (jeremy.luebker@gmail.com)

import rhinoscriptsyntax as rs

def SurfaceDomain(STRSRF):
    strSrf = STRSRF
    intU = 16
    intV = 30
    PtsMtx = {}
    PtsMtxEnd = {}

    #find surface domain
    UDomain = rs.SurfaceDomain(strSrf, 0)
    VDomain = rs.SurfaceDomain(strSrf, 1)

    #print (UDomain)
    #print (VDomain)

    #steps
    Ustep = (UDomain[1] - UDomain[0]) / intU
    Vstep = (VDomain[1] - VDomain[0]) / intV

    #print (Ustep, Vstep)

    #plot points
    for i in range(intU + 1):
        for j in range(intV + 1):

            #u = UDomain[0] + Ustep * i
            #v = VDomain[0] + Vstep * j

            if i>0 and j%2==0:

                pt1 = rs.EvaluateSurface(strSrf, (Ustep*i+Ustep/3), (Vstep*j))
                pt2 = rs.EvaluateSurface(strSrf, (Ustep*i+Ustep/6), (Vstep*j+Vstep))
                pt3 = rs.EvaluateSurface(strSrf, (Ustep*i-Ustep/6), (Vstep*j+Vstep))
                pt4 = rs.EvaluateSurface(strSrf, (Ustep*i-Ustep/3), (Vstep*j))
                pt5 = rs.EvaluateSurface(strSrf, (Ustep*i-Ustep/6), (Vstep*j-Vstep))
                pt6 = rs.EvaluateSurface(strSrf, (Ustep*i+Ustep/6), (Vstep*j-Vstep))
                PtsMtx[(i,j)] = [pt1,pt2,pt3,pt4,pt5,pt6,pt1]
                rs.AddPolyline(PtsMtx[(i,j)])

            elif i>0 and j>0:

                pt1 = rs.EvaluateSurface(strSrf, (Ustep*0.5+Ustep*i+Ustep/3), (Vstep*j))
                pt2 = rs.EvaluateSurface(strSrf, (Ustep*0.5+Ustep*i+Ustep/6), (Vstep*j+Vstep))
                pt3 = rs.EvaluateSurface(strSrf, (Ustep*0.5+Ustep*i-Ustep/6), (Vstep*j+Vstep))
                pt4 = rs.EvaluateSurface(strSrf, (Ustep*0.5+Ustep*i-Ustep/3), (Vstep*j))
                pt5 = rs.EvaluateSurface(strSrf, (Ustep*0.5+Ustep*i-Ustep/6), (Vstep*j-Vstep))
                pt6 = rs.EvaluateSurface(strSrf, (Ustep*0.5+Ustep*i+Ustep/6), (Vstep*j-Vstep))
                PtsMtx[(i,j)] = [pt1,pt2,pt3,pt4,pt5,pt6,pt1]
                rs.AddPolyline(PtsMtx[(i,j)])

    """
    for i in range(intU + 1):
        for j in range(intV + 1):

            if i>0 and j%2==0:
                point = rs.AddPoint(PtsMtx[(i,j)][4])
                rs.AddTextDot((i,j), point)
            elif i>0 and j>0:
                point = rs.AddPoint(PtsMtx[(i,j)][4])
                rs.AddTextDot((i,j), point)
            #print PtsMtx[(i,j)]
            """

def Main():

    #Select Surface
    strSrf = rs.GetObject('select surface', 8)

    rs.EnableRedraw(False)
    SurfaceDomain(strSrf)
    rs.EnableRedraw(True)

if __name__=="__main__":
    Main()
Advertisements

~ by jluebker on April 8, 2013.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: