示例#1
0
def sweepSec(crv, plane, vec):
    rect = profileXform(rectFrame(), plane, vec)
    sweep = rs.AddSweep1(crv, rect, closed=True)
    sweep = rs.CapPlanarHoles(sweep)
    if rect: rs.DeleteObjects(rect)
    if crv: rs.DeleteObjects(crv)
    return sweep
示例#2
0
def sweepSec(crv, plane, vec):
    # rs.AddPlaneSurface( plane, 1, 1 )
    rect = profile2(plane, vec)
    sweep = rs.AddSweep1(crv, rect, closed=True)
    sweep = rs.CapPlanarHoles(sweep)
    if rect: rs.DeleteObjects(rect)
    if crv: rs.DeleteObjects(crv)
    return sweep
示例#3
0
def _irregular_pyramid(pts0, pt1):
    pts0, pt1 = map(Pt, pts0), Pt(pt1)
    id = rh.JoinSurfaces([
        rh.AddSrfPt((pt00, pt01, pt1))
        for pt00, pt01 in zip(pts0, pts0[1:] + [pts0[0]])
    ])
    rh.CapPlanarHoles(id)
    return id
示例#4
0
def createPockets(tool_id, operation, z_pos, obj):

    if operation == 'Inner contour' or operation == 'Pocket' or operation=='Drill':
        surface_id = rs.ExtrudeCurveStraight( obj, (0,0,0), (0, 0, MAT_THICKNESS+2) )
        rs.CapPlanarHoles(surface_id)
        rs.MoveObject(surface_id, (0,0,z_pos))
        
        return surface_id
def splitModel(objs, cutLevel):
    point = Rhino.Geometry.Point3d(0,0,cutLevel)
    
    belowDir = rs.AddLine(point, [0,0,-9999])
    aboveDir = rs.AddLine(point, [0,0,9999])
    circle = rs.AddCircle(point, 9999)
    circleSrf = rs.AddPlanarSrf(circle)
    
    aboveGroup = rs.AddGroup("Above")
    belowGroup = rs.AddGroup("Below")
    
    
    for obj in objs:
        ptBtm = rs.BoundingBox(obj)[0]
        ptTop = rs.BoundingBox(obj)[6]
        if ptBtm[2]>cutLevel:
            intersecting = False
            rs.AddObjectToGroup(obj, "Above")
            #print "Object Above"
        elif ptTop[2]<cutLevel:
            intersecting = False
            rs.AddObjectToGroup(obj, "Below")
            #print "Object Below"
        else:
            intersecting = True
        
        if intersecting:
            if rs.IsBrep(obj):
                closed = False
                if rs.IsPolysurfaceClosed(obj):
                    closed = True
                try:
                    copy = rs.CopyObject(obj)
                    splitSrfs = rs.SplitBrep(obj, circleSrf, True)
                    for splitSrf in splitSrfs:
                        #print "looping"
                        if closed:
                            rs.CapPlanarHoles(splitSrf)
                        rs.MatchObjectAttributes(splitSrf, copy)
                        ptBtm = rs.BoundingBox(splitSrf)[0]
                        ptTop = rs.BoundingBox(splitSrf)[6]
                        mdPtZ = (ptBtm[2] + ptTop[2]) / 2
                        if mdPtZ>cutLevel:
                            rs.AddObjectToGroup(splitSrf, "Above")
                        else:
                            rs.AddObjectToGroup(splitSrf, "Below")
                    rs.DeleteObject(copy)
                    rs.DeleteObject(obj)
                except:
                    None
            if rs.IsBlockInstance(obj):
                contents = rs.ExplodeBlockInstance(obj)
                for content in contents:
                    objs.append(content)
    rs.DeleteObject(belowDir)
    rs.DeleteObject(aboveDir)
    rs.DeleteObject(circle)
    rs.DeleteObject(circleSrf)
示例#6
0
def makeExtrusions(m, obj, material_thickness):

    tool_id     = m.group(1)
    operation   = m.group(2)
    z_pos       = m.group(3)
    
    if operation == 'Outer contour':
        surface_id = rs.ExtrudeCurveStraight( obj, (0,0,0), (0, 0, material_thickness) )
        rs.CapPlanarHoles(surface_id)
        return surface_id        
示例#7
0
def _irregular_pyramid_frustum(pts0, pts1):
    pts0, pts1 = map(Pt, pts0), map(Pt, pts1)
    id = rh.JoinSurfaces([
        rh.AddSrfPt((pt00, pt01, pt11, pt10))
        for pt00, pt01, pt10, pt11 in zip(pts0, pts0[1:] +
                                          [pts0[0]], pts1, pts1[1:] +
                                          [pts1[0]])
    ])
    rh.CapPlanarHoles(id)
    return id
示例#8
0
def get_frame_brep(outline_srf, border_thickness, thickness):
    """get the frame brep. This is a solid that is booleaned with the slices of
	terrain to make a border when border mode is on."""
    edge_crvs = rs.DuplicateEdgeCurves(outline_srf)
    outline_crv = rs.JoinCurves(edge_crvs)
    pt, _ = rs.CurveAreaCentroid(outline_crv)
    inner_crv = rs.OffsetCurve(outline_crv, pt, border_thickness, [0, 0, 1])
    rs.MoveObjects([outline_crv, inner_crv], [0, 0, thickness * 2])

    path_line = rs.AddLine([0, 0, 0], [0, 0, -thickness * 4])
    inner_brep = rs.ExtrudeCurve(inner_crv, path_line)
    outer_brep = rs.ExtrudeCurve(outline_crv, path_line)
    rs.CapPlanarHoles(inner_brep)
    rs.CapPlanarHoles(outer_brep)

    frame_brep = rs.BooleanDifference([outer_brep], [inner_brep])
    rs.DeleteObjects([outline_crv, inner_crv])
    rs.DeleteObjects(edge_crvs)
    rs.DeleteObject(path_line)
    return frame_brep
示例#9
0
 def join_jigs(self, jigs):
     start_end = self.create_end_caps(jigs[0].start_corners,
                                      rs.VectorReverse(jigs[0].across))
     end_end = self.create_end_caps(jigs[len(jigs) - 1].end_corners,
                                    jigs[len(jigs) - 1].across)
     surfaces = [start_end]
     for i in range(0, len(jigs), 1):
         surfaces.append(jigs[i].srf)
         if (i < len(jigs) - 1):
             surfaces.append(jigs[i].connector)
     surfaces.append(end_end)
     surface = rs.JoinSurfaces(surfaces, True)
     rs.CapPlanarHoles(surface)
     print rs.IsObjectSolid(surface)
示例#10
0
 def slice_ref(self, r, p, n):
     cutter = rh.AddCutPlane([r], Pt(p), Pt(p + vx(1, p.cs)),
                             Pt(vy(1, p.cs)))
     rs = rh.SplitBrep(r, cutter, True)
     rs = rs or [r]
     for e in rs:
         rh.CapPlanarHoles(e)
     keep, clear = partition(
         rs, lambda r:
         (fromPt(rh.SurfaceVolumeCentroid(r)[0]) - p).dot(n) < 0)
     rh.DeleteObjects(clear)
     rh.DeleteObject(cutter)
     if keep == []:
         return empty_ref()
     else:
         return single_ref_or_union(keep)
示例#11
0
文件: rh_trial.py 项目: tanyaroi/PyGH
def extr_bld_flr():
    # Extrude all buildings according to NUM_FLOORS attribute multiplied by FLOOR_HEIGHT constant
    # get all objects in building layer
    building_objs = rs.ObjectsByLayer(relevant_layers_dict["buildings"])
    for building_obj in building_objs:
        if rs.IsCurve(building_obj) and rs.IsCurveClosed(
                building_obj
        ) and rs.CurveArea(building_obj)[0] > MIN_BUILDING_AREA_SQM:
            crv = rs.coercecurve(building_obj)
            num_of_floors = rs.GetUserText(building_obj, "NUM_FLOORS")
            building_height = FLOOR_HEIGHT_M * int(num_of_floors)
            srf = rs.ExtrudeCurveStraight(crv, (0, 0, 0),
                                          (0, 0, building_height))
            rs.CapPlanarHoles(srf)

    rs.ViewDisplayMode(rs.CurrentView(), "Shaded")
示例#12
0
def curveVic(storyHt):
    profiles = []
    firstCrv = rs.GetObject("pick a base curve", 4, True, True)
    count = rs.GetInteger("how many total curves")
    #dentil = rs.GetObject("pick dentil", 8)

    # vertically offset curves
    for i in range(count):
        if count == 0 or count == 1:
            return
        else:
            profiles.append(rs.CopyObject(firstCrv, [0, 0, storyHt * i]))

    # funk it up - needs to be more randomized?
    for crv in profiles:
        centerPt = rs.CurveAreaCentroid(crv)
        # deg = random.randint(0,360)
        # deg = random.randint(0,4) * 90 very swirly!
        deg = profiles.index(crv) * 10
        rs.RotateObject(crv, centerPt[0], deg)


#    centerPt = rs.CurveAreaCentroid(profiles[3])
#    rs.RotateObject(profiles[3], centerPt[0], 30)
#    centerPt = rs.CurveAreaCentroid(profiles[7])
#    rs.RotateObject(profiles[7], centerPt[0], 30)

# scale each crv randomly
#    for crv in profiles:
#        centerPt = rs.CurveAreaCentroid(crv)
#        x = random.uniform(.25,2)
#        y = random.uniform(.25,2)
#        z = 1
#        rs.ScaleObject(crv, centerPt[0], (x,y,z) )

# add dentils and trim. map to surface? project? rs.SporphObject() better to use in GUI flow?
# is there any flow along surface? no center box?!?! just acquire shape
#    for j in range(len(profiles)):
#       points = rs.DivideCurveEquidistant(profiles[j], 5)
#       for k in points:
#           rs.AddSphere(k, .25)

# loft curves and clean up
    finalShape = rs.AddLoftSrf(profiles, closed=False)
    #profiles.append(firstCrv)
    rs.DeleteObjects(profiles)
    rs.CapPlanarHoles(finalShape)
示例#13
0
            def make(self):
                self.segments = rs.ExplodeCurves(self.Rect)

                treadLength = rs.CurveLength(self.segments[1]) / self.numRisers
                riserHeight = self.deltaHeight / self.numRisers
                runVector = rs.VectorCreate(
                    rs.CurveEndPoint(self.segments[1]),
                    rs.CurveStartPoint(self.segments[1]))
                unitRunVec = rs.VectorUnitize(runVector)
                treadVec = rs.VectorScale(unitRunVec, treadLength)
                riseVec = rs.VectorCreate([0, 0, riserHeight], [0, 0, 0])

                newPt = [
                    rs.CurveStartPoint(self.segments[0]).X,
                    rs.CurveStartPoint(self.segments[0]).Y,
                    rs.CurveStartPoint(self.segments[0]).Z - self.deltaHeight
                ]
                ptList = []
                ptList.append(rs.AddPoint(newPt))
                for i in range(self.numRisers):
                    tempPt = rs.CopyObject(ptList[-1])
                    rs.MoveObject(tempPt, riseVec)
                    ptList.append(tempPt)
                    tempPt = rs.CopyObject(ptList[-1])
                    rs.MoveObject(tempPt, treadVec)
                    ptList.append(tempPt)

                downLine = rs.VectorCreate([0, 0, 0], [0, 0, self.thickness])
                newBtmPt = rs.MoveObject(rs.CopyObject(ptList[0]), downLine)
                ptList.insert(0, newBtmPt)
                newBtmPt2 = rs.MoveObject(rs.CopyObject(ptList[-1]), downLine)
                ptList.append(newBtmPt2)

                stringer = rs.AddPolyline(ptList)
                closeCrv = rs.AddLine(rs.CurveStartPoint(stringer),
                                      rs.CurveEndPoint(stringer))

                newStringer = rs.JoinCurves([stringer, closeCrv], True)

                stair = rs.ExtrudeCurve(newStringer, self.segments[0])
                rs.CapPlanarHoles(stair)
                rs.DeleteObject(stringer)
                rs.DeleteObject(newStringer)
                rs.DeleteObjects(ptList)
                rs.DeleteObjects(self.segments)
                return stair
示例#14
0
                    building_obj) and (rs.CurveArea(building_obj)[0] >
                                       MIN_BUILDING_AREA_SQM):
                crv = rs.coercecurve(building_obj)
                if rs.PointInPlanarClosedCurve(related_building_pnt, crv):
                    xy_found = True
                    for attr_label, attr_val in zip(attribute_labels_list,
                                                    attributes_row):
                        rs.SetUserText(building_obj, attr_label, attr_val)
        if not xy_found:
            rs.SelectObject(building_obj)
            print(x_val, y_val, z_val)
    print(out_loop_counter)
##########################################################################################################################################

# Extrude all buildings according to NUM_FLOORS attribute multiplied by FLOOR_HEIGHT constant
# get all objects in building layer
building_objs = rs.ObjectsByLayer(relevant_layers_dict["buildings"])
for building_obj in building_objs:
    if rs.IsCurve(building_obj) and rs.IsCurveClosed(
            building_obj
    ) and rs.CurveArea(building_obj)[0] > MIN_BUILDING_AREA_SQM:
        crv = rs.coercecurve(building_obj)

        num_of_floors = rs.GetUserText(building_obj, "NUM_FLOORS")
        if num_of_floors == None:
            pass
#        building_height = FLOOR_HEIGHT_M * num_of_floors
        srf = rs.ExtrudeCurveStraight(crv, (0, 0, 0), (0, 0, 20))
        rs.CapPlanarHoles(srf)

rs.ViewDisplayMode(rs.CurrentView(), "Shaded")
示例#15
0
def makeFireStair(rect, landingLevels):
    #HARD VARIABLES
    minStairWidth = 1.118
    minHeadroom = 2.032
    maxRunRise = 3.658
    minNumRisers = 3
    minGapSize = .2
    minTread = .280
    maxTread = .400
    minRiser = .100
    maxRiser = .180
    thickness = .25
    maxRisersInRun = 16
    maxWidth = 2.4
    scissorStair = False
    hdrlHeight = .900
    #hdrlTopExtension = .305
    #hdrlBtmExtension = 1*treadDepth
    #hdrlMaxProjection = .114

    #(1)Determine Run Direction
    rs.SimplifyCurve(rect)
    rectSegments = rs.ExplodeCurves(rect)
    edge1 = rectSegments[0]
    edge3 = rectSegments[1]
    if rs.CurveLength(edge1) > rs.CurveLength(edge3):
        longEdge = edge1
        shortEdge = edge3
    else:
        longEdge = edge3
        shortEdge = edge1
    longVec = rs.VectorCreate(rs.CurveStartPoint(longEdge),
                              rs.CurveEndPoint(longEdge))
    longVecRev = rs.VectorReverse(longVec)
    shortVec = rs.VectorCreate(rs.CurveStartPoint(shortEdge),
                               rs.CurveEndPoint(shortEdge))
    shortVecRev = rs.VectorReverse(shortVec)

    #(2)Stair Width
    stairWidth = (rs.CurveLength(shortEdge) - minGapSize) / 2
    if stairWidth < .6:
        print "ERROR: Stair is ridiculously too narrow."
        return

    #(3)Run Length
    runLength = rs.CurveLength(longEdge) - (stairWidth * 2)
    if runLength < 1:
        print "ERROR: Stair is ridiculously too short."
        return

    #LandingRect
    landing1Plane = rs.PlaneFromFrame(rs.CurveStartPoint(shortEdge),
                                      shortVecRev, longVecRev)
    landing1 = rs.AddRectangle(landing1Plane, rs.CurveLength(shortEdge),
                               stairWidth)
    landing2Plane = rs.PlaneFromFrame(rs.CurveEndPoint(longEdge), shortVec,
                                      longVec)
    landing2 = rs.AddRectangle(landing2Plane, rs.CurveLength(shortEdge),
                               stairWidth)

    #RunRects
    run1Plane = rs.PlaneFromFrame(
        rs.CurveEditPoints(landing1)[3], shortVecRev, longVecRev)
    run1Rect = rs.AddRectangle(run1Plane, stairWidth, runLength)
    run2Plane = rs.PlaneFromFrame(
        rs.CurveEditPoints(landing2)[3], shortVec, longVec)
    run2Rect = rs.AddRectangle(run2Plane, stairWidth, runLength)

    #(4)Num Flights between Landings
    numLevels = len(landingLevels)
    deltaLevels = []
    runsPerLevel = []
    mostRisersInRun = math.floor(runLength / minTread)
    if mostRisersInRun > maxRisersInRun:
        mostRisersInRun = maxRisersInRun
    numRuns = 0

    for i in range(0, numLevels - 1):
        deltaLevels.append(landingLevels[i + 1] - landingLevels[i])
        minNumRisers = math.ceil(deltaLevels[i] / maxRiser)
        runsPerLevel.append(math.ceil(minNumRisers / mostRisersInRun))
        numRuns = numRuns + int(runsPerLevel[i])

    #(5) Which flights
    listOfRuns = []
    for i in range(0, numRuns):
        if i % 2:  #if even
            listOfRuns.append(rs.CopyObject(run1Rect))
        else:
            listOfRuns.append(rs.CopyObject(run2Rect))

    #(6) Num Treads per run
    runsDeltaHeight = []
    for i in range(0, numLevels - 1):
        for j in range(0, int(runsPerLevel[i])):
            runsDeltaHeight.append(deltaLevels[i] / runsPerLevel[i])

    numRisersPerRun = []
    for i in range(0, numRuns):
        numRisersPerRun.append(math.ceil(runsDeltaHeight[i] / maxRiser))

    #(7) Move Runs
    elevation = 0
    landings = []
    for i in range(0, numRuns):
        elevation = elevation + runsDeltaHeight[i]
        translation = rs.VectorCreate([0, 0, elevation], [0, 0, 0])
        rs.MoveObject(listOfRuns[i], translation)
        if i % 2:
            landings.append(rs.MoveObject(rs.CopyObject(landing2),
                                          translation))
        else:
            landings.append(rs.MoveObject(rs.CopyObject(landing1),
                                          translation))

    #(8) Make Landings
    stairGeo = []
    for i in range(0, numRuns):
        dir = rs.VectorCreate([0, 0, 0], [0, 0, runsDeltaHeight[i]])
        #rs.MoveObject(landings[i], dir)
        path = rs.AddLine([0, 0, 0], [0, 0, -thickness])
        geo = rs.ExtrudeCurve(landings[i], path)
        rs.CapPlanarHoles(geo)
        stairGeo.append(geo)
        rs.DeleteObject(path)
    rs.DeleteObjects(landings)

    #(9) Draw Stairs
    runs = []
    for i in range(0, numRuns):
        runs.append(
            Run(listOfRuns[i], runsDeltaHeight[i], numRisersPerRun[i],
                thickness, i, maxTread))
        stairGeo.append(runs[i].make())
        runs[i].makeHandrail(hdrlHeight, minGapSize)
        runs[i].printStats()
        runs[i].cleanup()

    finalGeo = rs.BooleanUnion(stairGeo, delete_input=True)

    #(10) Scissor Stairs
    if scissorStair:
        pt0 = rs.CurveMidPoint(rectSegments[0])
        pt1 = rs.CurveMidPoint(rectSegments[1])
        pt2 = rs.CurveMidPoint(rectSegments[2])
        pt3 = rs.CurveMidPoint(rectSegments[3])
        mir1 = rs.MirrorObject(finalGeo, pt0, pt2, copy=True)
        mirroredStair = rs.MirrorObject(mir1, pt1, pt3, copy=False)

    #(11)Label
    rs.SetUserText(finalGeo, "Brew", "Hot Coffee")
    if scissorStair:
        rs.SetUserText(mirroredStair, "Brew", "Hot Coffee")

    #Cleanup
    rs.DeleteObjects(listOfRuns)
    rs.DeleteObjects(rectSegments)
    rs.DeleteObject(landing1)
    rs.DeleteObject(landing2)
    rs.DeleteObject(run1Rect)
    rs.DeleteObject(run2Rect)
    print "done"
    return None
示例#16
0
    def make(self):
        runVector = rs.VectorCreate(rs.CurveEndPoint(self.runLongEdge),
                                    rs.CurveStartPoint(self.runLongEdge))
        unitRunVec = rs.VectorUnitize(runVector)
        treadVec = rs.VectorScale(unitRunVec, self.treadLength)
        riseVec = rs.VectorCreate([0, 0, self.riserHeight], [0, 0, 0])

        newPt = [
            rs.CurveStartPoint(self.firstRiserEdge).X,
            rs.CurveStartPoint(self.firstRiserEdge).Y,
            rs.CurveStartPoint(self.firstRiserEdge).Z - self.deltaHeight
        ]

        ptList = []
        ptList.append(rs.AddPoint(newPt))
        for i in range(self.numRisers):
            tempPt = rs.CopyObject(ptList[-1])
            rs.MoveObject(tempPt, riseVec)
            ptList.append(tempPt)
            tempPt = rs.CopyObject(ptList[-1])
            rs.MoveObject(tempPt, treadVec)
            ptList.append(tempPt)

        #stringer construct offset line
        undersideLine = rs.AddLine(ptList[0], ptList[-1])
        closestPtParam = rs.CurveClosestPoint(undersideLine, ptList[1])
        closestPt = rs.EvaluateCurve(undersideLine, closestPtParam)
        perpVec = rs.VectorUnitize(rs.VectorCreate(ptList[1], closestPt))
        stringerBtm = rs.MoveObject(undersideLine,
                                    rs.VectorScale(perpVec, -self.thickness))
        cnstrLine = rs.ScaleObject(stringerBtm, rs.CurveMidPoint(stringerBtm),
                                   [2, 2, 2])

        #line going down
        btmPt = rs.MoveObject(ptList[0], [0, 0, -self.thickness])
        moveDir = rs.VectorCreate(ptList[2], ptList[1])
        btmPtMoved = rs.MoveObject(rs.CopyObject(btmPt),
                                   rs.VectorScale(moveDir, 3))
        btmLineCnstr = rs.AddLine(btmPt, btmPtMoved)
        ptIntersectBtm = rs.AddPoint(
            rs.LineLineIntersection(btmLineCnstr, cnstrLine)[0])  #yes

        #top lines
        topVec = rs.VectorScale(
            rs.VectorUnitize(rs.VectorCreate(ptList[-1], ptList[-2])),
            self.extenionLength)
        topPt1 = rs.MoveObject(ptList[-1], topVec)
        topPtDown = rs.MoveObject(rs.CopyObject(topPt1),
                                  [0, 0, -self.thickness])
        extLengthTemp = self.extenionLength
        if extLengthTemp < .1:
            extLengthTemp = .1
        topVec = rs.VectorScale(
            rs.VectorUnitize(rs.VectorCreate(ptList[-1], ptList[-2])),
            extLengthTemp)
        topPtTemp = rs.MoveObject(rs.CopyObject(topPtDown), topVec)
        topLine = rs.AddLine(topPtDown, topPtTemp)
        ptIntersectTop = rs.AddPoint(
            rs.LineLineIntersection(topLine, cnstrLine)[0])  #yes

        ptList.append(topPtDown)
        ptList.append(ptIntersectTop)
        ptList.append(ptIntersectBtm)

        stringer = rs.AddPolyline(ptList)
        closeCrv = rs.AddLine(rs.CurveStartPoint(stringer),
                              rs.CurveEndPoint(stringer))

        newStringer = rs.JoinCurves([stringer, closeCrv], True)

        stair = rs.ExtrudeCurve(newStringer, self.firstRiserEdge)

        rs.CapPlanarHoles(stair)

        #make handrail guide curve
        topOfNosing = rs.AddLine(ptList[1], ptList[-5])
        self.guideCrv = topOfNosing

        rs.DeleteObject(btmLineCnstr)
        rs.DeleteObject(btmPtMoved)
        rs.DeleteObject(btmLineCnstr)
        rs.DeleteObject(ptIntersectTop)
        rs.DeleteObject(undersideLine)
        rs.DeleteObject(topPtTemp)
        rs.DeleteObject(topLine)
        rs.DeleteObject(stringer)
        rs.DeleteObject(newStringer)
        rs.DeleteObjects(ptList)

        return stair
示例#17
0
def piece(layers, maxScale):
    curves = []
    initialRadii = []
    results = []
    for i in range(count):
        initialRadii.append(random.uniform(minScale * maxScale, maxScale))

    # outerExtrusions
    outerExtrusions = []
    radii = initialRadii[:]
    for layer in range(layers):
        height = layer * layerHeight
        smooth(radii, smoothAmount)
        shrink(radii, outerReduce)
        scale(radii, random.uniform(1 - wiggle, 1 + wiggle))
        scale(radii, upwardsShaping(layer / (layers - 1)))
        vertices = []
        for i in range(count):
            theta = 2 * math.pi * i / count
            vertices.append((math.sin(theta) * radii[i],
                             math.cos(theta) * radii[i], height))
        vertices.append(vertices[0])
        curve = rs.AddCurve(vertices, 5)
        curves.append(curve)
        if complete:
            extrusion = rs.ExtrudeCurveStraight(curve, (0, 0, 0),
                                                (0, 0, layerHeight))
            rs.CapPlanarHoles(extrusion)
            outerExtrusions.append(extrusion)
            if not hollow:
                results.append(extrusion)

    if hollow:
        for i in range(shrinkPasses):
            shrink(radii, innerReduce)

        # innerExtrusions
        for layer in range(layers):
            actualLayer = layers - layer - 1
            height = actualLayer * layerHeight
            smooth(radii, smoothAmount)
            shrink(radii, innerReduce)
            vertices = []
            for i in range(count):
                theta = 2 * math.pi * i / count
                vertices.append((math.sin(theta) * radii[i],
                                 math.cos(theta) * radii[i], height))
            vertices.append(vertices[0])
            curve = rs.AddCurve(vertices, 5)
            curves.append(curve)
            if complete:
                extrusion = rs.ExtrudeCurveStraight(curve, (0, 0, 0),
                                                    (0, 0, layerHeight))
                rs.CapPlanarHoles(extrusion)
                result = rs.BooleanDifference(outerExtrusions[actualLayer],
                                              extrusion)
                results.append(result)

    if downwards:
        radii = initialRadii[:]
        for layer in range(downwardsLayers):
            height = -(layer + 1) * layerHeight
            smooth(radii, smoothAmount)
            shrink(radii, downwardsReduce)
            scale(radii, random.uniform(1 - wiggle, 1 + wiggle))
            scale(radii, downwardsShaping(layer / (downwardsLayers - 1)))
            vertices = []
            for i in range(count):
                theta = 2 * math.pi * i / count
                vertices.append((math.sin(theta) * radii[i],
                                 math.cos(theta) * radii[i], height))
            vertices.append(vertices[0])
            curve = rs.AddCurve(vertices, 5)
            curves.append(curve)
            if complete:
                extrusion = rs.ExtrudeCurveStraight(curve, (0, 0, 0),
                                                    (0, 0, layerHeight))
                rs.CapPlanarHoles(extrusion)
                outerExtrusions.append(extrusion)
                if not hollow:
                    results.append(extrusion)

    if buildScaffolding:
        scaffoldBase = rs.AddRectangle(
            (-scaffoldSide / 2, -scaffoldSide / 2, 0), scaffoldSide,
            scaffoldSide)
        scaffold = rs.ExtrudeCurveStraight(scaffoldBase, (0, 0, 0),
                                           (0, 0, (layers - 1) * layerHeight))
        rs.CapPlanarHoles(scaffold)
        rs.DeleteObject(scaffoldBase)
        results.append(scaffold)

    if complete:
        rs.DeleteObjects(curves)
        rs.AddObjectsToGroup(results, rs.AddGroup())
        return results
    else:
        rs.AddObjectsToGroup(curves, rs.AddGroup())
        return curves
示例#18
0
def sweepVolume(crv, tool_id, z_pos):

    tangent = rs.CurveTangent(crv, rs.CurveParameter(crv, 0))
    origin = rs.CurveStartPoint(crv)
    
    block = rs.InsertBlock( tool_id, (0,0,0), scale=(1,1,1) )
    

    # rs.DeleteObjects(objs)
       
    # pt2 = [origin.X, origin.Y + perp.XAxis[1], origin.Z]
    pt2 = [origin.X, origin.Y , origin.Z + 1]
    pt3 = [origin.X + tangent.X, origin.Y + tangent.Y , origin.Z + tangent.Z]

    ref     = [(0,0,0),(0,1,0),(0,0,1)] 
    target  = [origin, pt2 ,pt3]
    
    
    block = rs.OrientObject(block, ref, target)
    
    objs = rs.ExplodeBlockInstance(block)
    profile = None
    for item in objs:
        if rs.ObjectLayer(item) == 'HULP::C_Toolcontours' or rs.ObjectLayer(item) == 'Hulp::C_Toolcontours':
            profile = rs.CopyObject(item)
            
    
    rs.DeleteObjects(objs)


    
    if not profile:
        rs.MessageBox('there is no layer named "C_Toolcontours" in block %s' % rs.BlockInstanceName(block))
        return False
            
    profile = rs.OffsetCurve(profile, rs.CurveAreaCentroid(profile)[0], 0.001, style=1)
    
    # rs.MoveObject(profile, (0,0,z_pos))
            
    
    # rail = obj
    # rail_crv = rs.coercecurve(rail)
    # if not rail_crv: return
    # 
    # cross_sections = [profile]
    # if not cross_sections: return
    # cross_sections = [rs.coercecurve(crv) for crv in cross_sections]
    # 
    # sweep = Rhino.Geometry.SweepOneRail()
    # sweep.AngleToleranceRadians = scriptcontext.doc.ModelAngleToleranceRadians
    # sweep.ClosedSweep = True
    # # sweep.MiterType  = 2
    # sweep.SweepTolerance = scriptcontext.doc.ModelAbsoluteTolerance
    # sweep.SetToRoadlikeTop()
    # breps = sweep.PerformSweep(rail_crv, cross_sections)
    # for brep in breps: scriptcontext.doc.Objects.AddBrep(brep)
    # scriptcontext.doc.Views.Redraw()
    # 
    # # surface_id = rs.LastCreatedObjects()

    
    # METHOD1
    surface_id = rs.AddSweep1( crv, profile, True )    

    rs.CapPlanarHoles(surface_id)
    
    pt = rs.CurveAreaCentroid(profile)[0]
    pt2 = (pt.X, pt.Y, pt.Z+1)
    
    rev = rs.AddRevSrf( profile, (pt, pt2) )
    
    
    
    rs.MoveObject(surface_id, (0,0,z_pos))
    rs.MoveObject(rev, (0,0,z_pos))
    
    
    
    return [surface_id, rev]        

    
    
    rs.UnselectAllObjects()
    rs.SelectObjects([crv, profile])
    
    result = rs.Command("_-Sweep1 _Enter Style=RoadlikeTop _Enter", False)
            
    if result: 
        rs.DeleteObject(profile)
        surface_id = rs.LastCreatedObjects()

        rs.CapPlanarHoles(surface_id)
    
        rs.DeleteObjects(objs)
        rs.MoveObject(surface_id, (0,0,z_pos))

        return surface_id        
示例#19
0
def solid_sweep_path_curve(path, profile, rotation, scale):
    r = sweep_path_curve(path, profile, rotation, scale)
    rh.CapPlanarHoles(r)
    rh.DeleteObject(profile)
    return r
示例#20
0
def makeExtrusions(tool_id, operation, z_pos, obj, material_thickness):
    
    if operation == 'Outer contour':
        surface_id = rs.ExtrudeCurveStraight( obj, (0,0,0), (0, 0, material_thickness) )
        rs.CapPlanarHoles(surface_id)
        return surface_id        
示例#21
0
def loft_profiles(profiles, rails, is_solid, is_ruled, is_closed):
    r = loft_profiles_aux(profiles, rails, is_ruled, is_closed)
    if is_solid:
        rh.CapPlanarHoles(r)
    return and_delete(r, *(profiles + rails))
示例#22
0
        def makeFireStair(rect, landingLevels):
            #HARD VARIABLES
            minGapSize = .2
            minTread = .260
            maxRiser = .180
            thickness = .15

            #(1)Determine Run Direction
            rs.SimplifyCurve(rect)
            rectSegments = rs.ExplodeCurves(rect)
            edge1 = rectSegments[0]
            edge3 = rectSegments[1]
            rs.DeleteObject(rectSegments[2])
            rs.DeleteObject(rectSegments[3])
            if rs.CurveLength(edge1) > rs.CurveLength(edge3):
                longEdge = edge1
                shortEdge = edge3
            else:
                longEdge = edge3
                shortEdge = edge1
            longVec = rs.VectorCreate(rs.CurveStartPoint(longEdge),
                                      rs.CurveEndPoint(longEdge))
            longVecRev = rs.VectorReverse(longVec)
            shortVec = rs.VectorCreate(rs.CurveStartPoint(shortEdge),
                                       rs.CurveEndPoint(shortEdge))
            shortVecRev = rs.VectorReverse(shortVec)
            rs.CurveArrows(longEdge, 2)
            rs.CurveArrows(shortEdge, 2)

            #(2)Stair Width
            stairWidth = (rs.CurveLength(shortEdge) - minGapSize) / 2

            #LandingRect
            landing1Plane = rs.PlaneFromFrame(rs.CurveStartPoint(shortEdge),
                                              shortVecRev, longVecRev)
            landing1 = rs.AddRectangle(landing1Plane,
                                       rs.CurveLength(shortEdge), stairWidth)
            landing2Plane = rs.PlaneFromFrame(rs.CurveEndPoint(longEdge),
                                              shortVec, longVec)
            landing2 = rs.AddRectangle(landing2Plane,
                                       rs.CurveLength(shortEdge), stairWidth)

            #(3)Run Length
            runLength = rs.CurveLength(longEdge) - (stairWidth * 2)

            #RunRects
            run1Plane = rs.PlaneFromFrame(
                rs.CurveEditPoints(landing1)[3], shortVecRev, longVecRev)
            run1Rect = rs.AddRectangle(run1Plane, stairWidth, runLength)
            run2Plane = rs.PlaneFromFrame(
                rs.CurveEditPoints(landing2)[3], shortVec, longVec)
            run2Rect = rs.AddRectangle(run2Plane, stairWidth, runLength)

            #(4)Num Flights between Landings
            numLevels = len(landingLevels)
            deltaLevels = []
            runsPerLevel = []
            maxRisersPerRun = math.floor(runLength / minTread)
            numRuns = 0

            for i in range(0, numLevels - 1):
                deltaLevels.append(landingLevels[i + 1] - landingLevels[i])
                minNumRisers = math.ceil(deltaLevels[i] / maxRiser)
                runsPerLevel.append(math.ceil(minNumRisers / maxRisersPerRun))
                numRuns = numRuns + int(runsPerLevel[i])

            #(5) Which flights

            listOfRuns = []
            for i in range(0, numRuns):
                if i % 2:  #if even
                    listOfRuns.append(rs.CopyObject(run1Rect))
                else:
                    listOfRuns.append(rs.CopyObject(run2Rect))

            #(6) Num Treads per run
            runsDeltaHeight = []
            for i in range(0, numLevels - 1):
                for j in range(0, int(runsPerLevel[i])):
                    runsDeltaHeight.append(deltaLevels[i] / runsPerLevel[i])

            numRisersPerRun = []
            for i in range(0, numRuns):
                numRisersPerRun.append(math.ceil(runsDeltaHeight[i] /
                                                 maxRiser))

            #(7) Move Runs
            elevation = 0
            landings = []
            for i in range(0, numRuns):
                elevation = elevation + runsDeltaHeight[i]
                translation = rs.VectorCreate([0, 0, elevation], [0, 0, 0])
                rs.MoveObject(listOfRuns[i], translation)
                if i % 2:
                    landings.append(
                        rs.MoveObject(rs.CopyObject(landing2), translation))
                else:
                    landings.append(
                        rs.MoveObject(rs.CopyObject(landing1), translation))

            #(8) Make Landings
            stairGeo = []
            for i in range(0, numRuns):
                dir = rs.VectorCreate([0, 0, 0], [0, 0, runsDeltaHeight[i]])
                #rs.MoveObject(landings[i], dir)
                path = rs.AddLine([0, 0, 0], [0, 0, -thickness])
                geo = rs.ExtrudeCurve(landings[i], path)
                rs.CapPlanarHoles(geo)
                stairGeo.append(geo)
                rs.DeleteObject(path)
            rs.DeleteObjects(landings)

            #(9) Draw Stairs
            runs = []
            for i in range(0, numRuns):
                runs.append(
                    Run(listOfRuns[i], runsDeltaHeight[i], numRisersPerRun[i]))
                stairGeo.append(runs[i].make())

            finalGeo = rs.BooleanUnion(stairGeo, delete_input=True)
            #Cleanup
            rs.DeleteObjects(listOfRuns)
            rs.DeleteObjects(rectSegments)
            rs.DeleteObject(landing1)
            rs.DeleteObject(landing2)
            rs.DeleteObject(run1Rect)
            rs.DeleteObject(run2Rect)
            print "done"
            return finalGeo
    bottom_planes.append(planes)
  
    
# Rotate planes on ZAxis
rotated_planes = []
for i in bottom_planes:
    plane = rs.ViewCPlane()
    rndm_angle = random.randrange(-5, 5) 
    rotated_z = rs.RotatePlane(i, rndm_angle, planes.ZAxis)
    # Tilt control
    tilt = random.randrange(-5, 5) * max_tilt
    rotated_x = rs.RotatePlane(rotated_z, tilt, planes.XAxis)
    rotated_planes.append(rotated_x)
    
    
# Create solids
solids = []
lines = []
for j in range(0, len(rotated_planes)):
    line = rs.AddLine(bottom_pts[j], top_pts[j])
    lines.append(line)
    tilt = random.randrange(-5, 5) * max_tilt
    rot_lines = rs.RotateObject(line, bottom_pts[j], tilt, planes.XAxis, copy=False)
    rct = rs.AddRectangle( rotated_planes[j], 
    rg.Interval(-0.5 * block_w, 0.5 * block_w), 
    rg.Interval(-0.5 * block_d, 0.5 * block_d))
    solid = rs.ExtrudeCurve(rct, rot_lines)
    sld = rs.CapPlanarHoles(solid)
    solids.append(solid)
    
print('Ivan Perez | [email protected] | Bogotá | Colombia')
示例#24
0
    # if math.sin(12 * (theta - t) + math.pi) > 0:
    # 	base -= .02
    # else:
    # 	base += .02
    return base


complete = True
layerHeight = 2.90
layerCount = 40
baseRadius = 112
phase = (10 / 360) * 2 * math.pi
vertexCount = 320

curves = []
for i in range(layerCount):
    vertices = []
    z = layerHeight * i
    t = map(i, -1, layerCount, 0, 1)  #i / (layerCount - 1)
    radius = baseRadius * layerShape(t)
    for j in range(vertexCount):
        theta = map(j, 0, vertexCount, 0, 2 * math.pi)
        curRadius = radiusShape(theta, t) * radius
        vertices.append((math.sin(phase + theta) * curRadius,
                         math.cos(phase + theta) * curRadius, z))
    vertices.append(vertices[0])
    curve = rs.AddCurve(vertices)
    curves.append(curve)
    extrusion = rs.ExtrudeCurveStraight(curve, (0, 0, 0), (0, 0, layerHeight))
    rs.CapPlanarHoles(extrusion)
rs.DeleteObjects(curves)
示例#25
0
        def stairGen(self, sender, e):

            # Variables and defaults
            tread = int(self.treadC.Value) * scale
            riser = int(self.riserC.Value) * scale
            numSteps = int(self.numStepsC.Value)
            flip = self.flipC.Checked
            stairLength = tread * numSteps
            genStair = self.genStairBool.Checked
            curveList = []
            junkList = []

            # get user line for top width of stair

            rs.EnableRedraw(False)

            if genStair == False:
                iteration = rs.ObjectsByName(
                    "GdC9V&^a^rGZZNgiWFH&aTRQLLscu*9AZCmhk8t2!a")
                if iteration:
                    rs.DeleteObject(iteration)
                    rs.EnableRedraw(True)

            if genStair == True:
                # Delete any existing iteration
                iteration = rs.ObjectsByName(
                    "GdC9V&^a^rGZZNgiWFH&aTRQLLscu*9AZCmhk8t2!a")
                if iteration:
                    rs.DeleteObject(iteration)

                topLine = rs.AddLine(line[0], line[1])
                topPoint = line[0]
                stepPoint = topPoint

                # get perp line - length of stair
                t = rs.CurveClosestPoint(topLine, topPoint)
                planeNormal = rs.CurveNormal(topLine)
                tangent = rs.CurveTangent(topLine, t)
                curveNormal = rs.VectorCrossProduct(planeNormal, tangent)

                # Get vector
                vectorRun = rs.VectorCreate(
                    topPoint, topPoint + curveNormal * tread)

                # Bool flip direction of stair (add bool option in GUI)
                if flip == True:
                    vector = rs.VectorReverse(vectorRun)
                else:
                    vector = vectorRun

                # loop through number of steps to gen step curve
                for i in range(numSteps):
                    pt01 = rs.AddPoint(stepPoint)
                    pt02 = rs.CopyObject(pt01, vector)
                    pt03 = rs.CopyObject(pt02, [0, 0, riser*-1])
                    curve = rs.AddPolyline([pt01, pt02, pt03])
                    curveList.append(curve)
                    stepPoint = rs.CurveEndPoint(curve)
                    rs.DeleteObjects([pt01, pt02, pt03])

                # Extrude stair curve to full width
                joinedCurve = rs.JoinCurves(curveList)
                bottomPoint = rs.CopyObject(
                    line[0], [0, 0, (riser*numSteps)*-1])
                stairBottom = rs.CurveEndPoint(joinedCurve)
                curve = rs.AddPolyline([line[0], bottomPoint, stairBottom])
                # createhandrail curve and return it
                handRailCurve = rs.AddCurve([bottomPoint, stairBottom])
                curveList.append(curve)
                joinedCurves = rs.JoinCurves(curveList)
                stair = rs.ExtrudeCurveStraight(joinedCurves, line[0], line[1])
                rs.CapPlanarHoles(stair)
                # this identifies the generated stair geometry
                rs.ObjectName(
                    stair, "GdC9V&^a^rGZZNgiWFH&aTRQLLscu*9AZCmhk8t2!a")

                # clean up leftover geometry
                junkList.extend([bottomPoint, joinedCurve,
                                joinedCurves, topLine, handRailCurve])
                junkList = junkList + curveList
                rs.DeleteObjects(junkList)

                rs.EnableRedraw(True)
示例#26
0
 def genFuncObj_Site(self):
     s = site_obj(self.site)
     pts = s.getPts()
     s.displayPts()
     poly_list = []
     for i in self.req_obj:
         for j in range(i.getNumber()):
             obj = i
             T = False
             k = 0
             this_gen_poly = None
             while (T == False and k < 100):
                 x = random.randint(1, len(pts) - 2)
                 p = pts[x - 1]
                 q = pts[x]
                 r = pts[x + 1]
                 poly = obj.getConfig1(p, q, r)
                 sum = 0
                 if (poly is not None and len(poly) > 0):
                     sum = 0
                     if (poly_list and len(poly_list) > 0):
                         for m in poly_list:
                             polyY = rs.AddPolyline(m)
                             G = self.checkPoly(poly, polyY)
                             rs.DeleteObject(polyY)
                             if (G == False):
                                 sum += 1
                                 break
                         if (sum == 0):
                             T = True
                             if (poly not in poly_list):
                                 this_gen_poly = poly
                                 poly_list.append(poly)
                     elif (poly is not None and len(poly) > 0):
                         if (poly not in poly_list):
                             this_gen_poly = poly
                             poly_list.append(poly)
                 k += 1
             if (this_gen_poly is not None):
                 if (len(this_gen_poly) > 0):
                     i.setGenPoly(
                         rs.AddPolyline(this_gen_poly))  #boundary-poly
     counter = 0
     for i in self.req_obj:
         poly = i.getGenPoly()  # n boundary poygons are created from input
         if (poly is not None and len(poly) > 0):
             for j in poly:  # for each poly in bounding-poly get internal-poly
                 counter2 = 0
                 i.genIntPoly(
                     j
                 )  # iterate over the first poly then second, this time there are 2 polys
                 npoly = i.getReqPoly()
             for j in i.getReqPoly():
                 li = []
                 for k in range(i.getNumFloors()):
                     c = rs.CopyObjects(j, [0, 0, 4 * k])
                     rs.ObjectLayer(c, "garbage")
                     li.append(c)
                 try:
                     srf = rs.AddLoftSrf(li)
                     rs.CapPlanarHoles(srf)
                     rs.ObjectColor(srf, i.getColr())
                     i.addSrf(srf)
                 except:
                     pass
示例#27
0
def revolve_border(border, axis, start, end):
    res = rh.AddRevSrf(border, axis, start, end)
    rh.CapPlanarHoles(res)
    rh.DeleteObject(border)
    return res
示例#28
0
    z = xyz[2]
    dphi = 2 * ma.pi / 100
    for k in range(0, 101):
        phi = k * dphi
        x = (R + a * (ma.cos(n * phi) - 1)) * ma.cos(phi)
        y = (R + a * (ma.cos(n * phi) - 1)) * ma.sin(phi)
        points.append([x, y, z])
    sections.append(rs.AddInterpCurve(points))
top = rs.EvaluateCurve(curve, domain[1])
plane = rs.PlaneFromNormal(top, [0, 0, 1])
sections.append(rs.AddCircle(plane, 1))

rs.AddLayer("Cactus")
rs.CurrentLayer("Cactus")
surf = rs.AddLoftSrf(sections)
rs.CapPlanarHoles(surf)

#Draw spines
cone = rs.AddCone([0, 0, -sh], sh, sr)
basis = []
theta = ma.pi / 8
dphi = 2 * ma.pi / m
for k in range(0, m):
    phi = k * dphi
    x = ma.sin(theta) * ma.cos(phi)
    y = ma.sin(theta) * ma.sin(phi)
    z = ma.cos(theta)
    matrix = rs.XformRotation3([0, 0, 1], [x, y, z], [0, 0, 0])
    basis.append(rs.TransformObject(cone, matrix, True))
rs.DeleteObject(cone)
示例#29
0
#Create group
rs.AddGroup("Legs")
rs.AddObjectsToGroup(Legs, "Legs")

#Construct the table top, draw offset curve
offset_crv = rs.OffsetCurve(Poly_top,
                            Cen_top,
                            -(offset_dist),
                            normal=None,
                            style=1)

rs.CurrentLayer("Tabletop")
#extrude Offset Curve
extruded_crv = rs.ExtrudeCurve(offset_crv, extrude_path)

#cap Extruded shape
closed_polysrf = rs.CapPlanarHoles(extruded_crv)

#Delete objects
erase = [A_lines, Poly_base, Poly_top, offset_crv]
rs.DeleteObjects(erase)

#Redraw geometry
rs.EnableRedraw(True)

#zoom extents of drawn geometry
rs.ZoomExtents()

rs.CurrentLayer("Default")

print("***************Program succesful***************")
示例#30
0
normal = rs.SurfaceNormal(miterFace, param)
miterEndPoint = intersectPoints[0] + normal
miterVector = normal

line = rs.AddLine(outerEndPoint, miterEndPoint)
rs.HideObject(line)
midPoint = rs.CurveMidPoint(line)

normalVector = rs.VectorCrossProduct(outerVector, miterVector)

cutPlane = rs.AddCutPlane(solid, intersectPoints[0], midPoint, normal = normalVector)
rs.HideObject(cutPlane)

splitSolids = rs.SplitBrep(solid, cutPlane, True)

rs.CapPlanarHoles(splitSolids[0])
rs.CapPlanarHoles(splitSolids[1])

if  rs.SurfaceArea(splitSolids[0]) > rs.SurfaceArea(splitSolids[1]):
    rs.DeleteObject(splitSolids[1])
else:
    rs.DeleteObject(splitSolids[0]) 

if not solid2:
    x = 0
else: 
    splitSolids = rs.SplitBrep(solid2, cutPlane, True)

    rs.CapPlanarHoles(splitSolids[0])
    rs.CapPlanarHoles(splitSolids[1])