Example #1
0
def create_quad_mesh(srf,u_div,v_div):
    
  
    
    u_domain = rs.SurfaceDomain(srf, 0)
    v_domain = rs.SurfaceDomain(srf, 1)
    u = (u_domain[1] - u_domain[0]) / (u_div - 1)
    v = (v_domain[1] - v_domain[0]) / (v_div - 1)
    
    #pts =  [[None for i in range(v_div)] for j in range(u_div)]
    mesh_pts = []
    for i in xrange(u_div):
        for j in xrange(v_div):
            #pts[i][j] = rs.EvaluateSurface (srf, u_domain[0] + u * i, v_domain[0] + v * j)
            mesh_pts.append(rs.EvaluateSurface (srf, u_domain[0] + u * i, v_domain[0] + v * j))
            
    faces = []        
    for i in xrange(u_div-1):
         for j in xrange(v_div-1):       
             faces.append(((i*v_div)+j,((i+1)*v_div)+j,((i+1)*v_div)+j+1,(i*v_div)+j+1))

    mesh = Mesh()
    
    for i,pt in enumerate(mesh_pts):
        mesh.add_vertex(str(i),{'x' : pt[0], 'y' : pt[1], 'z' : pt[2]})
    
    for face in faces:
        mesh.add_face(face)  
    
    return mesh        
Example #2
0
def RandomPtOnSrf(srf):
    if srf is None:
        print "Not a surface"
        return

    dom_u = rs.SurfaceDomain(srf, 0)
    dom_v = rs.SurfaceDomain(srf, 1)

    counter = 0
    while True:
        pt_u = random.uniform(dom_u[0], dom_u[1])
        pt_v = random.uniform(dom_v[0], dom_v[1])
        pt = rs.EvaluateSurface(srf, pt_u, pt_v)

        if type(srf
                ) == rc.DocObjects.ObjectType.Extrusion:  #If extrusion objects
            temp = rs.coercesurface(srf)
            testSrf = temp.ToBrep()
        else:
            testSrf = srf
        testPt = testSrf.ClosestPoint(pt)
        d = rs.Distance(testPt, pt)
        if d > rs.UnitAbsoluteTolerance():
            return pt
        else:
            counter += 1
Example #3
0
def ArrayPointsOnSurface():
    # Get the surface object
    surface_id = rs.GetObject("Select surface", rs.filter.surface)
    if surface_id is None: return

    # Get the number of rows
    rows = rs.GetInteger("Number of rows", 2, 2)
    if rows is None: return

    # Get the number of columns
    columns = rs.GetInteger("Number of columns", 2, 2)
    if columns is None: return

    # Get the number of columns
    hairlength = rs.GetInteger("Length of Hair", 2, 2)
    if hairlength is None: return

    # Get the domain of the surface
    U = rs.SurfaceDomain(surface_id, 0)
    V = rs.SurfaceDomain(surface_id, 1)
    if U is None or V is None: return

    # Add the points
    for i in xrange(0, rows):
        param0 = U[0] + (((U[1] - U[0]) / (rows - 1)) * i)
        for j in xrange(0, columns):
            param1 = V[0] + (((V[1] - V[0]) / (columns - 1)) * j)
            point = rs.EvaluateSurface(surface_id, param0, param1)
            rs.AddPoint(point)
            arrNormal = rs.SurfaceNormal(surface_id, point)
            rs.AddLine(point, point - arrNormal * hairlength)
def ArrayPointsOnSurface(srf):
    ptList = []

    # Get the number of rows
    rows = 51

    # Get the number of columns
    cols = 51

    # Get the domain of the surface
    u, v = rs.SurfaceDomain(srf, 0), rs.SurfaceDomain(srf, 1)

    # Turn off redrawing (faster)
    rs.EnableRedraw(False)

    # 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
            ptList.append(obj)

    return ptList

    # Turn on redrawing
    rs.EnableRedraw(True)
Example #5
0
def uv_points_from_surface(srf, u_div, v_div):
    """Creates a nested uv point list from a surface.

    Parameters
    ----------
    srf : System.Guid
        The surface identifier.
    u_div : int
        Number of poinst in u direction
    v_div : int
        Number of poinst in v direction

    Returns
    -------
    list[list[:rhino:`Rhino.Geometry.Point3d`]]
        Points for every uv division.

    """
    u_domain = rs.SurfaceDomain(srf, 0)
    v_domain = rs.SurfaceDomain(srf, 1)
    u_step = (u_domain[1] - u_domain[0]) / (u_div - 1)
    v_step = (v_domain[1] - v_domain[0]) / (v_div - 1)

    uv_points = [[None for _ in range(v_div)] for _ in range(u_div)]

    for u in range(u_div):
        for v in range(v_div):
            uv = (u_domain[0] + u_step * u, v_domain[0] + v_step * v)
            uv_points[u][v] = rs.EvaluateSurface(srf, uv[0], uv[1])

    return uv_points
Example #6
0
def uv_points_from_surface(srf, u_div, v_div):
    """Creates a nested uv point list from a surface.

    Parameters
    ----------
    srf : Rhino surface
        The object identifier
    u_div : int
        Number of poinst in u direction
    v_div : int
        Number of poinst in v direction

    Returns
    -------
    2D array (nested list)
        Points for every uv division.

    """
    u_domain = rs.SurfaceDomain(srf, 0)
    v_domain = rs.SurfaceDomain(srf, 1)
    u_step = (u_domain[1] - u_domain[0]) / (u_div - 1)
    v_step = (v_domain[1] - v_domain[0]) / (v_div - 1)

    uv_points = [[None for _ in range(v_div)] for _ in range(u_div)]

    for u in range(u_div):
        for v in range(v_div):
            uv = (u_domain[0] + u_step * u, v_domain[0] + v_step * v)
            uv_points[u][v] = rs.EvaluateSurface(srf, uv[0], uv[1])

    return uv_points
    def distance(self):

        Udomain = rs.SurfaceDomain(self.strsrf, 0)
        Vdomain = rs.SurfaceDomain(self.strsrf, 1)

        stepU = (Udomain[1] - Udomain[0]) / self.intu
        stepV = (Vdomain[1] - Vdomain[0]) / self.intv

        #PLOT POINTS ON SURFACE)
        for i in range(self.intu + 1):
            for j in range(self.intv + 1):

                #define u and v in terms of step values and i and j
                u = Udomain[0] + stepU * i
                v = Vdomain[0] + stepV * j

                point = rs.EvaluateSurface(self.strsrf, u, v)

                crvParam = rs.CurveClosestPoint(self.Crv, point)
                crvPoints = rs.EvaluateCurve(self.Crv, crvParam)

                if rs.Distance(point, crvPoints) < 400:
                    self.dis[(i, j)] = rs.Distance(point, crvPoints)
                else:
                    self.dis[(i, j)] = 1300

        return self.dis
Example #8
0
def _point_in_surface(id):
    v = rh.BrepClosestPoint(id, rawu0)
    if v:
        return fromPt(v[0])
    else:
        u, v = rh.SurfaceDomain(id, 0), rh.SurfaceDomain(id, 1)
        return rh.EvaluateSurface(id, u[0], v[0])
Example #9
0
    def calDomains(self):
        self.uDomain = rs.SurfaceDomain(self.srf, 0)
        self.vDomain = rs.SurfaceDomain(self.srf, 1)

        self.uStep = (self.uDomain[1] - self.uDomain[0]) / self.uNum
        self.vStep = (self.vDomain[1] -
                      self.vDomain[0]) / self.vDivisionAtStep(self.vNum)
Example #10
0
def srfPtZPair(srf):
    domainU = rs.SurfaceDomain(srf, 0)
    domainV = rs.SurfaceDomain(srf, 1)
    u = domainU[1] / 2.0
    v = domainV[1] / 2.0
    point = rs.EvaluateSurface(srf, u, v)
    el = round(point.Z, 3)
    return [srf, el]
Example #11
0
def getSrfFrame(srf):
    domainU = rs.SurfaceDomain(srf, 0)
    domainV = rs.SurfaceDomain(srf, 1)
    u = domainU[1] / 2.0
    v = domainV[1] / 2.0
    point = rs.EvaluateSurface(srf, u, v)
    param = rs.SurfaceClosestPoint(srf, point)
    return rs.SurfaceFrame(srf, param)
Example #12
0
def moveSrftoZ(srf):
    domainU = rs.SurfaceDomain(srf, 0)
    domainV = rs.SurfaceDomain(srf, 1)
    u = domainU[1] / 2.0
    v = domainV[1] / 2.0
    point = rs.EvaluateSurface(srf, u, v)
    # vec = [0, 0, point.Z]
    # vec = rs.VectorReverse(vec)
    # vec = [0,0,vec.Z]
    rs.MoveObjects(srf, rs.VectorReverse([0, 0, point.Z]))
Example #13
0
 def inter_S_B(s, div, Lis, br):
     udiv = div
     vdiv = div
     srf = rs.AddSphere((s[1]), ((s[2]) * 2.5))
     u = rs.SurfaceDomain(srf, 0)
     v = rs.SurfaceDomain(srf, 1)
     pts = []
     for i in range(0, udiv + 1, 1):
         for j in range(0, vdiv + 1, 1):
             pt = (i / udiv, j / vdiv, 0)
             srfP = rs.SurfaceParameter(srf, pt)
             newpt = rs.EvaluateSurface(srf, srfP[0], srfP[1])
             pts.append(rs.AddPoint(newpt))
     lig = []
     lid = []
     for p in pts:
         lig.append(rs.AddLine((Lis[0])[1], p))
         lid.append(rs.AddLine((Lis[0])[2], p))
     ig = []
     id = []
     for i in lig:
         for u in br:
             if type(rs.CurveBrepIntersect(i, (u[0]))) == tuple:
                 ig.append((rs.CurveBrepIntersect(i, (u[0]))) +
                           (u[1], ))
             else:
                 ig.append((rs.CurveBrepIntersect(i, (u[0]))))
     for i in lid:
         for u in br:
             if type(rs.CurveBrepIntersect(i, (u[0]))) == tuple:
                 id.append((rs.CurveBrepIntersect(i, (u[0]))) +
                           (u[1], ))
             else:
                 id.append((rs.CurveBrepIntersect(i, (u[0]))))
     if len(id) == 0:
         self.AddRuntimeMessage(
             war,
             "it doesn't seem like there's any geometries connected")
         raise Exception('noGeo')
     intg = 0
     for i in ig:
         if type(i) is tuple:
             intg += (1 * (i[-1]))
     intd = 0
     for i in id:
         if type(i) is tuple:
             intd += (1 * (i[-1]))
     difg = len(ig) - intg
     if difg <= 0:
         difg = 0.1
     difd = len(id) - intd
     if difd <= 0:
         difd = 0.1
     return [(((math.log10(difg * 100 / len(ig))) * 35.3) - 70.6),
             (((math.log10(difd * 100 / len(id))) * 35.3) - 70.6)]
Example #14
0
def SurfaceTensorField(srf_id, Nu, Nv):
    uDomain = rs.SurfaceDomain(srf_id, 0)
    vDomain = rs.SurfaceDomain(srf_id, 1)

    t = []
    k = []
    for i in range(Nu):
        u = uDomain[0] + (i/Nu)*(uDomain[1]-uDomain[0])
        for j in range(Nv):
            v = vDomain[0]+(j/Nv)*(vDomain[1]-vDomain[0])
            t.append( rs.SurfaceFrame(srf_id, (u,v)) )
            k.append( rs.SurfaceCurvature(srf_id, (u,v))[5] )
    return t,k
Example #15
0
def RandomPtOnSrf(srf):
    if srf is None:
        print "Not a surface"
        return
    dom_u = rs.SurfaceDomain(srf, 0)
    dom_v = rs.SurfaceDomain(srf, 1)
    
    while True:
        pt_u = random.uniform(dom_u[0], dom_u[1])
        pt_v = random.uniform(dom_v[0], dom_v[1])
        pt = rs.EvaluateSurface(srf, pt_u, pt_v)
        if rs.IsPointOnSurface(srf, pt):
            return pt
Example #16
0
def ptsOnSrf ():
    surfaceId = rs.GetObject("pick surface", 8, True, True)
    uVal = rs.GetInteger("pick u/row count",4, 1, 20)
    vVal = rs.GetInteger("pick v/col count",4, 1, 20)
    uDomain = rs.SurfaceDomain(surfaceId, 0)
    vDomain = rs.SurfaceDomain(surfaceId, 1)
    uStep = (uDomain[1] - uDomain[0])/ uVal
    vStep = (vDomain[1] - vDomain[0])/ vVal
    count = 0
    
    for i in rs.frange(uDomain[0], uDomain[1], uStep):
        for j in rs.frange(vDomain[0], vDomain[1], vStep):
            point = rs.EvaluateSurface(surfaceId, i, j)
            newPt = rs.AddPoint(point)
            count += 1
            rs.AddText(count,newPt, .25)
Example #17
0
def intervals(srf, uv, spacing):
    domains = []
    domain = rs.SurfaceDomain(srf, uv)
    i = spacing
    while i < domain[1]:
        domains.append(i)
        i = i + spacing
    return domains
    def SurfacePoints3(self):

        ptMTX = {}
        srfNORM = {}
        rndNORM = {}
        #rndptlist3 = []

        Udomain = rs.SurfaceDomain(self.strsrf, 0)
        Vdomain = rs.SurfaceDomain(self.strsrf, 1)

        stepU = (Udomain[1] - Udomain[0]) / self.intu
        stepV = (Vdomain[1] - Vdomain[0]) / self.intv

        #PLOT POINTS ON SURFACE
        count = 0
        self.rndvectorlist = self.rndvector()
        for i in range(self.intu + 1):
            for j in range(self.intv + 1):

                #define u and v in terms of step values and i and j
                u = Udomain[0] + stepU * i
                v = Vdomain[0] + stepV * j

                point = rs.EvaluateSurface(self.strsrf, u, v)
                ptMTX[(i, j)] = point

                #find normals at u,v parameters
                srfNORM[(i, j)] = rs.SurfaceNormal(self.strsrf, (u, v))

        #CREATE GRID OF OFFSET POINTS DEFINED BY SURFACE NORMALS
        self.Dis = self.distance()
        for i in range(self.intu + 1):
            for j in range(self.intv + 1):
                srfNORM[(i, j)] = rs.VectorScale(srfNORM[(i, j)],
                                                 120000 / self.Dis[(i, j)])
                srfNORM[(i, j)] = rs.PointAdd(ptMTX[(i, j)], srfNORM[(i, j)])
                rndNORM[(i, j)] = rs.VectorAdd(
                    srfNORM[(i, j)],
                    self.rndvectorlist[count] * (800 / self.Dis[(i, j)]))
                count = count + 1
                #rs.AddPoint(rndNORM[(i,j)])
                #rs.AddPoint(ptMTX[(i,j)])
                self.rndptlist3.append(rndNORM[(i, j)])
                #rs.DeleteObject(rndptlist3)
        return self.rndptlist3
Example #19
0
def FaceCamera():
    try:
        frames = rs.GetObjects("Select Picture Frames",
                               filter=8,
                               preselect=True)

        # rotate surfaces around z axis towards camera point
        if frames:
            rs.EnableRedraw(False)

            cam = rs.ViewCamera()
            camz = (cam.X, cam.Y, 0)
            angle = 1

            for i in frames:
                angle = 1
                while angle >= 1:

                    # get mid point of surface and move to z 0
                    pointmid = rs.SurfaceAreaCentroid(i)
                    pointmidz = (pointmid[0].X, pointmid[0].Y, 0)
                    # Get center UV of surface
                    domainU = rs.SurfaceDomain(i, 0)
                    domainV = rs.SurfaceDomain(i, 1)
                    u = domainU[1] / 2.0
                    v = domainV[1] / 2.0
                    # Get normal vector of surface and cam vector
                    vec1 = rs.SurfaceNormal(i, (u, v))
                    vec1 = vec1.X, vec1.Y, 0
                    vec2 = rs.VectorCreate(camz, pointmidz)
                    # find angle difference between the two vectors
                    angle = rs.VectorAngle(vec1, vec2)
                    angle = round(angle)
                    # Rotate Object
                    rs.RotateObject(i, pointmidz, angle)
                continue

            rs.EnableRedraw(True)

    except:
        print("Failed to execute")
        rs.EnableRedraw(True)
        return
Example #20
0
def RecursiveBox(polysurface, generation):
    surfaces = rs.ExplodePolysurfaces(polysurface, True)
    for surface in surfaces:

        if generation > 0:
            rs.RebuildSurface(surface, pointcount=(5, 5))
            domainU = rs.SurfaceDomain(surface, 0)
            domainV = rs.SurfaceDomain(surface, 1)
            randomU = random.uniform(domainU[0], domainU[1])
            randomV = random.uniform(domainV[0], domainV[1])
            point = rs.EvaluateSurface(surface, randomU, randomV)
            hulls = drawBoxByCenter(point[0], point[1], point[2],
                                    generation * 3, generation * 3,
                                    generation * 6)
            RecursiveBox(hulls, generation - 1)


#            ExplodeBox(hulls)
        SplitRecursive(surface, 0.5, 0, 3, generation)
Example #21
0
def ptsOnSrf ():
    surfaceId = rs.GetObject("pick surface", 8, True, True)
    uVal = rs.GetInteger("pick u/row count",4, 1, 20)
    vVal = rs.GetInteger("pick v/col count",4, 1, 20)
    uDomain = rs.SurfaceDomain(surfaceId, 0)
    vDomain = rs.SurfaceDomain(surfaceId, 1)
    uStep = (uDomain[1] - uDomain[0])/ uVal
    vStep = (vDomain[1] - vDomain[0])/ vVal
    count = 0
    allPts = []
    
    for i in rs.frange(uDomain[0], uDomain[1], uStep):
        for j in rs.frange(vDomain[0], vDomain[1], vStep):
            point = rs.EvaluateSurface(surfaceId, i, j)
            newPt = rs.AddPoint(point)
            allPts.append(newPt)
            
    rs.AddInterpCrvOnSrf(surfaceId, allPts)
    rs.DeleteObjects(allPts)
def RecursiveSphere(surface, generation):
    if generation > 0:
        domainU = rs.SurfaceDomain(surface, 0)
        domainV = rs.SurfaceDomain(surface, 1)
        randomU1 = random.uniform(domainU[0], domainU[1])
        randomV1 = random.uniform(domainV[0], domainV[1])
        randomU2 = random.uniform(domainU[0], domainU[1])
        randomV2 = random.uniform(domainV[0], domainV[1])
        randomU3 = random.uniform(domainU[0], domainU[1])
        randomV3 = random.uniform(domainV[0], domainV[1])
        point1 = rs.EvaluateSurface(surface, randomU1, randomV1)
        point2 = rs.EvaluateSurface(surface, randomU2, randomV2)
        point3 = rs.EvaluateSurface(surface, randomU3, randomV3)
        newsphere1 = NewSphere(point, 1000 / (4 - generation))
        newsphere2 = NewSphere(point, 1000 / (4 - generation))
        newsphere3 = NewSphere(point, 1000 / (4 - generation))
        RecursiveSphere(newsphere1, generation - 1)
        RecursiveSphere(newsphere2, generation - 1)
        RecursiveSphere(newsphere3, generation - 1)
    def SurfacePoints0(self):

        #ptlist0 = []

        Udomain = rs.SurfaceDomain(self.strsrf, 0)
        Vdomain = rs.SurfaceDomain(self.strsrf, 1)

        stepU = (Udomain[1] - Udomain[0]) / self.intu
        stepV = (Vdomain[1] - Vdomain[0]) / self.intv

        #PLOT POINTS ON SURFACE)
        for i in range(self.intu + 1):
            for j in range(self.intv + 1):

                #define u and v in terms of step values and i and j
                u = Udomain[0] + stepU * i
                v = Vdomain[0] + stepV * j

                point = rs.EvaluateSurface(self.strsrf, u, v)
                self.ptlist0.append(point)

        return self.ptlist0
Example #24
0
def Intervals(srf, uv, spacing, eq):
    domains = []
    domain = rs.SurfaceDomain(srf, uv)
    if eq:
        count = int(round(domain[1] / spacing))
        dist = domain[1] / count
    else:
        dist = spacing
    i = dist
    while i < domain[1]:
        domains.append(i)
        i = i + dist
    return domains
def SurfaceMidDomain(surface_id):
    """Returns the mid domain of a surface 
    Parameters:
      surface_id = the surface's identifier
    Returns:
      tuple of the mid domain u, v on success
    Example:
      import rsextras as rsext
      srf = rs.GetObject("Select a surface", rs.filter.surface)
      if rs.IsSurface(srf):
        print rsext.SurfaceMidDomain(srf)	
    See Also:
      
    """
    surface = rs.coercesurface(surface_id, True)
    u = rs.SurfaceDomain(surface, 0)
    u = (u[1] + u[0]) / 2
    v = rs.SurfaceDomain(surface, 1)
    v = (v[1] + v[0]) / 2
    if u is None or v is None:
        return scriptcontext.errorhandler()
    return (u, v)
Example #26
0
    def space(self, density=10):
        """"""
        try:
            du, dv = density
        except TypeError:
            du = density
            dv = density

        density_u = int(du)
        density_v = int(dv)

        uv = []

        rs.EnableRedraw(False)

        if rs.IsPolysurface(self.guid):
            faces = rs.ExplodePolysurfaces(self.guid)
        elif rs.IsSurface(self.guid):
            faces = [self.guid]
        else:
            raise Exception('Object is not a surface.')

        for face in faces:
            domain_u = rs.SurfaceDomain(face, 0)
            domain_v = rs.SurfaceDomain(face, 1)
            du = (domain_u[1] - domain_u[0]) / (density_u - 1)
            dv = (domain_v[1] - domain_v[0]) / (density_v - 1)

            for i in range(density_u):
                for j in range(density_v):
                    uv.append((domain_u[0] + i * du, domain_v[0] + j * dv))

        if len(faces) > 1:
            rs.DeleteObjects(faces)

        rs.EnableRedraw(True)

        return uv
Example #27
0
def saveSurfacesQuadDomains():
    surfaces = rs.GetObjects('select surfaces', 8)
    nU = rs.GetInteger("u", 2)
    nV = rs.GetInteger("v", 2)
    filename = rs.SaveFileName()
    vertices = {}
    vI = 1
    # file = open("testPythonexport.obj", "w")
    file = open(filename, "w")

    for surface in surfaces:
        domainU = rs.SurfaceDomain(surface, 0)
        dU = (domainU[1] - domainU[0]) / nU
        domainV = rs.SurfaceDomain(surface, 1)
        dV = (domainV[1] - domainV[0]) / nV
        for i in range(nU):
            for j in range(nV):
                cU1 = i * dU + domainU[0]
                cV1 = j * dV + domainV[0]
                cU2 = (i + 1) * dU + domainU[0]
                cV2 = (j + 1) * dV + domainV[0]
                pt1 = rs.SurfaceEvaluate(surface, [cU1, cV1], 1)[0]
                pt2 = rs.SurfaceEvaluate(surface, [cU2, cV1], 1)[0]
                pt3 = rs.SurfaceEvaluate(surface, [cU2, cV2], 1)[0]
                pt4 = rs.SurfaceEvaluate(surface, [cU1, cV2], 1)[0]
                pts = [pt1, pt2, pt3, pt4]
                indexes = []
                for point in pts:
                    index = vertices.get(point)
                    if index == None:
                        vertices[point] = vI
                        file.write(getVertexString(point))
                        index = vI
                        vI += 1
                    indexes.append(index)
                file.write(getFaceString(indexes))
                rs.AddCurve([pt1, pt2, pt3, pt4], 1)
    file.close()
Example #28
0
def map_surface_division(f,
                         surface,
                         nu,
                         nv,
                         include_last_u=True,
                         include_last_v=True):
    id = surface.realize()._ref
    domain_u = rh.SurfaceDomain(id, 0)
    domain_v = rh.SurfaceDomain(id, 1)
    start_u = domain_u[0]
    end_u = domain_u[1]
    start_v = domain_v[0]
    end_v = domain_v[1]

    def surf_f(u, v):
        plane = rh.SurfaceFrame(id, (u, v))
        if rh.IsPointOnSurface(id, plane.Origin):
            return f(fromPlane(plane))
        else:
            return False

    return map_division(surf_f, start_u, end_u, nu, include_last_u, start_v,
                        end_v, nv, include_last_v)
Example #29
0
def contour (crvOffset):
    # get geometry
    surfaceId = rs.GetObject("pick surface to contour", 0, True, True)
    startPt = rs.GetPoint("base point of contours")
    endPt = rs.GetPoint("end point of contours")
    count = 0
    reference = []
    target = []

    # make contours & store in newCrvs
    newCrvs = rs.AddSrfContourCrvs(surfaceId, (startPt, endPt), crvOffset) # output is a list of GUIDs. can't access raw points

    # divide the target surface
    printBed = rs.GetObject("pick surface for layout", 8, True, True)
    intCount = len(newCrvs)
    uDomain = rs.SurfaceDomain(printBed, 0)
    vDomain = rs.SurfaceDomain(printBed, 1)
    uStep = (uDomain[1] - uDomain[0]) / intCount

    for u in rs.frange(uDomain[0], uDomain[1], uStep):
        layout = rs.SurfaceFrame(printBed, [u,1])
        target1 = layout[0] # set target to point inside of object - note this is a single point
        target2 = rs.PointAdd(target1,(0,10,0)) # this could be more parametric
        target.extend([target1, target2])
    #print target

    # add text, reference and orient!
    # for orient, we need a list 3 points to reference and 3 points to target!
    # maybe reference should be curve origin crvPl[0] and midpoint? or else polyline verticies -- need to convert curve to polyline first? 
    for crv in newCrvs:
        count += 1 # for label
        crvPl = rs.CurvePlane(crv) # plane for text
        rs.AddText(count, crvPl, 0.25) # should you label on the ground?
        #crvPl = rs.PointAdd(crvPl[0], (0,0,-1)) # if you wanted to offset text
        ref1 = rs.CurveMidPoint(crv) 
        ref2 = crvPl[0]
        reference.extend([ref1, ref2])
Example #30
0
def WhoFramedTheSurface():
    surface_id = rs.GetObject("Surface to frame", 8, True, True)
    if not surface_id: return

    count = rs.GetInteger("Number of iterations per direction", 20, 2)
    if not count: return

    udomain = rs.SurfaceDomain(surface_id, 0)
    vdomain = rs.SurfaceDomain(surface_id, 1)
    ustep = (udomain[1] - udomain[0]) / count
    vstep = (vdomain[1] - vdomain[0]) / count

    rs.EnableRedraw(False)
    u = udomain[0]
    while u <= udomain[1]:
        v = vdomain[0]
        while v <= vdomain[1]:
            pt = rs.EvaluateSurface(surface_id, u, v)
            if rs.Distance(pt, rs.BrepClosestPoint(surface_id, pt)[0]) < 0.1:
                srf_frame = rs.SurfaceFrame(surface_id, [u, v])
                rs.AddPlaneSurface(srf_frame, 1.0, 1.0)
            v += vstep
        u += ustep
    rs.EnableRedraw(True)