Site Tools

Arraying Points on a Surface

Developer: RhinoScript
Summary: Demonstrates how to array points on a surface with a script.


I was wondering if there is a way to extract UV surface coordinates in Rhino. Specifically I'm trying to extract UVs of points on a surface and export it to a text file.


Yes. The following script will array points on a surface. When finished, simply export the selected points to a Points File (.txt).


Option Explicit
Sub ArrayPointsOnSurface()
   ' Get the surface object
   Dim srf : srf = Rhino.GetObject("Select surface", 8, vbTrue)
   If IsNull(srf) Then Exit Sub
   ' Get the number of rows
   Dim rows : rows = Rhino.GetInteger("Number of rows", 2, 2)
   If IsNull(rows) Then Exit Sub
   rows = rows - 1
   ' Get the number of columns
   Dim cols : cols = Rhino.GetInteger("Number of columns", 2, 2)
   If IsNull(cols) Then Exit Sub
   cols = cols - 1
   ' Get the domain of the surface
   Dim U : U = Rhino.SurfaceDomain(srf, 0)
   Dim V : V = Rhino.SurfaceDomain(srf, 1)
   If Not IsArray(U) Or Not IsArray(V) Then Exit Sub
   ' Turn off redrawing (faster)
   Rhino.EnableRedraw vbFalse
   ' Add the points
   Dim i, j, t(1), pt, obj
   For i = 0 To rows
     t(0) = U(0) + (((U(1) - U(0)) / rows) * i)
     For j = 0 To cols
       t(1) = V(0) + (((V(1) - V(0)) / cols) * j)
       pt = Rhino.EvaluateSurface(srf, t)
       If IsArray(pt) Then 
         obj = Rhino.AddPoint(pt) ' add the point
         Rhino.SelectObject obj   ' select the point
       End If
   ' Turn on redrawing
   Rhino.EnableRedraw vbTrue
End Sub


import rhinoscriptsyntax as rs
def ArrayPointsOnSurface():
    # Get the surface object
    srf = rs.GetObject("Select surface", rs.filter.surface, True)
    if not srf: return
    # Get the number of rows
    rows = rs.GetInteger("Number of rows", 2, 2)
    if not rows: return
    # Get the number of columns
    cols = rs.GetInteger("Number of columns", 2, 2)
    if not cols: return
    # Get the domain of the surface
    u, v = rs.SurfaceDomain(srf, 0), rs.SurfaceDomain(srf, 1)
    if not u or not v: return
    # Turn off redrawing (faster)
    # Add the points
    for i in range(rows):
        s = u[0] + ((u[1]-u[0])/(rows-1))*i
        for j in range(cols):
            t = v[0] + ((v[1]-v[0])/(cols-1))*j
            pt = rs.EvaluateSurface(srf, s, t)
            obj = rs.AddPoint(pt) # add the point
            rs.SelectObject(obj)  # select the point
    # Turn on redrawing
if __name__=="__main__":

developer/scriptsamples/arraypointsonsurface.txt ยท Last modified: 2015/09/15 by sandy