def PlaceInstance(file, x, y, mirror, rotate):
    rs.Command("_-Insert _File=_Yes " + root + "packages/" + file +
               ".3dm B 0,0,0 1 0 _Enter")
    objects = rs.SelectedObjects()
    if not len(objects):
        return None
    object = objects[0]
    rs.UnselectAllObjects()
    rs.RotateObject(object, (0, 0, 0), rotate)
    if mirror:
        rs.RotateObject(object, (0, 0, 0), 180, (0, 1, 0))
        rs.MoveObject(object, (0, 0, -boardThickness))
    rs.MoveObject(object, (x, y, 0))
    return object
Beispiel #2
0
def MoveToRL():
    try:
        # Determine Unit system and scale m input to unit system scale and close if not mm, cm, m
        def scale():
            system = rs.UnitSystem()
            if system == 2 or system == 3 or system == 4:
                scaleFactorDict = {2: 1000, 3: 100, 4: 1}
                scaleFactor = scaleFactorDict[system]
                return scaleFactor

            if system != 2 or system != 3 or system != 4:
                return None

        if scale() == None:
            rs.MessageBox(
                "This tool is can only be used in mm, cm or m model units")
            return None

        obj = rs.GetObjects('Select objects', preselect=True)
        if obj:
            current = rs.GetPoint('Select point')

            if current:
                rl = rs.GetString('RL to move to?')
                rl = float(rl)
                rl = rl * scale()

                if rl == 0:  # move objects to the 0 coord
                    target3 = current.Z
                    if target3:
                        target3 = target3 * -1
                        target4 = geo.Point3d(0, 0, target3)
                        rs.MoveObject(obj, target4)

                elif rl < 0:
                    target5 = rl - current.Z
                    target6 = geo.Point3d(0, 0, target5)
                    rs.MoveObject(obj, target6)

                elif rl > 0:
                    target = rl - current.Z  # + or - number to target location
                    # translated vector needed to hit target
                    target2 = geo.Point3d(0, 0, target)
                    rs.MoveObject(obj, target2)

    except:
        print("Failed to execute")
        rs.EnableRedraw(True)
        return
Beispiel #3
0
def PlaceInstance(file, x, y, mirror, rotate):
    rs.Command(
        "_-Insert _File=_Yes /Users/denis/sandbox/denisbohm/firefly-ice-mechanical/scripts/packages/"
        + file + ".3dm B 0,0,0 1 0 _Enter")
    objects = rs.SelectedObjects()
    if not len(objects):
        return None
    object = objects[0]
    rs.UnselectAllObjects()
    rs.RotateObject(object, (0, 0, 0), rotate)
    if mirror:
        rs.RotateObject(object, (0, 0, 0), 180, (0, 1, 0))
        rs.MoveObject(object, (0, 0, -boardThickness))
    rs.MoveObject(object, (x, y, 0))
    return object
Beispiel #4
0
    def proof_placement(self, checkbuildspace=True):

        # color objects
        self.correctplacement = True

        print 'Moving to zero level'
        for obj in self.objIds:
            BB = rs.BoundingBox(obj)
            rs.MoveObject(obj, [0, 0, -BB[0][2]])
            BB = rs.BoundingBox(obj)
            if checkbuildspace:
                print 'Checking positioning'

                for point in BB:
                    if point[0] < 0 or point[0] > 241:
                        rs.ObjectColor(obj, (255, 0, 0))
                        self.correctplacement = False
                        break
                    else:
                        rs.ObjectColor(obj, (0, 255, 0))

                    if point[1] < 0 or point[1] > 209:
                        rs.ObjectColor(obj, (255, 0, 0))
                        self.correctplacement = False
                        break
                    else:
                        rs.ObjectColor(obj, (0, 255, 0))

                    if point[2] < 0 or point[2] > 205:
                        rs.ObjectColor(obj, (255, 0, 0))
                        self.correctplacement = False
                        break
                    else:
                        rs.ObjectColor(obj, (0, 255, 0))
Beispiel #5
0
def CheckRunLengths(runs):
    lengthComment = ''
    for i, run in enumerate(runs):
        dist = rs.Distance(rs.CurveStartPoint(run[0]),
                           rs.CurveStartPoint(run[1]))
        if dist > 360:
            lengthComment += 'Run {} requires a landing\n'.format(i + 1)
            templine = rs.AddLine(rs.CurveStartPoint(run[0]),
                                  rs.CurveStartPoint(run[1]))
            mdPt = rs.CurveMidPoint(templine)
            vec = rs.VectorCreate(mdPt, rs.CurveStartPoint(run[0]))
            landingCenter = rs.CopyObject(run[0], vec)
            vec = rs.VectorScale(rs.VectorUnitize(vec), 30)
            upperLine = rs.CopyObject(landingCenter, vec)
            vec = rs.VectorReverse(vec)
            lowerLine = rs.MoveObject(landingCenter, vec)
            rs.DeleteObject(templine)
            run.insert(1, lowerLine)
            run.insert(2, upperLine)

    flatList = []
    for item in runs:
        for each in item:
            flatList.append(each)

    pairs = []
    for i in range(0, len(flatList), 2):
        pairs.append([flatList[i], flatList[i + 1]])
    return pairs, lengthComment
Beispiel #6
0
def GenStaggeredCourtyardBlock(site_crv, setback, stepbacks, bay_gap, fsr_li,
                               flr_depth):
    bldg_srf_li = []
    outer_setback_crv = rs.OffsetCurve(site_crv,
                                       rs.CurveAreaCentroid(site_crv)[0],
                                       setback)
    inner_floor_crv = rs.OffsetCurve(site_crv,
                                     rs.CurveAreaCentroid(site_crv)[0],
                                     setback + flr_depth)
    req_ht = (rs.CurveArea(site_crv)[0] * fsr_li[0]) / (
        rs.CurveArea(outer_setback_crv)[0] - rs.CurveArea(inner_floor_crv)[0])
    l = rs.AddLine([0, 0, 0], [0, 0, req_ht])
    srf = rs.AddPlanarSrf([outer_setback_crv, inner_floor_crv])
    srf2 = rs.ExtrudeSurface(srf, l)
    rs.DeleteObject(l)
    prev_ht = req_ht
    k = 1
    for depth in stepbacks:
        req_ar = rs.CurveArea(site_crv)[0] * fsr_li[k]
        itr_stepback_crv = rs.OffsetCurve(site_crv,
                                          rs.CurveAreaCentroid(site_crv)[0],
                                          setback + depth)
        got_ar = rs.CurveArea(itr_stepback_crv)[0] - rs.CurveArea(
            inner_floor_crv)[0]
        ht = req_ar / got_ar
        l = rs.AddLine([0, 0, 0], [0, 0, ht])
        srf = rs.AddPlanarSrf([itr_stepback_crv, inner_floor_crv])
        srf2 = rs.ExtrudeSurface(srf, l)
        rs.MoveObject(srf2, [0, 0, prev_ht])
        rs.DeleteObject(l)
        rs.DeleteObject(srf)
        bldg_srf_li.append(srf2)  #
        prev_ht += ht
        k += 1
Beispiel #7
0
def GenStagerredBlock(site_crv, setback, stepbacks, bay_gap, fsr_li,
                      flr_depths):
    bldg_srf_li = []
    setback_crv = rs.OffsetCurve(site_crv,
                                 rs.CurveAreaCentroid(site_crv)[0], setback)
    ht = fsr_li[0] * rs.CurveArea(site_crv)[0] / rs.CurveArea(setback_crv)[0]
    pl_srf0 = rs.AddPlanarSrf(setback_crv)
    l = rs.AddLine([0, 0, 0], [0, 0, ht])
    ext_srf = rs.ExtrudeSurface(pl_srf0, l)
    rs.DeleteObjects([l, pl_srf0])
    k = 1
    for depth in stepbacks:
        stepback_crv = rs.OffsetCurve(setback_crv,
                                      rs.CurveAreaCentroid(site_crv)[0], depth)
        ht2 = rs.CurveArea(site_crv)[0] * fsr_li[k] / rs.CurveArea(
            stepback_crv)[0]
        l = rs.AddLine([0, 0, 0], [0, 0, ht2])
        pl_srf = rs.AddPlanarSrf(stepback_crv)
        ext_srf = rs.ExtrudeSurface(pl_srf, l)
        rs.MoveObject(ext_srf, [0, 0, ht])
        bldg_srf_li.append(ext_srf)
        rs.DeleteObject(l)
        rs.DeleteObject(pl_srf)
        ht += ht2
        k += 1
def setSensorLocation():
    projectedPtList = []

    # Select boundary surface
    boundarySrf = rs.GetObject("Select surface for making boundary",
                               rs.filter.surface)

    # For making location point with grid
    direction = (0, 0, 100)
    plane = rs.MoveObject(boundarySrf, direction)

    # Dividing surface to points
    ptList = ArrayPointsOnSurface(plane)

    # point projection
    projectedSrf = rs.GetObject("Select surface for projection",
                                rs.filter.surface)
    for point in ptList:
        pointsOnModel = rs.ProjectPointToSurface(point, projectedSrf,
                                                 (0, 0, 1))
        projectedPt = rs.AddPoint(pointsOnModel[0][0], pointsOnModel[0][1],
                                  pointsOnModel[0][2])
        projectedPtList.append(projectedPt)

    rs.DeleteObjects(plane)
    rs.DeleteObjects(ptList)

    return projectedPtList
 def goto(self, x, y):
     prevPos = rs.PointCoordinates(self.point)
     movement = rs.VectorCreate([x,y,0],prevPos)
     rs.MoveObject(self.point,movement)
     currentPos = rs.PointCoordinates(self.point)
     gotoLine = rs.AddLine(prevPos,currentPos)
     rs.DeleteObject(gotoLine)
 def forward(self, magnitude):
     print self.direction
     movement = rs.VectorScale(self.direction, magnitude)
     prevPos = rs.PointCoordinates(self.point)
     rs.MoveObject(self.point, movement)
     currentPos = rs.PointCoordinates(self.point)
     rs.AddLine(prevPos, currentPos)
 def getExtendedCrv(self, crvList, dist=50, layer_height=2.5, vecMul=.66):
     segmentCount = int(math.floor(dist / layer_height)) - 1
     tmpList = []
     fullHeight = []
     for i in range(len(crvList)):
         extendedCrv = rs.ExtendCurveLength(crvList[i], 2, 0, dist)
         fullHeight.append(extendedCrv)
         domStart, domEnd = rs.CurveDomain(extendedCrv)
         trimmedCrv = rs.TrimCurve(extendedCrv, (domStart, 0))
         tmpList.append(trimmedCrv)
     tmp = []
     ###Smooth Curves###
     for i in range(len(tmpList)):
         bottomPt = rs.CurveEndPoint(tmpList[i])
         zVec = rs.VectorAdd((0, 0, 0), (0, 0, dist))
         topPt = rs.CopyObject(bottomPt, zVec)
         line = rs.AddLine(bottomPt, topPt)
         crvPts = rs.DivideCurve(tmpList[i], segmentCount)
         LinePts = rs.DivideCurve(line, segmentCount)
         for i in range(segmentCount):
             tmpVec = rs.VectorCreate(LinePts[segmentCount - i - 1],
                                      crvPts[i])
             tmpVec = rs.VectorScale(tmpVec, vecMul)
             rs.MoveObject(crvPts[i], tmpVec)
         tmp.append(rs.AddInterpCurve(crvPts))
         result = []
         for crv in tmp:
             crvLen = rs.CurveLength(crv)
             if crvLen < dist:
                 tmpExt = dist - crvLen
                 result.append(rs.ExtendCurveLength(crv, 2, 0, tmpExt))
             else:
                 result.append(rs.CopyObject(crv))
     return result
Beispiel #12
0
def Run(xNum, yNum):
    if xNum is None:
        rs.MessageBox("No number provided for x")
        return
    if yNum is None:
        rs.MessageBox("No number provided for y")
        return

    rs.EnableRedraw(False)
    boxes = []
    for i in range(xNum):
        for n in range(yNum):
            points = []
            for s in range(2):
                for t in range(4):
                    x = math.cos(math.radians(45 + 90 * t)) * math.sqrt(2)
                    y = math.sin(math.radians(45 + 90 * t)) * math.sqrt(2)
                    z = -1 + 2 * s
                    point = geo.Point3d(x, y, z)
                    points.append(point)
            box = rs.AddBox(points)

            box = rs.RotateObject(box, geo.Point3d(0, 0, 0),
                                  90 / (xNum - 1) * i, geo.Vector3d.ZAxis)
            box = rs.RotateObject(box, geo.Point3d(0, 0, 0),
                                  90 / (yNum - 1) * n, geo.Vector3d.XAxis)

            box = rs.MoveObject(box, geo.Vector3d(4 * i, 4 * n, 0))
            boxes.append(box)
    rs.EnableRedraw(True)

    return boxes


#Run()
Beispiel #13
0
 def forward(self, magnitude):
     movement = rs.VectorScale(self.direction, magnitude)
     prevPos = rs.PointCoordinates(self.point)
     rs.MoveObject(self.point, movement)
     currentPos = rs.PointCoordinates(self.point)
     line = self.drawLine(prevPos, currentPos)
     return line
Beispiel #14
0
    def deflect(self, deflectPoint):
        """
        Takes a Point as an input.
        Point creates a force field.
        The turtle deflects around the point
        """
        defPtPos = rs.PointCoordinates(deflectPoint)
        prevPos = rs.PointCoordinates(self.point)
        deflectVector1 = rs.VectorScale(rs.VectorCreate(prevPos, defPtPos),
                                        0.33)
        deflectVector2 = -deflectVector1
        deflectVector90_1 = rs.VectorScale(
            rs.VectorRotate(deflectVector1, 90, [0, 0, 1]), 0.33)
        deflectVector90_2 = -deflectVector90_1

        deflectVectorList = [
            deflectVector1, deflectVector2, deflectVector90_1,
            deflectVector90_2
        ]

        forcePts = []
        for i in deflectVectorList:
            newPt = rs.CopyObject(deflectPoint)
            rs.MoveObject(newPt, i)
            forcePts.append(newPt)

        gotoPt = rs.PointCoordinates(forcePts[0])

        self.goto(gotoPt[0], gotoPt[1])
        rs.AddArc3Pt(forcePts[0], forcePts[1], forcePts[2])
        rs.AddArc3Pt(forcePts[1], forcePts[0], forcePts[3])
        rs.DeleteObjects(forcePts)
Beispiel #15
0
def ColorAndMove(object, layer):
    index = rs.AddMaterialToObject(object)
    if layer == 1:
        rs.MaterialColor(index, (255, 0, 0))
    if layer == 16:
        rs.MaterialColor(index, (0, 0, 255))
        rs.MoveObject(object, (0, 0, -boardThickness - 0.1))
Beispiel #16
0
def Build_Key(Point, colors, tol):
    """
    Build key for tolerance shading.
    Create color coded text objects and planes.
    """
    low2 = "-" + str(tol[2]) + '"' + " and lower"
    low1 = "-" + str(tol[2]) + '"' + " to -" + str(tol[1]) + '"'
    low0 = "-" + str(tol[1]) + " to -" + str(tol[0]) + '"'
    good = "-" + str(tol[0]) + " to +" + str(tol[0]) + '"'
    high0 = "+" + str(tol[0]) + " to +" + str(tol[1]) + '"'
    high1 = "+" + str(tol[1]) + " to +" + str(tol[2]) + '"'
    high2 = "+" + str(tol[2]) + " and higher"

    stringList = [high2, high1, high0, good, low0, low1, low2]
    objs = []
    for i in range(len(stringList)):
        pt = rs.coerce3dpoint([0, 0, 1.5 * i + 3])
        plane = rs.PlaneFromNormal(pt + Point, [0, -1, 0], [1, 0, 0])
        txt = rs.AddText(stringList[i], plane)
        srf = rs.AddPlaneSurface(plane, 1, 1)
        rs.MoveObject(srf, [-2, 0, 0])
        stringColor = "Tol_" + colors[i].ToString().split("[")[1].rstrip("]")

        mt.OrganizeLayer(stringColor,
                         Objects=[srf, txt],
                         Render=colors[i],
                         Color=colors[i])
Beispiel #17
0
def filterObjects(objs):
    new_list = []
    for obj in objs:
        if rs.LayerVisible( rs.ObjectLayer(obj) ):
            # only export visible layers
            if rs.IsCurve(obj):
                new_list.append(obj)

            elif rs.IsPoint(obj):
                # convert to circle
                layer = rs.ObjectLayer(obj)
                point=rs.coerce3dpoint(obj)

                circle = rs.AddCircle(rs.WorldXYPlane(),3)

                rs.ObjectLayer(circle, layer)
                rs.MoveObject(circle, [point.X, point.Y, point.Z])
                new_list.append(circle)
                rs.DeleteObject(obj)
                # rs.DeleteObject(point)

            else:
                # remove from obj list
                rs.DeleteObject(obj)
        else:
            # remove from obj list
            rs.DeleteObject(obj)

    return new_list
Beispiel #18
0
def areaTag(pline):
    #get area
    area = rs.CurveArea(pline)[0]
    area = str((int(area * 100)) / 100) + "m2"
    print area

    #move area tag below name tag location
    offset = [0, -2.5, 0]

    #add text tag
    objID = pline
    text = '%<area("' + str(objID) + '")>%m2'

    pt = rs.AddPoint(rs.CurveAreaCentroid(pline)[0])
    rs.MoveObject(pt, offset)
    areaTag = rs.AddText(text, pt, 1, justification=131074)
    rs.DeleteObject(pt)

    parentLayer = rs.ParentLayer(rs.ObjectLayer(pline))
    hostLayer = rs.AddLayer("ANNO_AREA", (128, 128, 128), parent=parentLayer)
    rs.ObjectLayer(areaTag, hostLayer)

    te = rs.coercerhinoobject(areaTag, True, True)
    te.Geometry.TextFormula = text
    te.CommitChanges()
    sc.doc.Views.Redraw()
    return None
Beispiel #19
0
        def FromEdgetoPlane():
            PointPlane = []
            CurveIdList = []
            Brep = []
            edges = rs.GetEdgeCurves()
            if edges:
                for edgeinfo in edges:

                    Brep.append(edgeinfo[1])
                    CurveIdList.append(edgeinfo[0])

            for CurveId in CurveIdList:

                if rs.IsCircle(CurveId):

                    Pt = rs.CircleCenterPoint(CurveId)
                    Normal = rs.CurveNormal(CurveId)
                    LenghtNormal = rs.VectorLength(Normal)
                    LenghNormal = self.m_foronumero.Text
                    LenghNormal = int(LenghNormal)
                    Normal = (LenghNormal * Normal[0], LenghNormal * Normal[1],
                              LenghNormal * Normal[2])
                    PtStill = rs.AddPoint(Pt)

                    Ptmoved = rs.MoveObject(Pt, Normal)
                    Ptmoved = rs.coerce3dpoint(Ptmoved)
                    PtStill = rs.coerce3dpoint(PtStill)

                    PointPlane.append([
                        PtStill[0], PtStill[1], PtStill[2], Normal[0],
                        Normal[1], Normal[2]
                    ])
                    #PointPlane.append([Ptmoved[0],Ptmoved[1],Ptmoved[2],Normal[0],Normal[1],Normal[2]])
            return (PointPlane, Brep)
def squareSect(crv,width,height):
    sections=[]
    divPts=rs.DivideCurve(crv,10)
    keep=True
    for i in range(len(divPts)):
        param=rs.CurveClosestPoint(crv,divPts[i])
        tan=rs.CurveTangent(crv,param)
        plane=rs.PlaneFromNormal(divPts[i],tan)
        sect=rs.AddRectangle(plane,width,height)
        cpt=rs.CurveAreaCentroid(sect)[0]
        vec=rs.VectorCreate(divPts[i],cpt)
        sect=rs.MoveObject(sect,vec)
        if i>0:
            if testAlign(sect,oldSect)==False:
                sect=align(sect,oldSect,divPts[i],tan)
        oldSect=sect
        sections.append(sect)
    branch=rs.AddLoftSrf(sections,None,None,2,0,0,False)
    edges=rs.DuplicateEdgeCurves(branch)
    if width>height:
        testVal=height
    else:
        testVal=width
    for i in range(len(edges)):
        testPt=rs.CurveMidPoint(edges[i])
        for j in range(len(edges)):
            param=rs.CurveClosestPoint(edges[j],testPt)
            pt=rs.EvaluateCurve(edges[j],param)
            if rs.Distance(pt,testPt)<testVal/6:
                keep=False
    rs.DeleteObjects(sections)
    rs.DeleteObjects(edges)
    return branch
Beispiel #21
0
    def unroll(self):
        x = 0

        for i in range(len(self.srfList)):
            g = rs.AddGroup()

            s, p = rs.UnrollSurface(self.srfList[i], False, self.unrollList[i])

            s = rs.JoinSurfaces(s, True)

            p = rs.MoveObjects(p, [x, self.name * 10, 0])
            s = rs.MoveObject(s, [x, self.name * 10, 0])

            b = rs.DuplicateSurfaceBorder(s, 1)

            rs.ObjectLayer(b, "cut")

            rs.AddObjectsToGroup(b, g)
            rs.AddObjectsToGroup(p, g)

            bb = rs.BoundingBox(s)
            x += fabs(bb[0].X - bb[1].X) + 1

            t = rs.AddText(
                str(self.name) + "-" + str(i),
                util.averagePt(rs.CurvePoints(b)), 0.3)

            t = util.makeEngravingFont(t)

            rs.AddObjectsToGroup(t, g)

            rs.DeleteObjects(s)
Beispiel #22
0
 def MoveWithVector (treeIn, profPointTreeIn, vectorTreeIn, thicknessIn, angleIn, treeOut):
     
     profMax = GridCornerBig (profPointTreeIn)
     profMin = GridCornerSmall (profPointTreeIn)
     
     max =  GridCornerBig (treeIn)
     
     
     for i in range(treeIn.BranchCount):
         treeBranch = treeIn.Branch(i)
         treePath = treeIn.Path(i)
         
         profBranch = profPointTreeIn.Branch(i)
         vectorBranch = vectorTreeIn.Branch(i)
         thicknessBranch = thicknessIn.Branch(i)
         angleBranch = angleIn.Branch(i)
         
         for j in range(treeBranch.Count):
             elem = treeBranch[j]
             profPoint = profBranch [j]
             vector = vectorBranch [j]
             v = thicknessBranch [j]
             angle = angleBranch [j]
             
             
             if type != 0:
                 elemLapos = rs.AddPoint (elem.X,elem.Y,0)
                 elemLapos = rs.coerce3dvector (elemLapos)
                 
                 #angle = rs.VectorAngle ([1,0,0], elemLapos)
                 betaRad = math.radians (beta)
                 
                 gammaRad = math.radians (angle)
                 
                 if gammaRad > betaRad/2:
                     gammaRad = gammaRad - betaRad/2
                 else:
                     gammaRad = betaRad/2 - gammaRad
                 
                 v = (math.cos (betaRad/2)) / (math.cos (gammaRad)) *v
             
             vec = rs.coerce3dpoint (vector)
             rotVecX = vec.X
             rotVecZ = vec.Y
             rotVecY = vec.Z
             rotVec = rs.AddPoint (rotVecX, rotVecY, rotVecZ)
             rotVec = rs.coerce3dpoint (rotVec)
             ORIGO = rs.AddPoint (0,0,0)
             ORIGO = rs.coerce3dpoint (ORIGO)
             VECTOR = rs.RotateObject(rotVec, ORIGO, angle, [0,0,1])
             
             vector = rs.coerce3dvector (VECTOR)
             vector = vector * v
             
             elem = rs.coerce3dpoint (elem)
             
             MovePoint = rs.MoveObject (elem, vector)
             MovePoint = rs.coerce3dpoint (MovePoint)
             
             treeOut.Add (elem, treePath)
Beispiel #23
0
 def goto(self, x, y, z=0):
     prevPos = rs.PointCoordinates(self.point)
     movement = rs.VectorCreate([x, y, z], prevPos)
     rs.MoveObject(self.point, movement)
     currentPos = rs.PointCoordinates(self.point)
     line = self.drawLine(prevPos, currentPos)
     return line
Beispiel #24
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
Beispiel #25
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
Beispiel #26
0
def modify_input(filename):

    # Import object from file
    join_string = str(input_directory + filename)
    combined_string = '!_Import ' + '"' + join_string + '"'
    rs.Command(combined_string)

    # Get all objects imported
    objs = rs.LastCreatedObjects(select=False)[0]

    # Close curve
    closed_curve = rs.CloseCurve(objs, 0.5)
    rs.DeleteObject(objs)

    # Rebuild curve to create smoother shape
    rs.RebuildCurve(closed_curve, 3, 100)

    # Pipe figure with radius of 0.25
    piped = rs.AddPipe(closed_curve, 0, 0.4)[0]

    rs.MoveObject(piped, [0, 0, 0])

    bounding_pts = rs.BoundingBox([piped], view_or_plane=rs.WorldXYPlane())

    maxX = 0
    minX = 0
    minY = 0
    minZ = 0
    for pt in bounding_pts:
        if pt[0] < minX:
            minX = pt[0]
        if pt[0] > maxX:
            maxX = pt[0]
        if pt[1] < minY:
            minY = pt[1]
        if pt[2] < minZ:
            minZ = pt[2]

    rect = rs.AddRectangle(rs.WorldXYPlane(), abs(maxX - minX), 3.0)
    rs.MoveObject(rect, [minX, minY - 3.0, minZ])
    rs.AddPipe(rect, 0, 0.4)
    rs.DeleteObject(closed_curve)
    rs.DeleteObject(rect)

    export_string = '!_Export ' + '"' + str(output_directory + filename) + '"'
    rs.Command(export_string)
def createSlits(data, width, height):
    for i in range(0, len(data)):
        rect = rs.AddRectangle(rs.WorldXYPlane(), width, height)
        rs.MoveObject(rect, [data[i][0], data[i][2], 0])

    export_string = '!_Export ' + '"' + str(output_directory +
                                            'placements') + '"'
    rs.Command(export_string)
Beispiel #28
0
def MakeHandrailFromRuns(run, HDRLoffset):
    pt1 = rs.CurveStartPoint(run[0])
    pt2 = rs.CurveStartPoint(run[1])

    pt3 = rs.CurveEndPoint(run[0])
    pt4 = rs.CurveEndPoint(run[1])

    crossVec = rs.VectorCreate(pt3, pt1)
    crossVec = rs.VectorUnitize(crossVec)
    crossVec = rs.VectorScale(crossVec, HDRLoffset)

    edge1 = rs.AddLine(pt1, pt2)
    edge2 = rs.AddLine(pt3, pt4)
    edge1 = rs.MoveObject(edge1, crossVec)
    edge2 = rs.MoveObject(edge2, rs.VectorReverse(crossVec))

    return [edge1, edge2]
Beispiel #29
0
    def GenerateLiftingSurface(self, ChordFactor, ScaleFactor, OptimizeChordScale=0):
        # This is the main method of this class. It builds a lifting surface
        # (wing, tailplane, etc.) with the given ChordFactor and ScaleFactor or
        # an optimized ChordFactor and ScaleFactor, with the local search started
        # from the two given values.

        x0 = [ChordFactor, ScaleFactor]

        if OptimizeChordScale:
            self._CheckOptParCorrectlySpec()
            self._NormaliseWeightings()
            self._PrintTargetsAndWeights()
            print("Optimizing scale factors...")
            # An iterative local hillclimber type optimizer is needed here. One
            # option might be SciPy's fmin as below:
            # x0, fopt, iter, funcalls, warnflag, allvecs = scipy.optimize.fmin(self._LSObjective, x0, retall=True, xtol=0.025, full_output=True)
            # However, SciPy is not supported on 64-bit Rhino installations, so
            # so here we use an alternative: a simple evoltionary optimizer
            # included with AirCONICS_tools.
            MaxIter = 50
            xtol = 0.025
            deltax = [x0[0]*0.25,x0[1]*0.25]
            x0, fopt = act.boxevopmin2d(self._LSObjective, x0, deltax, xtol, MaxIter)
            x0[0] = abs(x0[0])
            x0[1] = abs(x0[1])
            print("Optimum chord factor %5.3f, optimum scale factor %5.3f" % (x0[0], x0[1]))

        LS, ActualSemiSpan, LSP_area,  RootChord, AR, WingTip = self._BuildLS(x0[0], x0[1])

        self._ClearConstructionGeometry()

        # Moving the wing into position
        AP = rs.AddPoint(self.ApexPoint)
        MoveVec = rs.VectorCreate(AP, (0,0,0))
        rs.MoveObject(LS, MoveVec)
        if WingTip:
            rs.MoveObject(WingTip, MoveVec)
        rs.DeleteObject(AP)

        # FINAL REPORT ON THE COMPLETED SURFACE
        SA  = rs.SurfaceArea(LS)
        print("Wing complete. Key features (all related to both wings):")
        print("Proj.area: %5.4f   Wet.area: %5.4f   Span:%5.4f  Aspect ratio:  %5.4f  Root chord: %5.4f" % (2*LSP_area, 2.0*SA[0], 2.0*ActualSemiSpan, AR, RootChord))

        return LS, ActualSemiSpan, LSP_area,  RootChord, AR, WingTip
def makeHeight(pt, val):
    originalPt = rs.CopyObject(pt)
    vector = (0, 0, val)
    movedPt = rs.MoveObject(pt, vector)

    line = [originalPt, movedPt]
    lineID = rs.AddLine(line[0], line[1])

    return lineID