示例#1
0
def ArcorCurve(Curve):
    if rs.CurveDegree(Curve) == 2:
        return "arc"
    elif rs.CurveDegree(Curve) == 1:
        return "line"
    else:
        return "Invalid Curve"
示例#2
0
def Getendpoints(Curve):
    x = rs.CurveStartPoint(Curve)
    y = rs.CurveEndPoint(Curve)
    z = rs.CurveMidPoint(Curve)
    startP = x.X, x.Y, x.Z
    MidP = z.X, z.Y, z.Z
    EndP = y.X, y.Y, y.Z
    if rs.CurveDegree(Curve) == 2:
        return str(startP) + "," + str(MidP) + "," + str(EndP)
    elif rs.CurveDegree(Curve) == 1:
        return str(startP) + "," + str(EndP)
    else:
        return "Invalid Curve"
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()
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
示例#5
0
文件: curve.py 项目: mpopescu/compas
    def is_polyline(self):
        """Determine if the curve is a polyline.

        Returns
        -------
        bool
            Tue if the curve is a polyline.
            False otherwise.

        Notes
        -----
        A curve is a polyline if it consists of linear segments between a sequence of points.

        """
        return (rs.IsPolyline(self.guid) and rs.CurveDegree(self.guid) == 1
                and len(rs.CurvePoints(self.guid)) > 2)
示例#6
0
def is_curve_line(guid):
    """Verify that a curve is a line.

    Parameters
    ----------
    guid : System.Guid
        The identifier of the curve.

    Returns
    -------
    bool
        True if the curve is a line.
        False otherwise.

    """
    return rs.IsCurve(guid) and rs.IsLine(guid) and rs.CurveDegree(guid) == 1 and len(rs.CurvePoints(guid)) == 2
示例#7
0
文件: curve.py 项目: mpopescu/compas
    def is_line(self):
        """Determine if the curve is a line.

        Returns
        -------
        bool
            Tue if the curve is a line.
            False otherwise.

        Notes
        -----
        A curve is a line if it is a linear segment between two points.

        """
        return (rs.IsLine(self.guid) and rs.CurveDegree(self.guid) == 1
                and len(rs.CurvePoints(self.guid)) == 2)
示例#8
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)
示例#9
0
def is_curve_polygon(guid):
    return rs.IsCurve(guid) and rs.IsCurveClosed(guid) and rs.CurveDegree(guid) == 1 and len(rs.CurvePoints(guid)) > 2
示例#10
0
def is_curve_polyline(guid):
    return rs.IsCurve(guid) and rs.IsPolyline(guid) and rs.CurveDegree(guid) == 1 and len(rs.CurvePoints(guid)) > 2
示例#11
0
def is_curve_line(guid):
    return rs.IsCurve(guid) and rs.IsLine(guid) and rs.CurveDegree(guid) == 1 and len(rs.CurvePoints(guid)) == 2
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)
示例#13
0
#everything is drawn with pen 1 or 2, depending on the lay
#hpgl file saved in the same folder as this script called "outputxxxxx.hpgl" where xxxxx is a random series of numbers
import rhinoscriptsyntax as rs
import random
#hpglOut = file('./output'+str(random.randint(100000000,999999999))+'.hpgl', 'w')
#print hpglOut.tell()

hpglOut = file('C:\Users\William\Documents\hpgl\output'+str(random.randint(100000000,999999999))+'.hpgl', 'w')
allCurves =rs.ObjectsByType(4)

hpglOut.write('IN;\n')
#hpglOut.write('SP1;\n')

#first explode anypolycurves (that aren't polylines) -- an exception I forgot to mention in class
for curve in allCurves:
	if rs.IsPolyCurve(curve) and rs.CurveDegree (curve) >= 2 :
		rs.ExplodeCurves (curve, True)

allCurves =rs.ObjectsByType(4)

curvesByLayers = [[] for _ in range(6)]

for curve in allCurves:
	if rs.ObjectLayer(curve)=="1":
		curvesByLayers[0].append(curve)
	elif rs.ObjectLayer(curve)=="2":
		curvesByLayers[1].append(curve)
	elif rs.ObjectLayer(curve)=="3":
		curvesByLayers[2].append(curve)
	elif rs.ObjectLayer(curve)=="4":
		curvesByLayers[3].append(curve)
示例#14
0
def Crv2ViewLoose():
    curve1 = rs.GetObject("select first curve", rs.filter.curve)
    if curve1 != None:
        rs.LockObject(curve1)
    curve2 = rs.GetObject("select second curve", rs.filter.curve)
    if curve1 == None or curve2 == None:
        return

    degree1 = rs.CurveDegree(curve1)
    degree2 = rs.CurveDegree(curve2)
    pts1 = rs.CurvePoints(curve1)
    pts2 = rs.CurvePoints(curve2)
    error = False
    errors = []
    if rs.IsPolyCurve(curve1) or rs.IsPolyCurve(curve2):
        errors.append("Error: This script only works for single open curves")
        error = True
    if not rs.IsCurvePlanar(curve1) or not rs.IsCurvePlanar(curve2):
        errors.append("Error: One or more of the input curves is not planar.")
        error = True
    if rs.IsCurvePeriodic(curve1) or rs.IsCurvePeriodic(curve2):
        errors.append("Error: This script only works with open curves")
        error = True
    if len(pts1) != len(pts2):
        errors.append(
            "Error: Input curves need to have same amount of control points")
        error = True
    if rs.CurveDegree(curve1) != rs.CurveDegree(curve2):
        errors.append("Error: Input curves need to be of same degree")
        error = True
    if error:
        for err in errors:
            print err
        rs.UnlockObject(curve1)
        return

    top = 0
    right = 0
    front = 0
    if rs.CurvePlane(curve1).ZAxis[2] != 0:  #top view curve
        top = 1

    if rs.CurvePlane(curve2).ZAxis[2] != 0:  #top view curve
        top = 2

    if rs.CurvePlane(curve1).ZAxis[0] != 0:  #right view curve
        right = 1

    if rs.CurvePlane(curve2).ZAxis[0] != 0:  #right view curve
        right = 2

    if rs.CurvePlane(curve1).ZAxis[1] != 0:  #front view curve
        front = 1

    if rs.CurvePlane(curve2).ZAxis[1] != 0:  #front view curve
        front = 2

    pts3 = []  #array to store the points for the new curve
    if top == 1 and right == 2:
        for i in range(0, len(pts1)):
            pts1[i][2] = pts2[i][2]
            pts1[i][1] = (pts1[i][1] + pts2[i][1]
                          ) / 2  #average out y-coordinate of each point
            pts3.append(pts1[i])
    if top == 2 and right == 1:
        for i in range(0, len(pts1)):
            pts2[i][2] = pts1[i][2]
            pts2[i][1] = (pts1[i][1] + pts2[i][1]
                          ) / 2  #average out y-coordinate of each point
            pts3.append(pts2[i])
    if top == 1 and front == 2:
        for i in range(0, len(pts1)):
            pts1[i][2] = pts2[i][2]
            pts1[i][0] = (pts1[i][0] + pts2[i][0]
                          ) / 2  #average out x-coordinate of each point
            pts3.append(pts1[i])
    if top == 2 and front == 1:
        for i in range(0, len(pts1)):
            pts2[i][2] = pts1[i][2]
            pts2[i][0] = (pts1[i][0] + pts2[i][0]
                          ) / 2  #average out x-coordinate of each point
            pts3.append(pts2[i])
    rs.UnlockObject(curve1)

    if (right == 0 and front == 0) or (top == 0
                                       and right == 0) or (top == 0
                                                           and front == 0):
        print "Error: Curves need to be placed on orthogonal views"
        return
    else:

        rs.AddCurve(pts3, degree1)
示例#15
0
 def is_polyline(self):
     return (rs.IsPolyline(self.guid) and rs.CurveDegree(self.guid) == 1
             and len(rs.CurvePoints(self.guid)) > 2)
示例#16
0
 def is_line(self):
     return (rs.IsLine(self.guid) and rs.CurveDegree(self.guid) == 1
             and len(rs.CurvePoints(self.guid)) == 2)
示例#17
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()