def project_text(vase, text, ndivs, div_y, x):
    size = Rhino.Geometry.Surface.GetSurfaceSize(rs.coercesurface(vase))
    boundary = rs.AddRectangle(rs.WorldXYPlane(), size[1], size[2])

    letters = list(text)
    letter_ncurves = []
    height = size[2] / ndivs
    for letter in letters:
        curves = create_text_curves("m" + letter, height, x, height * div_y)
        letter_ncurves.append(len(curves) - 1)
        rs.DeleteObjects(curves)

    return []
    curves = create_text_curves(text, height, x, height * div_y)
    return []
    start = 0
    splitted_vase = vase
    all_extruded = []
    for i in range(len(letters)):
        letter_curves = curves[start : start + letter_ncurves[i]]
        start = start + letter_ncurves[i]
        proj_curves = apply_crv(splitted_vase, boundary, letter_curves)
        ids = proj_curves[: letter_ncurves[i]]
        # rs.AddPipe(ids[0],[0],[0.1])
        print ids
        new_srf = split_srf(splitted_vase, ids)
        splitted_vase = new_srf[0]
        rs.FlipSurface(new_srf[1], flip=True)
        extruded = extrude_srf(new_srf[1])
        all_extruded.append(extruded[0])

    all_extruded.append(splitted_vase)
    rs.DeleteObjects(curves)
    rs.DeleteObjects(boundary)
    return all_extruded
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 cleanSrfcInput(_srfcsInput):
    """If Brep or Polysrfc are input, explode them"""

    outputSrfcs = []

    with idf2ph_rhDoc():

        for inputObj in _srfcsInput:

            if isinstance(rs.coercesurface(inputObj), Rhino.Geometry.BrepFace):

                # Catches Bare surfaces

                outputSrfcs.append(inputObj)

            elif isinstance(rs.coercebrep(inputObj), Rhino.Geometry.Brep):

                # Catches Polysurfaces / Extrusions or other Masses

                faces = ghc.DeconstructBrep(rs.coercebrep(inputObj)).faces

                if isinstance(faces, list):

                    for face in faces:

                        outputSrfcs.append(face)

            elif isinstance(rs.coercegeometry(inputObj),
                            Rhino.Geometry.PolylineCurve):

                # Catches PolylineCurves

                if not rs.coercegeometry(inputObj).IsClosed:

                    warn = 'Non-Closed Polyline Curves found. Make sure all curves are closed.'

                    ghenv.Component.AddRuntimeMessage(
                        ghK.GH_RuntimeMessageLevel.Remark, warn)

                else:

                    faces = ghc.DeconstructBrep(
                        rs.coercegeometry(inputObj)).faces

                    if isinstance(faces, list):

                        for face in faces:

                            outputSrfcs.append(face)

                    else:

                        outputSrfcs.append(faces)

        return outputSrfcs
Example #4
0
 def __init__(self, srfGUID):
     self.GUID = srfGUID
     self.borderGUID = rs.DuplicateSurfaceBorder(srfGUID)
     self.srfGeo = rs.coercesurface(srfGUID)
     self.brep = self.srfGeo.ToBrep()
     self.edgeCrvs = self.brep.DuplicateEdgeCurves()
     self.border = rg.Curve.JoinCurves( self.edgeCrvs )[0]
     self.nurbsCrv = self.border.ToNurbsCurve()
     
     amp = rg.AreaMassProperties.Compute(self.nurbsCrv, us.util.tol() )
     self.Centroid = amp .Centroid
     self.Area = amp.Area
Example #5
0
def clean_and_coerce_list(brep_list):
    #""" Ladybug - This definition cleans the list and adds them to RhinoCommon"""

    outputMesh = []
    outputBrep = []

    for id in brep_list:
        if rs.IsMesh(id):
            geo = rs.coercemesh(id)
            if geo is not None:
                outputMesh.append(geo)
                try:
                    rs.DeleteObject(id)
                except:
                    pass

        elif rs.IsBrep(id):
            geo = rs.coercebrep(id)
            if geo is not None:
                outputBrep.append(geo)
                try:
                    rs.DeleteObject(id)
                except:
                    pass

            else:
                # the idea was to remove the problematice surfaces
                # not all the geometry which is not possible since
                # badGeometries won't pass rs.IsBrep()
                tempBrep = []
                surfaces = rs.ExplodePolysurfaces(id)

                for surface in surfaces:
                    geo = rs.coercesurface(surface)
                    if geo is not None:
                        tempBrep.append(geo)
                        try:
                            rs.DeleteObject(surface)
                        except:
                            pass

                geo = JoinBreps(tempBrep, 0.01)

                for Brep in tempBrep:
                    Brep.Dispose()
                    try:
                        rs.DeleteObject(id)
                    except:
                        pass
                outputBrep.append(geo)

    return outputMesh, outputBrep
Example #6
0
def RunCommand( is_interactive ):
    rs.UnselectAllObjects()
    (vase, crv) = create_vase([3,4,3,5],[0, 3, 6, 10])
    rs.UnselectAllObjects()
    c = create_text_curves("na")
    #rs.DeleteObjects(c)
    #c = create_text_curves("gy")
    #rs.DeleteObjects(c)
    #c = create_text_curves("nmn")
    
    size = Rhino.Geometry.Surface.GetSurfaceSize(rs.coercesurface(vase))
    boundary = rs.AddRectangle(rs.WorldXYPlane(), size[1], size[2])
    apply_crv(vase, boundary, c)
def RunCommand():
  surface_id = rs.GetSurfaceObject()[0]
  if surface_id == None:
    return
  surface = rs.coercesurface(surface_id)

  corners = rs.GetRectangle()
  if corners == None:
    return
    
  plane = Plane(corners[0], corners[1], corners[2])

  is_or_isnt = "" if IsSurfaceInPlane(surface, plane, doc.ModelAbsoluteTolerance) else " not "
  print "Surface is{0} in plane.".format(is_or_isnt)
Example #8
0
def projectPtOnSrf(attractorPt, targetSrf, pt):
    r = rs.AddLine(attractorPt, pt)
    r = rs.ScaleObject(r, attractorPt, (10, 10, 10))

    dom = rs.CurveDomain(r)
    crv = rs.coercecurve(r)

    srf = rs.coercesurface(targetSrf).ToNurbsSurface()
    inv = Interval(dom[0], dom[1])

    rs.DeleteObject(r)

    xobj = Intersection.CurveSurface(crv, inv, srf, 0.1, 1)

    return xobj[0].PointB
Example #9
0
def projectPtOnSrf(attractorPt, targetSrf, pt):
    r = rs.AddLine(attractorPt, pt)
    r = rs.ScaleObject(r, attractorPt, (10, 10,10))
    
    dom = rs.CurveDomain(r)
    crv = rs.coercecurve(r)
    
    srf = rs.coercesurface(targetSrf).ToNurbsSurface()
    inv = Interval(dom[0], dom[1])
    
    rs.DeleteObject(r)
    
    xobj = Intersection.CurveSurface(crv, inv, srf, 0.1, 1)
    
    return xobj[0].PointB
Example #10
0
def RunCommand():
    surface_id = rs.GetSurfaceObject()[0]
    if surface_id == None:
        return
    surface = rs.coercesurface(surface_id)

    corners = rs.GetRectangle()
    if corners == None:
        return

    plane = Plane(corners[0], corners[1], corners[2])

    is_or_isnt = "" if IsSurfaceInPlane(
        surface, plane, doc.ModelAbsoluteTolerance) else " not "
    print "Surface is{0} in plane.".format(is_or_isnt)
Example #11
0
    def splitSrfwCrvs(srfGuid, crvGuids, delOrigSrf, skipBadCrvs=True):
        """Split a Surface with a Set of Curves
        Parameters:
          srfGuid: the input surface ID
          crvsGuid: the input trimming curves ID
          skipBadCrvs: flag to omit bad curves or fail the script if bad curves encountered
          delOrigSrf: flag to Delete the Original Surface
        Returns:
          True if successful
          False if not successful
        """

        retSrf = []

        srf = rs.coercesurface(srfGuid)
        if srf == None:
            print("SSC001_Not a Valid Surface")
            return False

        crvs = []
        for crv in crvGuids:
            validCrv = rs.coercecurve(crv)
            if validCrv == None:
                print("SSC002_Not a Valid Curve")
                if skipBadCrvs == False:
                    return False
            crvs.append(validCrv)

        #Have a Valid Surface and Valid Curves

        splitSrf = rg.BrepFace.Split(srf, crvs, 0.1)
        polySrf = sc.doc.Objects.AddBrep(splitSrf)
        splitSrfs = rs.ExplodePolysurfaces(polySrf)
        retSrf = splitSrfs

        #Change Isocurve Density to 0 for Individual Split Surfaces
        for srf in splitSrfs:
            theSrf = sc.doc.Objects.Find(srf)
            theSrf.Attributes.WireDensity = 0
            theSrf.CommitChanges()

        if delOrigSrf:
            sc.doc.Objects.Delete(srfGuid, True)

        sc.doc.Objects.Delete(polySrf, True)

        return retSrf
Example #12
0
def HorizPlaneFromSurface(srf):
    rhsrf = rs.coercesurface(srf)
    centerPoint = utils.FindMostDistantPointOnSrf(srf)
    u, v = rs.SurfaceClosestPoint(srf, centerPoint)
    origPlane = rhsrf.FrameAt(u,v)[1]
    if abs(origPlane.Normal.Z) == 1:
        #SURFACE HORIZONTAL
        plane = rs.WorldXYPlane()
        plane.Origin = centerPoint
        return plane
    else:
        #SURFACE NOT HORIZONTAL
        upVec = utils.GetUphillVectorFromPlane(srf)
        ptUp = rc.Geometry.Point3d.Add(centerPoint, upVec)
        line1 = rc.Geometry.Line(centerPoint, ptUp)
        ptY = rc.Geometry.Point3d.Add(centerPoint, origPlane.YAxis)
        line2 = rc.Geometry.Line(centerPoint, ptY)
        angle = math.radians(min(rs.Angle2(line1, line2)))
        origPlane.Rotate(angle, origPlane.Normal, centerPoint)
        return origPlane
def SurfaceMidPoint(surface_id):
    """Returns the point of mid domain of a surface 
    Parameters:
      surface_id = the surface's identifier
    Returns:
      point of the mid domain of a surface on success
    Example:
      import rsextras as rsext
      srf = rs.GetObject("Select a surface", rs.filter.surface)
      if rs.IsSurface(srf):
        print rsext.SurfaceMidPoint(srf)	
    See Also:
      
    """
    surface = rs.coercesurface(surface_id, True)
    u, v = getMidDomain(surface)
    es = rs.EvaluateSurface(surface, u, v)
    if es is None:
        return scriptcontext.errorhandler()
    return es
Example #14
0
def GetUphillVectorFromPlane(obj, u = 0, v = 0):
    """Gets the uphill vector from a surface, with optional u, v
    Parameters:
      surface (surface): surface to test
      u (float)[optional]: u parameter
      v (float)[optional]: v parameter
    Returns:
      vector(guid, ...): identifiers of surfaces created on success
    """
    rhobj = rs.coercesurface(obj)
    frame = rhobj.FrameAt(u,v)[1]
    pt0 = rhobj.PointAt(u,v)
    pt1 = rc.Geometry.Point3d.Add(pt0, rc.Geometry.Vector3d(0,0,10))
    projPoint = frame.ClosestPoint(pt1)
    vec = rs.VectorCreate(projPoint, pt0)
    if rs.VectorLength(vec) < rs.UnitAbsoluteTolerance():
        uphillVec = rc.Geometry.Vector3d(0,0,1)
    else:
        uphillVec = rs.VectorUnitize(vec)
    return uphillVec
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)
def project_text0(vase):
    size = Rhino.Geometry.Surface.GetSurfaceSize(rs.coercesurface(vase))
    boundary = rs.AddRectangle(rs.WorldXYPlane(), size[1], size[2])

    curves = create_text_curves("naama")
    new_curves = apply_crv(vase, boundary, curves)

    # rs.DeleteObjects(text_obj)
    # rs.DeleteObjects(boundary)

    id = rs.coerceguid(new_curves[2], True)
    new_srf = split_srf(vase, [id])

    strid = new_srf[1].Id.ToString()
    rs.FlipSurface(new_srf[1].Id, flip=True)
    bb = rs.coerceboundingbox(rs.BoundingBox(strid))
    normal = rs.SurfaceNormal(strid, rs.SurfaceClosestPoint(strid, bb.Center))
    cmd = "_ExtrudeSrf _SelID %s _Enter Direction %s %s 0.1 _Enter" % (strid, point2str(normal), point2str(bb.Center))

    print cmd
    rs.Command(cmd)

    return True
def DynamicCrvOnSrf():
    def drawMyCurve(sender, e):

        points[-1] = e.CurrentPoint  #change last point to CurrentPoint
        pts = [points[i] for i in xrange(len(points))]
        curve = rhsrf.InterpolatedCurveOnSurface(points, 0.01)
        if curve == None:
            del pts[-1]
            curve = rhsrf.InterpolatedCurveOnSurface(pts, 0.01)
        if curve:
            nc = curve.ToNurbsCurve()
            ptCount = optInt.CurrentValue
            nc = nc.Rebuild(ptCount, 3, True)
            ncpoints = [nc.Points[i].Location for i in xrange(nc.Points.Count)]
            e.Display.DrawCurve(nc, Color.LightCyan, 2)
            e.Display.DrawPoints(ncpoints, Rhino.Display.PointStyle.Simple, 5,
                                 Color.Cyan)
            e.Display.DrawPoints(points, Rhino.Display.PointStyle.X, 1,
                                 Color.Blue)

    def getPoint():
        if points != [] and len(points) == 4:
            gp.AddOption("Close")
        while True:
            result = gp.Get()
            if result == Rhino.Input.GetResult.Point:
                gp.AcceptUndo(True)
                gp.SetCommandPrompt("Next point")
                pt = gp.Point()
                newpoint = rs.AddPoint(pt)
                snapPoints.append(newpoint)
                #append first picked point
                if points == []:
                    points.append(pt)
                    gp.DynamicDraw += drawMyCurve
                #check if next picked point is same as previous
                if len(points) > 1:
                    a = round(points[-1].X, 2)
                    b = round(points[-2].X, 2)
                    if a == b:
                        del points[-1]
                #add empty point to list
                #will get assigned in drawMyCurve()
                points.append(Rhino.Geometry.Point3d)

                #recursion: getpoint calling itself if a point has been picked:
                getPoint()
            elif result == Rhino.Input.GetResult.Option:
                #go back to point selection mode
                if gp.OptionIndex() == 1:
                    getPoint()
                elif gp.OptionIndex() == 2:
                    #close the curve
                    del points[-1]
                    ptCount = optInt.CurrentValue
                    pt = points[0]
                    #check if the last point is already 'closing' the curve
                    a = round(points[-1].X, 2)
                    b = round(points[0].X, 2)
                    if a == b:
                        del points[-1]
                    points.append(pt)
                    rs.DeleteObjects(snapPoints)
                    newcrv = rs.AddInterpCrvOnSrf(srf, points)
                    rs.RebuildCurve(newcrv, 3, ptCount)
                    sc.doc.Views.Redraw()

            elif result == Rhino.Input.GetResult.Undo:
                if len(points) > 1:
                    del points[-2]
                    rs.DeleteObject(snapPoints[-1])
                    del snapPoints[-1]
                if len(points) <= 1:
                    gp.AcceptUndo(False)
                getPoint()
            #pressing spacebar, enter
            elif result == Rhino.Input.GetResult.Nothing and len(
                    points) > 2:  #2 picked points +1 temporary point
                #remove last added preview point
                del points[-1]
                ptCount = optInt.CurrentValue
                rs.DeleteObjects(snapPoints)
                newcrv = rs.AddInterpCrvOnSrf(srf, points)
                rs.RebuildCurve(newcrv, 3, ptCount)
                sc.doc.Views.Redraw()
            #pressing esc
            else:
                rs.DeleteObjects(snapPoints)
            break

    srf = rs.GetObject("Select surface to draw curve on", rs.filter.surface)
    if srf == None:
        return
    rhsrf = rs.coercesurface(srf)
    gp = Rhino.Input.Custom.GetPoint()
    gp.SetCommandPrompt("Start of Curve")
    gp.Constrain(rhsrf, False)
    gp.AcceptNothing(True)
    Rhino.ApplicationSettings.SmartTrackSettings.UseSmartTrack = False
    points = []
    snapPoints = []
    optInt = Rhino.Input.Custom.OptionInteger(20, 4, 100)
    gp.AddOptionInteger("ptCount", optInt)
    getPoint()
Example #18
0
import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino
import Rhino.Geometry

targId = rs.GetObject(
    "Select the first object to replace",
    rs.filter.surface,
    preselect=True,
)
#obj = sc.doc.Objects.Find(targId)
#if not targId:return
#point = rs.GetPointOnSurface(surface, "Point on surface")

obj = sc.doc.Objects.Find(targId)
srf = rs.coercesurface(targId)
#point = rs.GetPointOnSurface(srf, "Point on surface")
print srf


def intFlipBool(tf):
    return abs(tf - 1)


def frange(start, count, step=1.0):
    ''' "range()" like function which accept float type'''
    i = start
    for c in range(count):
        yield i
        i += step
Example #19
0
def AreaTag(obj, decPlaces):
    try:
        rhsrf = rs.coercesurface(obj)
        if rs.IsCurve(obj):
            if rs.IsCurvePlanar(obj) == False:
                return [0, False]
            if rs.IsCurveClosed(obj) == False:
                return [0, False]

        #get area
        if rs.UnitSystem() == 8:
            if rs.IsCurve(obj):
                area = rs.CurveArea(obj)[0]*0.0069444444444444
            else:
                area = rs.Area(obj)*0.0069444444444444
            areaText = utils.RoundNumber(area, decPlaces) + " SF"
        else:
            print "WARNING: Your units are not in inches"
            area = rs.CurveArea(obj)[0]
            areaText = area + ' ' + rs.UnitSystemName(False, True, True)

        #add annotation style
        dimStyle = sc.doc.DimStyles.FindName('PCPA_12')

        ###########################################################################
        #CURVES
        if rs.IsCurve(obj):
            if utils.IsRectangle(obj)[0]:
                #RECTANGLES
                srf = rs.AddPlanarSrf(obj)
                plane = HorizPlaneFromSurface(srf)
                rs.DeleteObject(srf)
            else:
                #OTHER CURVES
                srf = rs.AddPlanarSrf(obj)
                plane = HorizPlaneFromSurface(srf)
                rs.DeleteObject(srf)
        ###########################################################################
        #HATCHES
        elif rs.IsHatch(obj):
            rhobj = rs.coercegeometry(obj)
            boundaryCrvs = []
            crvs = rhobj.Get3dCurves(False)
            for crv in crvs:
                boundaryCrvs.append(crv)
            for crv in rhobj.Get3dCurves(True):
                boundaryCrvs.append(crv)
            srf = sc.doc.Objects.AddBrep(rc.Geometry.Brep.CreatePlanarBreps(boundaryCrvs)[0])
            plane = HorizPlaneFromSurface(srf)
            rs.DeleteObject(srf)
        ###########################################################################
        #SURFACES
        elif rs.IsSurface(obj):
            plane = HorizPlaneFromSurface(obj)

        ###########################################################################
        #OTHER/ERROR
        else:
            pts = rs.BoundingBox(obj)
            centerPoint = (pts[0] + pts[6]) / 2


        if dimStyle is not None:
            textHeight = dimStyle.TextHeight
            areaTag = rs.AddText(areaText, plane, height = textHeight, justification = 131074)
        else:
            areaTag = rs.AddText(areaText, plane, height = 1, justification = 131074)

        #Change layers
        hostLayer = layers.AddLayerByNumber(8103, False)
        rs.ObjectLayer(areaTag, layers.GetLayerNameByNumber(8103))
        return [area, True, areaTag]
    except:
        return [0, False]
Example #20
0
 def __init__(self):
     self.floorID = r'ec68de3f-0f6f-4c67-95e9-cb86d8a13d7e'
     self.floor = rs.coercesurface(self.floorID)
Example #21
0
def CutModel(objs, srf):
    try:
        if rs.ObjectType(srf) == 1073741824:
            extrusionSurface = rs.coercesurface(srf)
            rhSrf = extrusionSurface.ToBrep().Faces[0]
        else:
            rhSrf = rs.coercesurface(srf)
        plane = rhSrf.TryGetPlane()[1]
        if rhSrf.OrientationIsReversed:
            plane.Flip()
        groupMain = rs.AddGroup('MainObjects')
        groupCut = rs.AddGroup('SectionSurfaces')
        groupVisible = rs.AddGroup('VisibleObjects')

        rs.HideObject(objs)

        for obj in objs:
            #BLOCKS
            if rs.IsBlockInstance(obj):
                blockObjs = utils.GetAllBlockObjectsInPosition(obj)
                for eachBlockObj in blockObjs:
                    rhobj = rs.coercegeometry(eachBlockObj)
                    splitResults = CutObjectWithPlane(rhobj, plane)
                    if splitResults[0] is not None:
                        for eachObj in splitResults[0]:
                            utils.SafeMatchObjectAttributes(
                                eachObj, eachBlockObj)
                            #rs.MatchObjectAttributes(eachObj, eachBlockObj)
                            rs.ShowObject(eachObj)
                            rs.AddObjectToGroup(eachObj, groupMain)
                        for eachObj in splitResults[1]:
                            utils.SafeMatchObjectAttributes(
                                eachObj, eachBlockObj)
                            #rs.MatchObjectAttributes(eachObj, eachBlockObj)
                            rs.ShowObject(eachObj)
                            rs.AddObjectToGroup(eachObj, groupMain)
                        for eachObj in splitResults[3]:
                            rs.ObjectColor(eachObj, (255, 0, 0))
                            rs.ObjectName(eachObj, 'Section Cut Surface')
                            rs.AddObjectToGroup(eachObj, groupCut)
                    rs.DeleteObject(eachBlockObj)

            #GEOMETRY
            else:
                rhobj = rs.coercegeometry(obj)
                splitResults = CutObjectWithPlane(rhobj, plane)
                if splitResults[0] is not None:
                    for eachObj in splitResults[0]:
                        utils.SafeMatchObjectAttributes(eachObj, eachBlockObj)
                        #rs.MatchObjectAttributes(eachObj, obj)
                        rs.ShowObject(eachObj)
                        rs.AddObjectToGroup(eachObj, groupMain)
                    for eachObj in splitResults[1]:
                        utils.SafeMatchObjectAttributes(eachObj, eachBlockObj)
                        #rs.MatchObjectAttributes(eachObj, obj)
                        rs.ShowObject(eachObj)
                        rs.AddObjectToGroup(eachObj, groupMain)
                    for eachObj in splitResults[3]:
                        rs.ObjectColor(eachObj, (255, 0, 0))
                        rs.ObjectName(eachObj, 'Section Cut Surface')
                        rs.AddObjectToGroup(eachObj, groupCut)
        return True
    except:
        print "Cut Model failed"
        return False
Example #22
0
 def test_IncreaseByOne(self):
     self.assertTrue(rs.ChangeSurfaceDegree(self.id, (3, 3)))
     d0 = rs.coercesurface(self.id).ToNurbsSurface().Degree(0)
     d1 = rs.coercesurface(self.id).ToNurbsSurface().Degree(1)
     self.assertEqual(3, d0)
     self.assertEqual(3, d1)
 def test_IncreaseByOne(self):
   self.assertTrue(rs.ChangeSurfaceDegree(self.id, (3,3)))
   d0 = rs.coercesurface(self.id).ToNurbsSurface().Degree(0)
   d1 = rs.coercesurface(self.id).ToNurbsSurface().Degree(1)
   self.assertEqual(3, d0)
   self.assertEqual(3, d1)
Example #24
0
def FindMostDistantPointOnSrf(obj, resolution = 20):
    """
    Returns the approximately most distant point within a closed curve
    inputs:
        obj (curve): closed planar curves
        resolution (int)[optional]: numbers of sample points in a resolutionXresolution grid
    returns:
        point (point): point furthest from curve
    """
    #HATCH
    if rs.IsHatch(obj):
        rhobj = rs.coercegeometry(obj)
        boundaryCrvs = []
        crvs = rhobj.Get3dCurves(False)
        for crv in crvs:
            boundaryCrvs.append(crv)
        for crv in rhobj.Get3dCurves(True):
            boundaryCrvs.append(crv)
        obj = sc.doc.Objects.AddBrep(rc.Geometry.Brep.CreatePlanarBreps(boundaryCrvs)[0])
        rhobj = rs.coercesurface(obj)
        brep = rs.coercebrep(obj)
        rs.DeleteObject(obj)
    else:
        rhobj = rs.coercesurface(obj)
        brep = rs.coercebrep(obj)
    edges = brep.Edges
    duplEdgs = [edg.DuplicateCurve() for edg in edges]
    duplEdgs = rc.Geometry.Curve.JoinCurves(duplEdgs)

    uDir = rhobj.Domain(0)
    vDir = rhobj.Domain(1)

    uVals = []
    vVals = []
    for i in range(resolution):
        uVals.append(i)
        vVals.append(i)

    newUvals = RemapList(uVals, uDir[0], uDir[1])
    newVvals = RemapList(vVals, vDir[0], vDir[1])

    furthestPt = None
    furthestDist = 0
    maxDist = 999999
    for uVal in newUvals:
        for vVal in newVvals:
            u = uVal
            v = vVal
            srf_pt = rhobj.PointAt(u,v)
            result = rhobj.IsPointOnFace(u,v) != rc.Geometry.PointFaceRelation.Exterior
            if result:
                thisPtsDistances = []
                for eachEdge in duplEdgs:
                    param = eachEdge.ClosestPoint(srf_pt, maxDist)
                    crvPt = eachEdge.PointAt(param[1])
                    thisPtsDistances.append(rs.Distance(crvPt, srf_pt))

                dist = min(thisPtsDistances)
                if dist > furthestDist:
                    furthestPt = srf_pt
                    furthestDist = dist
    if furthestDist == 0:
        return None
    return furthestPt