예제 #1
0
def EvaluateSurfaceParam(ref_srf, u_val, v_val):
    normalized = (u_val, v_val)
    parameter = rs.SurfaceParameter(ref_srf, normalized)

    print "Surface parameter: ", parameter

    return rs.EvaluateSurface(ref_srf, parameter[0], parameter[1])
예제 #2
0
def faces():
    surfaces = rs.GetObjects("select surfaces", filter=rs.filter.surface)

    points = [
        rs.EvaluateSurface(surface, *rs.SurfaceParameter(surface, (0.5, 0.5)))
        for surface in surfaces
    ]
    x = reduce(lambda s, point: s + point.X, points, 0) / len(points)
    y = reduce(lambda s, point: s + point.Y, points, 0) / len(points)
    z = reduce(lambda s, point: s + point.Z, points, 0) / len(points)

    # find the center of the object
    mass_center = rs.AddPoint(x, y, z)

    extrude_curves = {}
    # find the appropriate extrusion curve with the lowest dot product
    for surface in surfaces:
        surface_center = rs.EvaluateSurface(
            surface, *rs.SurfaceParameter(surface, (0.5, 0.5)))
        center_vector = rs.VectorCreate(surface_center, mass_center)

        normals = []
        normals.append(
            rs.SurfaceNormal(surface, rs.SurfaceParameter(surface,
                                                          (0.5, 0.5))))
        normals.append(-rs.SurfaceNormal(
            surface, rs.SurfaceParameter(surface, (0.5, 0.5))))

        if (rs.VectorDotProduct(normals[0], center_vector) <
                rs.VectorDotProduct(normals[1], center_vector)):
            extrude_curve = normals[0]
        else:
            extrude_curve = normals[1]
        extrude_curve = rs.VectorUnitize(extrude_curve)
        extrude_curve = rs.VectorScale(extrude_curve, 0.25)
        extrude_curve = [
            surface_center,
            rs.VectorAdd(surface_center, extrude_curve)
        ]
        extrude_curve = rs.AddCurve(extrude_curve)

        rs.ExtrudeSurface(surface, extrude_curve)
        rs.DeleteObject(extrude_curve)
        rs.DeleteObject(surface)

    rs.DeleteObject(mass_center)
예제 #3
0
def set_part_base_plane(part):
    """returns an alinged plane at (U.5,V.5) of a planar surface"""
    x = True
    if x == True:  #rs.IsPlaneSurface(part):
        normalizedParameter = (.5, .5)
        frameParameter = rs.SurfaceParameter(part, normalizedParameter)
        frame = rs.SurfaceFrame(part, frameParameter)
        return frame
    else:
        return "object is not a planar surface"
예제 #4
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)]
예제 #5
0
def create_tag_location(part, u, v):
    """Given a srf., create a tag location on the srf at a given normalized
        u,v parameter"""
    parameter = rs.SurfaceParameter(part, (u, v))
    tagPt = rs.EvaluateSurface(part, parameter[0], parameter[1])
    return tagPt
#Python Workshop Lesson:22
#http://designalyze.com/int2pythonscripting22_DivideSrf2pts
import rhinoscriptsyntax as rs

srf = rs.GetObject("Pick surface to divide")
udiv = rs.GetInteger("Number of Divisions in U", 10)
vdiv = rs.GetInteger("Number of Divisions in V", 10)

u = rs.SurfaceDomain(srf, 0)
v = rs.SurfaceDomain(srf, 1)
print(str(u))
print(str(v))

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))
예제 #7
0
    def RunScript(self, Vi, NmbrOfRay, NmbrOfRef, Tolerance):

        __author__ = "theomarchal"
        self.Params.Input[
            0].Description = "Visualize (from esquissons main engine)"
        self.Params.Input[
            1].Description = "Definition/number of ray (1-100)<default=10>"
        self.Params.Input[
            2].Description = "Level of reflexion/number of bounces(1-10)<default=2>"
        self.Params.Input[
            3].Description = "Ray Distance to listener tolerance (0.1-1.0)<default=0.5>"
        self.Params.Output[0].Description = "Reflexion Rays"
        self.Name = "Visualize Reflections"
        self.NickName = "Visualize Rays"
        self.Message = "EsquisSons V3"
        self.Category = "EsquisSons"
        self.SubCategory = "2/ Visualization"
        Def = NmbrOfRay
        Level = NmbrOfRef
        Dist = Tolerance
        import rhinoscriptsyntax as rs
        import Grasshopper.Kernel as gh

        rem = gh.GH_RuntimeMessageLevel.Remark
        ero = gh.GH_RuntimeMessageLevel.Error
        war = gh.GH_RuntimeMessageLevel.Warning

        if Def == None:
            Def = 10
        if Level == None:
            Level = 2
        if Dist == None:
            Dist = 0.5
        try:
            Ge = Vi[0]
        except:
            self.AddRuntimeMessage(
                ero, 'A "Vi" ouptut from main engine must be connected !')
            raise Exception('noInput')
        Lis = Vi[1]
        Src = Vi[2]
        udiv = Def
        vdiv = Def
        Pt_L = Lis[0][0]
        Pt_R = Lis[0][2]
        srf = []
        FirstRay = []
        SecondRay = []
        First_RefPoint = []
        drawray = []
        for i in Ge:
            srf.append(i[0])
        for i in Src:
            sph = (rs.AddSphere(i[1], i[2]))
            Src_pt = (i[1])
            u = rs.SurfaceDomain(sph, 0)
            v = rs.SurfaceDomain(sph, 1)
            pts = []
            for i in range(0, udiv + 1, 1):
                for j in range(0, vdiv + 1, 1):
                    pt = (i / udiv, j / vdiv, 0)
                    sphP = rs.SurfaceParameter(sph, pt)
                    newpt = rs.EvaluateSurface(sph, sphP[0], sphP[1])
                    pts.append(rs.AddPoint(newpt))
            Dir = []
            for p in pts:
                Dir.append(rs.VectorCreate(p, Src_pt))
            Reflexion = []
            for d in Dir:
                Reflexion.append(rs.ShootRay(srf, Src_pt, d,
                                             reflections=Level))
            SourceRay = []
            for v in Reflexion:
                Cl_Pt = []
                Ray_v = []
                try:
                    Ray_v.append(rs.AddPolyline(v))
                except:
                    pass
                for u in Ray_v:
                    pt_on = rs.CurveClosestPoint(u, Pt_L)
                    cl = rs.EvaluateCurve(u, pt_on)
                    Dicl = (rs.Distance(Pt_L, cl))
                    if Dicl <= ((Lis[0])[3]) * Dist:
                        try:
                            drawray.append(u)
                        except:
                            pass
        if len(drawray) == 0:
            self.AddRuntimeMessage(
                war,
                'No ray, please be sure Geometries are connected to main engine and placed to create reflexions'
            )
            self.AddRuntimeMessage(war,
                                   'Change parameters to generate more rays')
            Rays = None
        else:
            Rays = drawray
        return Rays
예제 #8
0
 def rev(Ge, Lis, Src, div):
     udiv = div
     vdiv = div
     Pt_L = Lis[0][0]
     srf = []
     FirstRay = []
     SecondRay = []
     First_RefPoint = []
     drawray = []
     Reverb = []
     for i in Ge:
         srf.append(i[0])
     sph = (rs.AddSphere(Src[1], Src[2]))
     Src_pt = (Src[1])
     u = rs.SurfaceDomain(sph, 0)
     v = rs.SurfaceDomain(sph, 1)
     pts = []
     for i in range(0, udiv + 1, 1):
         for j in range(0, vdiv + 1, 1):
             pt = (i / udiv, j / vdiv, 0)
             sphP = rs.SurfaceParameter(sph, pt)
             newpt = rs.EvaluateSurface(sph, sphP[0], sphP[1])
             pts.append(rs.AddPoint(newpt))
     Dir = []
     for p in pts:
         Dir.append(rs.VectorCreate(p, Src_pt))
     Reflexion = []
     for d in Dir:
         Reflexion.append(rs.ShootRay(srf, Src_pt, d, reflections=4))
     Project = []
     for v in Reflexion:
         Cl_Pt = []
         Ray_v = []
         try:
             Project.append(v[1])
             Ray_v.append(rs.AddPolyline(v))
         except:
             pass
         for u in Ray_v:
             pt_on = rs.CurveClosestPoint(u, Pt_L)
             cl = rs.EvaluateCurve(u, pt_on)
             Dicl = (rs.Distance(Pt_L, cl))
             if Dicl <= ((Lis[0])[3]):
                 try:
                     First_RefPoint = rs.CurveClosestPoint(u, v[1])
                     Second_RefPoint = rs.CurveClosestPoint(u, v[2])
                     endc = ((rs.CurveClosestPoint(
                         u, (rs.CurveEndPoint(u)))))
                     if pt_on > Second_RefPoint:
                         SecondRay.append(pt_on / endc *
                                          (rs.CurveLength(u)))
                         drawray.append(u)
                     elif pt_on > First_RefPoint:
                         FirstRay.append(pt_on / endc *
                                         (rs.CurveLength(u)))
                 except:
                     pass
     box = rs.AddBox(rs.BoundingBox(Project))
     boxarea = round((rs.SurfaceArea(box)[0]), 2)
     Cube = []
     Cube.append(box)
     surfacetorev = []
     for s in srf:
         ptons = []
         for p in Project:
             if rs.Distance((rs.BrepClosestPoint(s, p)[0]), p) < 0.1:
                 ptons.append(p)
         if len(ptons) > 0:
             surfacetorev.append(s)
     surfaceab = []
     for x in Ge:
         if x[0] in surfacetorev:
             surfaceab.append(x[2])
     SrfandAb = [(surfacetorev[i], surfaceab[i])
                 for i in range(0, len(surfacetorev))]
     bbox = box
     box = round(((rs.SurfaceVolume(box))[0]), 1)
     srfvol = []
     srfvolex = []
     absvol = []
     srfarea = []
     srfrev = []
     areaabs = []
     surfacecenter = []
     absidx = []
     absvoltot = []
     for i in SrfandAb:
         if rs.SurfaceVolume(i[0]) > 0:
             srfvol.append(i[0])
             absvol.append(i[1])
         else:
             srfarea.append((rs.SurfaceArea(i[0]))[0])
             absvoltot.append(i[1])
     srfvolex = rs.ExplodePolysurfaces(srfvol)
     for i in srfvolex:
         ptonsrf = []
         usefulsrf = []
         for p in Project:
             if rs.Distance((rs.BrepClosestPoint(i, p)[0]), p) < 0.01:
                 ptonsrf.append(p)
                 usefulsrf.append(i)
         if len(ptonsrf) > 0:
             srfarea.append(rs.SurfaceArea(i)[0])
             srfrev.append(i)
     for i in srfrev:
         surfacecenter.append(rs.SurfaceAreaCentroid(i)[0])
     for b in srfvol:
         for i in surfacecenter:
             if rs.Distance((rs.BrepClosestPoint(b, i)[0]), i) < 0.01:
                 absidx.append(srfvol.index(b))
     for i in absidx:
         absvoltot.append(absvol[i])
     try:
         areaabs = [
             srfarea[i] * (absvoltot[i])
             for i in range(0, len(absvoltot))
         ]
     except:
         raise Exception(
             'One source must be too deep inside a geometry, try to get it out or to move it a little bit !'
         )
     Builtareaabs = 0
     for i in areaabs:
         Builtareaabs += i
     BuiltArea = 0
     for i in srfarea:
         BuiltArea += i
     BuiltArea = round(BuiltArea, 2)
     EmptyArea = 2 * (round(boxarea - BuiltArea, 2))
     if EmptyArea < 0:
         EmptyArea = 0
     TR = 1000 * (0.16 * box) / (Builtareaabs + (EmptyArea * 1))
     FRValue = 0
     for f in FirstRay:
         FV = ((((Lis[0])[3]) * 15) / f)
         FRValue += FV
     if FRValue >= 125:
         FRValue = 125
     SRValue = 0
     for s in SecondRay:
         SV = ((((Lis[0])[3]) * 20) / s)
         SRValue += SV
     if SRValue > 125:
         SRValue = 125
     Reverb.append(round(FRValue))
     Reverb.append(round(SRValue))
     Reverb.append(round(TR, 2))
     return Reverb
예제 #9
0

# SCRIPT

# select object
#objId = rs.GetObject("Select the surface", preselect = True, select = True)
#objId = "48a4e368-b082-4929-b4f9-da80ee50404a"
a = sc.doc.Objects.FindId(Guid.Parse(objId))
print(a)
#rs.EnableRedraw(False)

# make matrix
m = make_matrix(10, get_normalized_series(17))
# iterate matrix
d = iterate(m)

for comb in d:
    params1 = rs.SurfaceParameter(objId, [comb[0], comb[1]])
    params2 = rs.SurfaceParameter(objId, [comb[2], comb[3]])
    params3 = rs.SurfaceParameter(objId, [comb[4], comb[5]])
    params4 = rs.SurfaceParameter(objId, [comb[6], comb[7]])

    p1 = rs.SurfaceEvaluate(objId, params1, 0)
    p2 = rs.SurfaceEvaluate(objId, params2, 0)
    p3 = rs.SurfaceEvaluate(objId, params3, 0)
    p4 = rs.SurfaceEvaluate(objId, params4, 0)

    rs.AddSrfPt([p1[0], p2[0], p3[0], p4[0]])

#rs.EnableRedraw(True)