예제 #1
0
def addcurvaturegraph(idCrv, spansamples, scale):
    allGeometry = []
    knots = rs.CurveKnots(idCrv)
    p = 5
    for i in range(knots.Count - 1):
        tmpGeometry = addcurvaturegraphsection(idCrv, knots[i], knots[i + 1],
                                               spansamples, scale)
        if tmpGeometry: allGeometry.append(tmpGeometry)
    rs.AddObjectsToGroup(allGeometry, rs.AddGroup())
    return allGeometry
def smoothcurve(curve_id, s):
    curve_points = rs.CurvePoints(curve_id)
    new_curve_points = []

    for i in range(len(curve_points) - 1):
        vm = smoothingvector(curve_points[i], curve_points[i - 1],
                             curve_points[i + 1], s)
        new_curve_points.append(rs.PointAdd(curve_points[i], vm))

    knots = rs.CurveKnots(curve_id)
    degree = rs.CurveDegree(curve_id)
    weights = rs.CurveWeights(curve_id, 0)
    newcurve_id = rs.AddNurbsCurve(new_curve_points, knots, degree, weights)
    if newcurve_id: rs.DeleteObject(curve_id)
    return newcurve_id
def SampleExportCurvesAsJSON():

    # Select curves to export
    ids = rs.GetObjects('Select curves to export', 4, True, True)
    if not ids: return

    # Name of filename to creat
    fname = rs.SaveFileName('Save', 'JSON File (*.json)|*.json||')
    if not fname: return

    # The json data (dictionary)
    data = {}

    # The version of this data format
    data['version'] = 1.0

    # The Rhino version
    data['rhino'] = rs.ExeVersion()

    # The date
    data['date'] = time.strftime('%d/%m/%Y')

    # The number of curve records
    data['curve_count'] = len(ids)

    # The curve records (list)
    data['curves'] = []

    for id in ids:

        # Create a curve record (dictionary)
        rec = {}

        # The id
        rec['id'] = id.ToString()

        # The dimension
        rec['dim'] = rs.CurveDim(id)

        # Is rational
        rec['rational'] = rs.IsCurveRational(id)

        # The degree
        rec['degree'] = rs.CurveDegree(id)

        # The control point count
        rec['cv_count'] = rs.CurvePointCount(id)

        # The control points
        rec['cvs'] = []
        pts = rs.CurvePoints(id)
        wht = rs.CurveWeights(id)
        for i in range(len(pts)):
            pt = pts[i]
            rec['cvs'].append([pt[0], pt[1], pt[2], wht[i]])

        # The knot count
        rec['knot_count'] = rs.CurveKnotCount(id)

        # The knots
        rec['knots'] = []
        knots = rs.CurveKnots(id)
        for i in range(len(knots)):
            rec['knots'].append(knots[i])

        # Some other (unnecessary) properties
        rec['closed'] = rs.IsCurveClosed(id)
        rec['periodic'] = rs.IsCurvePeriodic(id)
        rec['planar'] = rs.IsCurvePlanar(id)

        # Append the curve record
        data['curves'].append(rec)

    # Write the json data
    with open('c:/users/dale/desktop/data.json', 'w') as outfile:
        json.dump(data, outfile)
예제 #4
0
import rhinoscriptsyntax as rs
import random as rd

curve = rs.GetObject("Select a Curve", 4)

if curve:
    points = rs.CurvePoints(curve)
    knots = rs.CurveKnots(curve)
    degree = rs.CurveDegree(curve)

    newpoints = []
    for p in points:
        dx = rd.randrange(0, 10)
        dy = rd.randrange(0, 10)
        dz = rd.randrange(0, 10)
        d = [dx, dy, dz]
        q = rs.PointAdd(p, d)
        newpoints.append(q)

    newcurve = rs.AddNurbsCurve(newpoints, knots, degree)