Exemple #1
0
 def divide_length(self, length_of_segments):
     rs.EnableRedraw(False)
     points = rs.DivideCurveLength(self.guid,
                                   length_of_segments,
                                   create_points=False,
                                   return_points=True)
     points[:] = map(list, points)
     rs.EnableRedraw(True)
     return points
Exemple #2
0
def getDiv(srf, dist, uv, eq):
    domaincrv = rs.ExtractIsoCurve(srf, [0, 0], uv)
    crvLen = rs.CurveLength(domaincrv)
    newdist = setDist(crvLen, dist, eq)
    pts = rs.DivideCurveLength(domaincrv, newdist)
    pts.pop(0)
    pts.pop(-1)
    rs.DeleteObject(domaincrv)
    return pts
Exemple #3
0
 def find_point_in_curve(self, crv):
     offset_points = rs.BoundingBox(crv)
     diagonal = rs.AddLine(offset_points[0], offset_points[2])
     test_points = rs.DivideCurveLength(diagonal,
                                        POINT_TOL,
                                        create_points=False,
                                        return_points=True)
     rs.DeleteObject(diagonal)
     for point in test_points:
         if rs.PointInPlanarClosedCurve(point, crv):
             return point
     return self.point
def splitVertical(St, ver_item):

    ver_param = rs.DivideCurveLength(ver_item, ipHeight, False, False)
    ver_Split = rs.SplitCurve(ver_item, ver_param, True)
    ver_line_split = []

    for ver_id in range(St, len(ver_Split), 2):
        ver_item = ver_Split[ver_id]

        ver_line_split.append(ver_item)
        #rs.DeleteObject(ver_item)

    return ver_line_split
Exemple #5
0
    def resample_polyline(self, length):
        try:
            rs_poly = rs.AddPolyline(self.polyline.points)
            if length <= self.polyline.length:
                a = rs.DivideCurveLength(rs_poly, length, False)
                num_div = len(
                    rs.DivideCurveLength(rs_poly, length, False, False))
                new_pts = rs.DivideCurve(rs_poly, num_div, False, True)

                new_rs_poly = rs.AddPolyline(new_pts)
                segs = rs.ExplodeCurves(new_rs_poly)

            else:
                print('it is a line!')
                segs = [
                    rs.AddLine(rs.CurveStartPoint(rs_poly),
                               rs.CurveEndPoint(rs_poly))
                ]
                print(segs)

            out_pts = []
            out_vec = []

            for seg in segs:
                new_pt = rs.CurveMidPoint(seg)
                v = rs.VectorCreate(rs.CurveEndPoint(seg),
                                    rs.CurveStartPoint(seg))
                new_pt = [new_pt.X, new_pt.Y, new_pt.Z]
                new_vec = [v.X, v.Y, v.Z]
                new_vec = compas.geometry.normalize_vector(new_vec)
                out_pts.append(new_pt)
                out_vec.append(new_vec)
            # print('succesfully resampled')
            return out_pts, out_vec

        except Exception:
            print('Polyline could not be resampled.')
            return None, None
Exemple #6
0
    def resample_curve(self, le):
        try:
            # rs_poly = rs.AddPolyline(self.polyline.points)
            crv = rs.AddInterpCurve(self.polyline.points)

            if le <= self.polyline.length:
                a = rs.DivideCurveLength(crv, le, False)
                div = rs.DivideCurveLength(crv, le, False, False)
                new_pts = rs.DivideCurve(crv, len(div), False, True)
                new_par = rs.DivideCurve(crv, len(div), False, False)

            else:
                print('it is a line!')
                new_pts = [rs.CurveStartPoint(crv), rs.CurveEndPoint(crv)]
                new_par = [0.0, rs.CurveLength(crv)]

            out_pts = []
            out_vec = []

            for idx, pt in enumerate(new_pts):

                pt = [pt.X, pt.Y, pt.Z]

                v = rs.CurveTangent(crv, new_par[idx])
                vec = [v.X, v.Y, v.Z]
                # vec = compas.geometry.normalize_vector(vec)

                out_pts.append(pt)
                out_vec.append(vec)
            # print('succesfully resampled')

            return out_pts, out_vec

        except Exception:
            print('Interpolated Curve could not be resampled.')
            return None, None
Exemple #7
0
def multiLineCurve():
    """
    --- --- --- --- --- --- --- --- --- --- ---
    -------------------------------------------
    --- --- --- --- --- --- --- --- --- --- --- 
    this script divides a curve by length and adds dashes to either side of the curve, grouped per curve / polyline
    limitation: does not accomodate at corners (to avoid ccx issues)
    www.studiogijs.nl
    """
    curves = rs.GetObjects("select curves to change into multiline-style",4, preselect=True)
    if not curves:
        return
    s=sc.sticky['scale'] if sc.sticky.has_key('scale') else 20
    scale = rs.GetReal("scale of the multiline curve", s, 5, 100)
     
    
    if not scale:
        return
    sc.sticky['scale']=scale
    
    rs.EnableRedraw(False)
    
    for curve in curves:
        lines=[]
        if rs.CurveLength(curve)>scale:
            pts = rs.DivideCurveLength(curve, scale)
            for pt in pts:
                t=rs.CurveClosestPoint(curve, pt)
                vec = rs.CurveTangent(curve, t)*scale/5
                line = rs.AddLine(pt-vec, pt+vec)
                trans = rs.VectorRotate(vec, 90, [0,0,1])
                trans/=2
                line_copy = rs.CopyObject(line, trans)
                trans = -trans
                lines.append(line_copy)
                rs.MoveObject(line, trans)
                lines.append(line)
            group = rs.AddGroup()
            rs.AddObjectsToGroup(lines, group)
            rs.AddObjectsToGroup(curve, group)
            rs.SelectObjects(lines)
            rs.SelectObjects(curves)
    rs.EnableRedraw(True)
Exemple #8
0
def fenceCurve():
    """
    ---x---x---x---x---x---x---
    this script divides a curve by length and adds 'crosses' to it, grouped per curve / polyline
    www.studiogijs.nl
    """
    curves = rs.GetObjects("select curves to change into fence-style",
                           4,
                           preselect=True)
    if not curves:
        return

    s = sc.sticky['scale'] if sc.sticky.has_key('scale') else 20
    scale = rs.GetReal("scale of the arrow curve", s, 5, 100)

    if not scale:
        return
    sc.sticky['scale'] = scale

    rs.EnableRedraw(False)

    for curve in curves:
        lines = []
        if rs.CurveLength(curve) > scale:
            pts = rs.DivideCurveLength(curve, scale)
            for pt in pts:
                t = rs.CurveClosestPoint(curve, pt)
                vec = rs.CurveTangent(curve, t)
                line = rs.AddLine(pt - vec * scale / 10, pt + vec * scale / 10)
                rs.RotateObject(line, pt, 45)
                lines.append(line)
                line_copy = rs.RotateObject(line, pt, 90, copy=True)
                lines.append(line_copy)
            group = rs.AddGroup()
            rs.AddObjectsToGroup(lines, group)
            rs.AddObjectsToGroup(curve, group)
            rs.SelectObjects(lines)
            rs.SelectObjects(curves)
    rs.EnableRedraw(True)
import math
import rhinoscriptsyntax as rs
import ghpythonlib.components as ghc
import Rhino.Geometry as rg
icurvesn = []
icurvesm = []
ipointssnm = []
ipointssmn = []
curve01 = curves[0]
curve12 = curves[1]
curve23 = curves[2]
curve30 = curves[3]
points01 = rs.DivideCurveLength(curve01, length)
points12 = rs.DivideCurveLength(curve12, length)
points23 = rs.DivideCurveLength(curve23, length)
points30 = rs.DivideCurveLength(curve30, length)
m = (len(points12) + len(points30)) / 2
n = (len(points01) + len(points23)) / 2

points01 = rs.DivideCurve(curve01, n + 1)
points12 = rs.DivideCurve(curve12, m + 1)
points23 = rs.DivideCurve(curve23, n + 1)
points30 = rs.DivideCurve(curve30, m + 1)
m = int(m)
n = int(n)
bpoints = points01 + points12 + points23 + points30
for i in range(n):
    icurve = rs.ShortPath(surface, points01[i + 1], points23[-(i + 2)])
    icurvesn.append(icurve)
count = 0
while (count < loop):
Exemple #10
0
 def _get_base_points(self, curve_id):
     base_points = rs.DivideCurveLength(curve_id,
                                        self.spacing,
                                        create_points=False,
                                        return_points=True)
     return base_points
Exemple #11
0
import rhinoscriptsyntax as rs

fp = "gcode_out.txt"

inCrv = rs.GetObjects("Select curves to draw")


subD = rs.GetReal("Input segment length", number=1.0)

with open(fp, mode='w') as outfile:
    if len(inCrv) >= 1:
        for crv in inCrv:
            pts = rs.DivideCurveLength(crv, subD)
            for i, pt in enumerate(pts):
                if i == 0:
                    #raise pen
                    outfile.write("M03 S0 \n")
                    #go to first position
                    outfile.write("G00 X%.3f Y%.3f \n" %(pt.X,pt.Z) )
                    #drop pen
                    outfile.write("M03 S1024 \n")
                    continue
                #go to next position (with pen down)
                outfile.write("G00 X%.3f Y%.3f \n" %(pt.X,pt.Z) )
            #lift pen
            outfile.write("M03 S0 \n")
        outfile.write("G00 X0 Y0 \n")

outfile.close()
def basicpoints(bplines, lengthunit):
    #
    basicplanepoints = []  #等分点
    for u in range(len(bplines)):
        basicplanepoint = rs.DivideCurveLength(bplines[u], lengthunit, True,
                                               True)
        basicplanepoints.append(basicplanepoint)

    planeunit = 1
    randomselectionp = []  #随机提取的点
    pupoints = []
    for o in range(len(basicplanepoints) - 1):  #循环等分点母列表
        for p in range(len(basicplanepoints[0])):  #循环子列表
            basicplanepointscor = [
                basicplanepoints[o][p][0], basicplanepoints[o][p][1],
                basicplanepoints[o][p][2]
            ]
            pupoints.append(basicplanepointscor)  #提取一条线的各个点坐标

            #每组9个点,已有一个原点
            pupoint1 = [
                basicplanepointscor[0] + planeunit, basicplanepointscor[1],
                basicplanepointscor[2]
            ]
            pupoints.append(pupoint1)  #第1个点
            rs.Addpoint(pupoint1)

            pupoint2 = [
                basicplanepointscor[0] + planeunit,
                basicplanepointscor[1] + planeunit, basicplanepointscor[2]
            ]
            pupoints.append(pupoint2)  #第2个点
            rs.Addpoint(pupoint2)

            pupoint3 = [
                basicplanepointscor[0], basicplanepointscor[1] + planeunit,
                basicplanepointscor[2]
            ]
            pupoints.append(pupoint3)  #第3个点
            rs.Addpoint(pupoint3)

            pupoint4 = [
                basicplanepointscor[0] - planeunit,
                basicplanepointscor[1] + planeunit, basicplanepointscor[2]
            ]
            pupoints.append(pupoint4)  #第4个点
            rs.Addpoint(pupoint4)

            pupoint5 = [
                basicplanepointscor[0] - planeunit, basicplanepointscor[1],
                basicplanepointscor[2]
            ]
            pupoints.append(pupoint5)  #第5个点
            rs.Addpoint(pupoint5)

            pupoint6 = [
                basicplanepointscor[0] - planeunit,
                basicplanepointscor[1] - planeunit, basicplanepointscor[2]
            ]
            pupoints.append(pupoint6)  #第6个点
            rs.Addpoint(pupoint6)

            pupoint7 = [
                basicplanepointscor[0], basicplanepointscor[1] - planeunit,
                basicplanepointscor[2]
            ]
            pupoints.append(pupoint7)  #第7个点
            rs.Addpoint(pupoint7)

            pupoint8 = [
                basicplanepointscor[0] + planeunit,
                basicplanepointscor[1] - planeunit, basicplanepointscor[2]
            ]
            pupoints.append(pupoint8)  #第8个点
            rs.Addpoint(pupoint8)

            randomselectionp.append(random.choice(pupoints))
            pupoints = []
    pupoints0 = randomselectionp[:]
Exemple #13
0
	elif rs.ObjectLayer(curve)=="5":
		curvesByLayers[4].append(curve)
	elif rs.ObjectLayer(curve)=="6":
		curvesByLayers[5].append(curve)
print len(curvesByLayers[0])

for idx, pencurves in enumerate(curvesByLayers):
	if not pencurves: continue
	pen = idx + 1
	hpglOut.write('SP'+str(pen)+';\n')
	for curve in pencurves:
		if rs.CurveDegree (curve) == 1: #polyline or line
			points=rs.CurveEditPoints(curve) #works for polyline or line
			#print 'line'
		elif rs.CurveDegree (curve) == 2 or rs.CurveDegree (curve) == 3: #curvy curve
			points = rs.DivideCurveLength(curve, .025)
			print 'curvy'
		if not points:
			#print 'found one very tiny curve, which is not exported'
			continue #means skip this iteration of the loop and go right to the next curve
		#pen up to the first point on line
		x = points[0][0]
		y = points[0][1]
		hpglOut.write('PU'+str(int(x*1000))+','+str(int(y*1000))+';\n')
		#pen down to every subsequent point
		i=1
		while i<len(points):
			x = points[i][0]
			y = points[i][1]
			hpglOut.write('PD'+str(int(x*1000))+','+str(int(y*1000))+';\n')
			i=i+1
Exemple #14
0
import rhinoscriptsyntax as rs
import random

point = rs.GetPoint()

for i in range(0, 10):

    a = random.randint(0, 10)
    b = random.randint(0, 10)
    c = 0

    StartPoint = (a, b, c)
    NewVecEnd = (point)
    NewVecStart = (0, 0, 0)
    origin = StartPoint

    r = random.randint(0, 255)
    b = random.randint(0, 255)
    g = random.randint(0, 255)
    color = [r, g, b]

    vector = rs.VectorCreate(NewVecEnd, NewVecStart)
    line = rs.AddLine(StartPoint, vector)
    #line = rs.ScaleObject(line, origin, (0.5,0.5,0.5))

    rs.ObjectColor(line, color)
    segments = rs.DivideCurveLength(line, 9)
    rs.AddLine(StartPoint, segments[1])

print(segments[0])
Exemple #15
0
import rhinoscriptsyntax as rs

fp = "gcode_out.txt"

inCrv = rs.GetObject("Select curve to draw")

subD = rs.GetReal("Input segment length", number=1.0)

pts = rs.DivideCurveLength(inCrv, subD)

with open(fp, mode='w') as outfile:
    for i, pt in enumerate(pts):
        if i == 0:
            #raise pen
            outfile.write("M03 S0 \n")
            #go to first position
            outfile.write("G00 X%.3f Y%.3f \n" % (pt.X, pt.Y))
            #drop pen
            outfile.write("M03 S1024 \n")
            continue
        #go to next position (with pen down)
        outfile.write("G00 X%.3f Y%.3f \n" % (pt.X, pt.Y))
    #lift pen
    outfile.write("M03 S0 \n")
    outfile.write("G00 X0 Y0 \n")

outfile.close()