def ProjectOnSrfLoose():
    crv = rs.GetObject("select curve to loosely project", rs.filter.curve)
    srf = rs.GetObject("Select surface to loosely project onto",
                       rs.filter.surface)
    if crv == None or srf == None:
        return
    degree = rs.CurveDegree(crv)
    bPeriodic = False
    pts = rs.CurvePoints(crv)
    if rs.IsCurvePeriodic(crv):
        pts = rs.CullDuplicatePoints(pts, 0.01)
        bPeriodic = True

    pts_projected = []
    curveplane = rs.CurvePlane(crv)
    projection_dir = curveplane.ZAxis

    for pt in pts:

        pp = rs.ProjectPointToSurface(pt, srf, projection_dir)
        if len(pp) > 0:
            pt_projected = pp[0]
            pts_projected.append(pt_projected)
    if len(pts_projected) <= 2:
        return
    if len(pts_projected) < len(pts):
        bPeriodic = False
    nc = Rhino.Geometry.NurbsCurve.Create(bPeriodic, degree, pts_projected)
    sc.doc.Objects.AddCurve(nc)
    sc.doc.Views.Redraw()
Example #2
0
def get_boundary_points(crvs_bound,trg_len):
    crvs = rs.ExplodeCurves(crvs_bound,True)
    if not crvs:  crvs = [crvs_bound]
    div_pts = []
    for crv in crvs:
        div = round(rs.CurveLength(crv)/trg_len,0)
        if div < 1: div = 1
        pts = rs.DivideCurve(crv,div)
        div_pts += pts
        
    div_pts = rs.CullDuplicatePoints(div_pts)
    if crvs: rs.DeleteObjects(crvs)
    return div_pts    
        Beams.append(Beam)
    return Beams


# Excecute the Code
ListBeams = rs.GetObjects("GetLine", rs.filter.curve)

ListPts = []
for i in ListBeams:
    StPt = rs.CurveStartPoint(i)
    ListPts.append(StPt)
    EdPt = rs.CurveEndPoint(i)
    ListPts.append(EdPt)

if ListPts:
    ListPts = rs.CullDuplicatePoints(ListPts)
    #rs.AddPoints(ListPts)

    #getting Neighbour elements

    LstNodeBeams = []
    for n in ListPts:
        NeiBeamList = []
        for l in ListBeams:
            EndL = rs.CurveEndPoint(l)
            StEl = rs.CurveStartPoint(l)
            if rs.Distance(n, EndL) < 0.2 or rs.Distance(n, StEl) < 0.2:
                NeiBeamList.append(l)

        LstNodeBeams.append(NeiBeamList)
Example #4
0
def OffsetCrvLoose():

    crv = rs.GetObject("select curve to offset loosely", rs.filter.curve, True)
    if crv == None:
        return
    if not rs.IsCurvePlanar(crv):
        print "Sorry, but that curve is not planar."
        return
    if rs.IsPolyCurve(crv):
        print "This simple script works only for single open or closed curves"
        return
    offset = rs.GetReal("offset amount", 5)

    if offset == None or offset == 0:
        return
    both_sides = rs.GetBoolean("Offset both sides?",
                               ["both_sides", "off", "on"], False)[0]
    bPeriodic = False
    #rs.EnableRedraw(False)
    pts = rs.CurvePoints(crv)
    degree = rs.CurveDegree(crv)
    if rs.IsCurvePeriodic(crv):
        pts = rs.CullDuplicatePoints(pts, 0.01)
        bPeriodic = True
    offset_pts = []
    offset_pts2 = []  #if both_sides=true
    plane = rs.CurvePlane(crv)
    axis = plane.ZAxis
    for pt in pts:
        cp = rs.CurveClosestPoint(crv, pt)
        v = rs.CurveTangent(crv, cp)
        v = rs.VectorUnitize(v)
        v *= offset
        v = rs.VectorRotate(v, 90, axis)
        pt_ = rs.AddPoint(pt)
        #create points for offset on one side of the curve
        movedpt = rs.MoveObject(pt_, v)
        newpt = rs.coerce3dpoint(movedpt)
        offset_pts.append(newpt)
        #create points for offset on other side of the curve
        movedpt = rs.MoveObject(pt_, -2 * v)
        newpt = rs.coerce3dpoint(movedpt)
        offset_pts2.append(newpt)
        rs.DeleteObject(pt_)
    nc = Rhino.Geometry.NurbsCurve.Create(bPeriodic, degree, offset_pts)
    nc2 = Rhino.Geometry.NurbsCurve.Create(bPeriodic, degree, offset_pts2)

    if not both_sides:
        if nc.GetLength(0.1) > nc2.GetLength(0.1):  #get the longest curve...
            if offset > 0:  #...and add it to the document for positive offsets...
                sc.doc.Objects.AddCurve(nc)
            else:  #...or the shortest for negative offsets.
                sc.doc.Objects.AddCurve(nc2)
        else:
            if offset > 0:
                sc.doc.Objects.AddCurve(nc2)
            else:
                sc.doc.Objects.AddCurve(nc)
    else:  #add both curves to the document
        sc.doc.Objects.AddCurve(nc)
        sc.doc.Objects.AddCurve(nc2)

    rs.EnableRedraw(True)
    sc.doc.Views.Redraw()
Example #5
0
def get_points_from_polylines(polys):
    points = []
    for key in polys:
        points += polys[key]['points']
    return rs.CullDuplicatePoints(points)
Example #6
0
    def setSurfaceForSlicing(self):
        explodedSurfaces = None

        editPoint = []
        explodedSurfaces = rs.ExplodePolysurfaces(self.addtiveObj)
        for i in explodedSurfaces:
            tmp = rs.SurfaceEditPoints(i)
            for j in tmp:
                editPoint.append(j)

        rs.CullDuplicatePoints(editPoint)

        minValue = []
        maxValue = []
        basePointForPlane = None
        basePointForDistance = None

        for i in range(len(editPoint)):
            if i == 0:
                basePointForPlane = editPoint[0]
                basePointForDistance = editPoint[0]

                for j in range(3):
                    minValue.append(editPoint[0][j])
                    maxValue.append(editPoint[0][j])
                continue

            else:
                if basePointForPlane[2] > editPoint[i][2]:
                    basePointForPlane = editPoint[i]
                if basePointForDistance[2] < editPoint[i][2]:
                    basePointForDistance = editPoint[i]

                for j in range(3):
                    if minValue[j] > editPoint[i][j]:
                        minValue[j] = editPoint[i][j]
                    elif maxValue[j] < editPoint[i][j]:
                        maxValue[j] = editPoint[i][j]

        #why?
        self.basePointForPlane = basePointForPlane

        plane = rs.PlaneFromNormal(basePointForPlane, self.normalVec)

        #calculating distance printing
        forDistance = []
        for i in range(len(editPoint)):
            if i == 0:
                forDistance.append(editPoint[0])
                forDistance.append(rs.DistanceToPlane(plane, editPoint[0]))
            else:
                tmpDistance = rs.DistanceToPlane(plane, editPoint[i])
                if tmpDistance > forDistance[1]:
                    forDistance[0] = editPoint[i]
                    forDistance[1] = tmpDistance

        self.distancePrinting = rs.DistanceToPlane(plane, forDistance[0])
        #adapt to Z Axis
        self.distancePrinting *= (1.0 /
                                  math.cos(math.radians(self.angleOfSurface)))

        if self.distancePrinting < 0:
            self.distancePrinting *= -1

        plane = rs.PlaneFromNormal(basePointForPlane, self.normalVec)

        pntForSur = []
        line = (minValue[0], minValue[1],
                minValue[2]), (minValue[0], minValue[1], maxValue[2])
        pntForSur.append(rs.LinePlaneIntersection(line, plane))
        line = (minValue[0], maxValue[1],
                minValue[2]), (minValue[0], maxValue[1], maxValue[2])
        pntForSur.append(rs.LinePlaneIntersection(line, plane))
        line = (maxValue[0], maxValue[1],
                minValue[2]), (maxValue[0], maxValue[1], maxValue[2])
        pntForSur.append(rs.LinePlaneIntersection(line, plane))
        line = (maxValue[0], minValue[1],
                minValue[2]), (maxValue[0], minValue[1], maxValue[2])
        pntForSur.append(rs.LinePlaneIntersection(line, plane))

        lineForSur = []

        for i in range(4):
            lineForSur.append(rs.AddLine(pntForSur[i], pntForSur[(i + 1) % 4]))

        self.sliceSurface = rs.AddEdgeSrf(lineForSur)

        #Delete lines used for making sliceSurface
        rs.DeleteObjects(lineForSur)
        rs.DeleteObjects(explodedSurfaces)