Ejemplo n.º 1
0
 def test_get_boundary_polyline(self):
     #deprivated, since now in general not drwaing lines
     #However, if needed can easily specifically draw cut lines
     island.make_five_by_five_square_island(self.island)
     self.island.clear()
     self.island.draw_edges()
     boundary = self.island.get_boundary_polyline()
     self.assertTrue(rs.IsPolyCurve(boundary))
     self.assertTrue(rs.IsCurveClosed(boundary))
     self.assertTrue(rs.IsCurvePlanar(boundary))
     self.island.clear()
Ejemplo n.º 2
0
 def tangents(self, points):
     tangents = []
     if rs.IsPolyCurve(self.guid):
         pass
     elif rs.IsCurve(self.guid):
         for point in points:
             param = rs.CurveClosestPoint(self.guid, point)
             vector = list(rs.CurveTangent(self.guid, param))
             tangents.append(vector)
     else:
         raise Exception('Object is not a curve.')
     return tangents
Ejemplo n.º 3
0
 def tangents(self, points):
     tangents = []
     if rs.IsPolyCurve(self.guid):
         pass
     elif rs.IsCurve(self.guid):
         for point in points:
             param = rs.CurveClosestPoint(self.guid, point)
             vector = list(rs.CurveTangent(self.guid, param))
             tangents.append((point, vector))
     else:
         raise RhinoCurveError('object is not a curve')
     return tangents
Ejemplo n.º 4
0
 def space(self, density):
     space = []
     density = int(density)
     if rs.IsCurve(self.guid):
         domain = rs.CurveDomain(self.guid)
         u = (domain[1] - domain[0]) / (density - 1)
         for i in range(density):
             space.append(domain[0] + u * i)
     elif rs.IsPolyCurve(self.guid):
         rs.EnableRedraw(False)
         segments = rs.ExplodeCurves(self.guid)
         for segment in segments:
             domain = rs.CurveDomain(segment)
             u = (domain[1] - domain[0]) / (density - 1)
             for i in range(density):
                 space.append(domain[0] + u * i)
         rs.DeleteObjects(segments)
         rs.EnableRedraw(True)
     else:
         raise Exception('Object is not a curve.')
     return space
Ejemplo n.º 5
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)
Ejemplo n.º 6
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()
Ejemplo n.º 7
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)