Forgot password?

Create an account!

Forum

« back

RhinoScript – Script to subdivide a surface

Messages

Please log in to write a message.

  • 1. hpnotiq (Jul 03, 2012 10.43):

    Hi All

    I am very new to programming and Rhinoscripting. I am trying to write a script/ code that divides a surface (square or rectangle) into a 3x3 grid. After which each piece will be unrolled and labelled horizontally in order. I am lost.. I really am. I am pasting what I have thus far here:

    # step 1 - select the surface
    # step 2 - get the domain values for the surface in U and V directions
    # step 3 - ask the user to enter the number of U and V divisions s/he wants
    # step 4 - those values they enter are now assigned to U and V
    # step 5 - divide that range of U and V values into smaller bits based on users input (u-step)
    # step 6 - draw curves using those smaller values dividing the surface
    # OR EXPLODE SURFACE BASED ON THESE UV DIVISIONS
    # step 7 - extract the lines from those smaller values
    # step 8 - unroll surfaces horizontally
    # step 9 - label


    import rhinoscriptsyntax as rs

    #STEP 1-
    surface = rs.GetObject("Select surface to unroll", 8)
    # I cannot put if not return here because it is not a function definition

    #STEP 2-
    uDomain = rs.SurfaceDomain(surface,0) # 0 for the U direction.
    # Returns the domain of a  surface object in the specified direction.

    vDomain = rs.SurfaceDomain(surface,1) # 1 for the V direction

    print "Domain in U direction: ", uDomain
    print "Domain in V direction: ", vDomain

    # rhinoscriptsyntax.GetReal ( message=None, number=None, minimum=None, maximum=None )

    #STEP 3 & 4
    u = rs.GetReal("Enter U value", 10) # Pauses for user input of a number.
    v = rs.GetReal("Enter V value", 20)

    #STEP 5A-
    uStep = (uDomain[1] - uDomain[0]) / u #max-min/no. entered
    vStep = (vDomain[1] - vDomain[0]) / v

    print type(uStep)
    print type(vStep)

    #STEP 5B-
    uFixed = int(uStep) # trying to convert float to integer
    vFixed = int(vStep)

    #uDomain = rs.SurfaceDomain(idSurface, 0) *** pg 59
    #vDomain = rs.SurfaceDomain(idSurface, 1)
    #uStep = (uDomain[1] - uDomain[0]) / intCount
    #vStep = (vDomain[1] - vDomain[0]) / intCount

    #STEP 5c- CREATE LISTS TO STORE VALUES
    U_values=[] # where we will store all U values
    V_values=[] # where we will store all V values

    rs.EnableRedraw(False)

    #begin a loop for each segment of the surface
    #for i in range (uDomain[0], uDomain[1], uFixed): #from: to: step (row loop of x domain)
    #    for j in range (vDomain[0], vDomain[1], vFixed): # column loop for the y domain
    #        pt = rs.EvaluateSurface (surface, [uFixed, vFixed]) #Evaluates a surface at a U,V parameter and returns a 3D point

    for i in range (uFixed):
        U = uDomain[0] + (i/Nv)*(uDomain[1] - uDomain[0])
        for j in range (vFixed):
            V = vDomain[0] + (j/Nv)*(vDomain[1] - vDomain[0])
            points[(i,j)] = rs.EvaluateSurface (surface, [uFixed, vFixed]) #gives UV coord of point -
            # to evaluate a point on a surface on specific parameter

    # surface closest point
    # Evaluate surface
    # surface normal

    #EXPLODE POLYSURFACE
    #Explodes, or un-joins,  one more polysurface objects.  
    #Polysurfaces will be exploded into separate surfaces.


    # UNROLL SURFACE
    # rhinoscriptsyntax.UnrollSurface (surface_id, explode=False, following_geometry=None)

    # rs.ExplodePolysurfaces( surface )

    #if surface: rs.UnrollSurface(surface, True)

    # rs.EnableRedraw (True)

Recommend

Why are these buttons gray?