name_dot = rs.AddTextDot(value, point_list[i][j]) rs.ObjectLayer(name_dot, new_layer) else: # convert to string to float value = float(value) if(value > 0): value = value * factor # select vector vec_coord = norm_list[i][j] print(vec_coord) # scale vector with data from team vec = rs.VectorScale(vec_coord, value + 0.1 ) if(rs.VectorLength(vec) < 0.1): # unitize vector vec_unit = rs.VectorUnitize(vec) vec = rs.VectorScale(vec_unit, 0.2) print(point_list[i][j]) # copy point start_point = rs.AddPoint(point_list[i][j]) end_point = rs.CopyObject(start_point, vec) # create a line line = rs.AddLine(point_list[i][j], end_point) pipe = rs.AddPipe(line, [0.0, 1.0], [4, 4], cap = 1) rs.DeleteObjects([start_point, end_point, line]) rs.ObjectLayer(pipe, new_layer) rs.EnableRedraw = True
#fixed_vertices = mesh.vertices_on_boundary() #curve = rs.GetObject('curve', filter = 4) #for vkey in fixed_vertices: # xyz = mesh.vertex_coordinates(vkey) # t = rs.CurveClosestPoint(curve, xyz) # x, y, z = rs.EvaluateCurve(curve, t) # attr = mesh.vertex[vkey] # attr['x'] = x # attr['y'] = y # attr['z'] = z #mesh_smooth_area(mesh, fixed = fixed_vertices, kmax = 50, damping = .5) is_polygonal = False for fkey in mesh.faces(): if len(mesh.face_vertices(fkey)) > 4: is_polygonal = True if not is_polygonal: draw_mesh(mesh) else: edges = [] for u, v in mesh.edges(): u_xyz = mesh.vertex_coordinates(u) v_xyz = mesh.vertex_coordinates(v) if u_xyz != v_xyz: edges.append(rs.AddLine(u_xyz, v_xyz)) rs.AddGroup('mesh') rs.AddObjectsToGroup(edges, 'mesh') rs.EnableRedraw(False)
#print clos_pt_layer #change_layer = rs.ObjectLayer(pt, clos_pt_layer) #vector initializing vect = rs.VectorCreate(clos_pt, pt) unit_vect = rs.VectorUnitize(vect) #this makes the objects fall along a sphere #sub_vect = (vect)-(unit_vect) #this makes the objects fall along a straight line sub_vect = (vect)/3 #draw line between origin (og_) pts and cloud of random pts init_dst = rs.AddLine(pt, clos_pt) line_set1.append(init_dst) #pipes the lines #rs.AddPipe(init_dst, 0, .01, 0) #move cloud of random pts according to outcome of sub_vect new_pt = rs.MoveObject(pt,sub_vect) new_pt_coord = rs.PointCoordinates(new_pt) cloud_pts.append(new_pt) #set parameter for spheres and boxes #run through clos_pt, if it's layer is x, then move cloud pts that are close to it into x layer, #then get those close pts by layer, and apply parameter to the boxes that grow off them. #string_l = rs.ObjectLayer(index) #print string_l
def VectorDraw(vecdir, base_point=[0, 0, 0]): """Draws a vector starting at the given base point.""" tip_point = rs.PointAdd(base_point, vecdir) line = rs.AddLine(base_point, tip_point) if line: return rs.CurveArrows(line, 2) # adds an arrow tip
def main(): # get our curves profile, cross = get_two_curves() if profile is None or cross is None: return ################################################## # get bounding box for cross section cross_bbox = rs.BoundingBox([cross]) cmin, cmax = box_to_points(cross_bbox) cz_range = cmax[2] - cmin[2] cz = 0.5 * (cmax[2] + cmin[2]) c_ctr, _ = rs.CurveAreaCentroid(cross) # make sure it's planar in XY if cz_range > 1e-9: print 'cross section curve should be planar in XY plane' return ################################################## # get bounding box for profile profile_bbox = rs.BoundingBox([profile]) # make sure it's planar in in YZ pmin, pmax = box_to_points(profile_bbox) px_range = pmax[0] - pmin[0] if px_range > 1e-9: print 'profile curve should be planar in YZ plane' return ################################################## # get the point closest to the center for the # cross-section curve r, pc = get_inscribed_radius(cross, c_ctr) ################################################## # get the range of z-values for the profile curve _, _, z0 = pmin _, _, z1 = pmax ################################################## # build list of rings and list of points points = [] ring_pipes = [] # for each level for i in range(num_levels): # get the Z value of the ith plane u = float(i) / (num_levels-1) z = z0 + u*(z1 - z0) # build the i'th plane plane = rs.PlaneFromNormal([0, 0, z], [0, 0, 1], [1, 0, 0]) # find out where the plane intersects the profile curve intersect = rs.PlaneCurveIntersection(plane, profile) # there should be exactly one intersection of type 1 (point) if intersect is None or len(intersect) > 1 or intersect[0][0] != 1: print 'bad intersection' return # get the intersection point pi = intersect[0][1] # get the desired XY radius at this z value ri = abs(pi[1]) # we need to set up some transformations: # translate cross section curve down to z=0 T1 = rs.XformTranslation(mz.vec_mul(list(c_ctr), -1.0)) # scale it along XY by the ratio of radii S1 = rs.XformScale([ri/r, ri/r, 1.0]) # scale a piped cross section along Z by a vertical scale factor S2 = rs.XformScale([1.0, 1.0, ring_vscale]) # translate piped cross section up to our desired z value T2 = rs.XformTranslation([0, 0, z]) # scale and translate cross section curve ci = rs.TransformObject(cross, rs.XformMultiply(S1, T1), copy=True) # pipe it ring = rs.AddPipe(ci, [0, 1], [ring_rad, ring_rad]) # scale vertically and transform up ring = rs.TransformObject(ring, rs.XformMultiply(T2, S2)) # delete the copy of the cross section curve rs.DeleteObject(ci) # add to list of ring pipes ring_pipes.append(ring) # create a rotation by the i'th angle angle_i_deg = i*360.0/num_sides Ri = rs.XformRotation2(angle_i_deg, [0, 0, 1], [0, 0, 0]) # transform the closest point by rotation and scale pci = rs.PointTransform(pc, rs.XformMultiply(rs.XformMultiply(Ri, T2), S1)) # add to list of points points.append(pci) # we have built up a list of points for a single spiral of struts to connect, # now we need to pipe them all together and do the ArrayPolar thing around # the z axis # first build a single spiral of struts strut_pipes = [] for i0 in range(num_levels-1): i1 = i0+1 p0 = points[i0] p1 = points[i1] l01 = rs.AddLine(p0, p1) pipe = rs.AddPipe(l01, [0, 1], [strut_rad, strut_rad], cap=2) rs.DeleteObject(l01) strut_pipes.append(pipe) # then array polar around Z axis all_strut_pipes = [] all_strut_pipes += strut_pipes for j in range(1, num_sides): angle_j_deg = j*360.0/num_sides Rj = rs.XformRotation2(angle_j_deg, [0, 0, 1], [0, 0, 0]) all_strut_pipes += rs.TransformObjects(strut_pipes, Rj, copy=True) # now just select all the objects we created rs.SelectObjects(ring_pipes + all_strut_pipes) # done! print 'yay'
bed_temp = rs.GetReal("Bed temperture",60) printspeed = rs.GetReal("Print speed",2500) multi = rs.GetReal("Extrude multiply",1.0) plane = Rhino.Geometry.Plane(box_point[0], box_point[1], box_point[2]) u_dir = rs.Distance(box_point[0], box_point[1]) v_dir = rs.Distance(box_point[1], box_point[2]) surface = rs.AddPlaneSurface(plane, u_dir, v_dir) box_value = box_point[6] array_z_number = int(box_value[2] // Layerheight) if surface: array_lines=[] line = rs.AddLine(box_point[0],box_point[3]) array_number = int(box_value[0] // distance_x) #Array line if line: i = 0 for i in range(array_number): offset_x = distance_x * i line_copy = (offset_x, 0, 0) array_lines.append(rs.CopyObject( line, line_copy )) n = 0 for n in range(array_z_number): offset_z = Layerheight * n surface_copy = (0,0,offset_z)
def ProfileCurveThings (treeIn, profCrv, profPointTreeOut, vectorTreeOut, vectorLineTree, tOut): MaxCoord = GridCornerBig (treeIn) x_max = MaxCoord.X y_max = MaxCoord.Y z_max = MaxCoord.Z profPointList = [] profVecDirection = [] vectorList = [] curvatureTree = datatree [sys.Object] () directionTree = datatree [sys.Object] () Crv = rs.coercecurve (profCrv) start = rs.CurveStartPoint (Crv) end = rs.CurveEndPoint (Crv) if start.Y > end.Y : Crv = rh.Geometry.Curve.Reverse (Crv) for i in range(treeIn.BranchCount): treeBranch = treeIn.Branch(i) treePath = treeIn.Path(i) for j in range(treeBranch.Count): elem = treeBranch[j] x = elem.X y = elem.Y z = elem.Z Yarany = y / y_max crvPoint = rh.Geometry.Curve.PointAtNormalizedLength(profCrv, Yarany) crvPoint = rs.coerce3dpoint (crvPoint) t = rs.CurveClosestPoint (profCrv, crvPoint) curvature = rs.CurveCurvature(profCrv, t)[4] tangent = rs.CurveCurvature(profCrv, t)[1] angle1 = rs.VectorAngle ([0,1,0], curvature) angle2 = rs.VectorAngle ([0,1,0], tangent) curvatureRot = curvature curvatureRot = rs.coerce3dpoint (curvatureRot) rs.RotateObject (curvatureRot, [0,0,0], 90, [0,0,1]) curvatureRot = rs.coerce3dvector (curvatureRot) angle = rs.VectorAngle (curvatureRot, tangent) curvature = rs.coerce3dpoint(curvature) if 179.99 < angle <180.01: angleDirect = 0 else: angleDirect = 1 profPointList.append (crvPoint) profVecDirection.append (angleDirect) vectorList.append (curvature) curvatureTree.Add (curvature, treePath) profPointTreeOut.Add (crvPoint, treePath) directionTree.Add (angleDirect, treePath) tOut.Add (Yarany, treePath) profPoint_x_List = [] for i in range (profPointList.Count): profPoint = profPointList [i] profPoint_x = profPoint.X profPoint_x_List.append (profPoint_x) a = 0 for i in range (profPoint_x_List.Count): x = profPoint_x_List [i] Xabs = math.fabs (x) if Xabs > a: b = i a = Xabs c = x directByMax = profVecDirection [b] vectorByMax = vectorList [b] pointByMax = profPointList [b] stableByMax = pointByMax pointX = math.fabs (stableByMax.X) moveByMax = pointByMax unitVecByMax = rs.VectorUnitize (vectorByMax) rs.MoveObject (moveByMax, 5* unitVecByMax) moveX = math.fabs (moveByMax.X) if moveX > pointX: mirror = 1 else: mirror = 0 for i in range(curvatureTree.BranchCount): treeBranch = curvatureTree.Branch(i) treePath = curvatureTree.Path(i) pointBranch = profPointTreeOut.Branch(i) directionBranch = directionTree.Branch(i) for j in range(treeBranch.Count): curvature = treeBranch [j] crvPoint = pointBranch [j] direction = directionBranch [j] curvature = rs.coerce3dpoint(curvature) if mirror == 0: if direction != directByMax: rs.RotateObject (curvature, [0,0,0], 180, [0,0,1]) if mirror == 1: if direction == directByMax: rs.RotateObject (curvature, [0,0,0], 180, [0,0,1]) curvature = rs.coerce3dvector(curvature) unitCrvVec = rs.VectorUnitize (curvature) if c < 0: unitCrvVec2 = - unitCrvVec else: unitCrvVec2 = unitCrvVec unitCrvVec = rs.coerce3dvector (unitCrvVec) unitCrvVec2 = rs.coerce3dvector (unitCrvVec2) moveCrvPoint = crvPoint + (unitCrvVec*5) moveCrvPoint = rs.coerce3dpoint (moveCrvPoint) vectorLine = rs.AddLine (crvPoint, moveCrvPoint) vectorTreeOut.Add (unitCrvVec2, treePath) vectorLineTree.Add (vectorLine, treePath)
#bs3 = lista de barras do banzo supeiro #nbs3 = lista de nós do bazo superior #dg3 e ndg3 para diagoains e bi3 e nbi3 para banzo inferior bs3, nbs3, dg3, ndg3, bi3, nbi3 = Elementos_vigas(v3) raAux = bi3[0] rbAux = bs3[0] pAux1 = nbi3[0] pAux2 = nbs3[0] #caso o numero de diagonais seja par if len(dg3) % 2 == 0: raAux = rs.coerceline(raAux) #ponto de interseção das resultantes pt_inter = gh.LineXLine(R1FG, raAux)[-1] resultante_1.append(pt_inter) #resultante entre banzo e diagonal rbAux = rs.AddLine(pAux2, pt_inter) rbAux = rs.coerceline(rbAux) #vetor auxiliar para deslocamento gh.Move pto_R1 = dic_1['R1'].PointAt(1) vAux1 = rs.AddLine(pAux1, pto_R1) vAux1 = rs.coerceline(vAux1) #vetor auxiliar para deslocamento gh.Move vAux2 = rs.AddLine(pAux2, pto_inicial_1) vAux2 = rs.coerceline(vAux2) #movendo linhas do FG para o PF raAux = gh.Move(raAux, vAux1)[0] rbAux = gh.Move(rbAux, vAux2)[0] #ponto de interseção das reações no PF pto_PF = gh.LineXLine(raAux, rbAux)[-1] # - desenhando reação RA no PF RA = rs.AddLine(pto_R1, pto_PF)
def Linha_force_extena(no, peso, conv): lincarg = rs.AddLine(no, gh.Move(no, peso * conv * eY)[0]) rs.ReverseCurve(lincarg) return lincarg
uDomain = rs.SurfaceDomain(srf, 0) vDomain = rs.SurfaceDomain(srf, 1) uMin = uDomain[0] uMax = uDomain[1] vMin = vDomain[0] vMax = vDomain[1] uRange = uMax - uMin vRange = vMax - vMin uStep = uRange / numberUCells vStep = vRange / numberVCells U = uMin while U < uMax: V = vMin while V < vMax: point = rs.EvaluateSurface(srf, U, V) normal = rs.SurfaceNormal(srf, (U, V)) scaledNormal = rs.VectorScale(normal, 7) pointOffSurface = rs.VectorAdd(point, scaledNormal) myTrunk = rs.AddLine(point, pointOffSurface) tree(myTrunk, 4, scaledNormal) V += vStep U += uStep
def goto(self, x, y): prevPos = rs.PointCoordinates(self.point) movement = rs.VectorCreate([x, y, 0], prevPos) rs.MoveObject(self.point, movement) currentPos = rs.PointCoordinates(self.point) rs.AddLine(prevPos, currentPos)
import rhinoscriptsyntax as rs layers = rs.LayerNames() i = 0 for layer in layers: a = (i, i, 0) b = (i, i + 1, 0) rs.CurrentLayer(layer) rs.AddLine(a, b) i += 1
for outerFacePoint in outerFacePoints: for miterFacePoint in miterFacePoints: if miterFacePoint == outerFacePoint: intersectPoints.append(miterFacePoint) param = rs.SurfaceClosestPoint(outerFace, intersectPoints[0]) normal = rs.SurfaceNormal(outerFace, param) outerEndPoint = intersectPoints[0] + normal outerVector = normal param = rs.SurfaceClosestPoint(miterFace, intersectPoints[0]) normal = rs.SurfaceNormal(miterFace, param) miterEndPoint = intersectPoints[0] + normal miterVector = normal line = rs.AddLine(outerEndPoint, miterEndPoint) rs.HideObject(line) midPoint = rs.CurveMidPoint(line) normalVector = rs.VectorCrossProduct(outerVector, miterVector) cutPlane = rs.AddCutPlane(solid, intersectPoints[0], midPoint, normal = normalVector) rs.HideObject(cutPlane) splitSolids = rs.SplitBrep(solid, cutPlane, True) rs.CapPlanarHoles(splitSolids[0]) rs.CapPlanarHoles(splitSolids[1]) if rs.SurfaceArea(splitSolids[0]) > rs.SurfaceArea(splitSolids[1]): rs.DeleteObject(splitSolids[1])
PlaceSmd(1.698669, 20.338546, 0.365022, 0.521305, 0.000000, 1) PlaceSmd(2.301331, 18.861454, 0.365022, 0.521305, 0.000000, 1) PlaceSmd(1.464244, 19.009055, 0.365022, 0.521305, 0.000000, 1) PlaceSmd(2.418543, 19.526200, 0.373704, 0.472065, 0.000000, 1) PlaceSmd(1.581457, 19.673800, 0.373704, 0.472065, 0.000000, 1) PlaceInstance("SMLP36", 1.800000, 17.000000, False, 270.000000) PlaceSmd(2.225000, 17.675000, 0.450000, 0.450000, 0.000000, 1) PlaceSmd(1.375000, 17.675000, 0.450000, 0.450000, 0.000000, 1) PlaceSmd(2.225000, 16.325000, 0.450000, 0.450000, 0.000000, 1) PlaceSmd(1.375000, 16.325000, 0.450000, 0.450000, 0.000000, 1) PlaceSmd(2.225000, 17.000000, 0.450000, 0.400000, 0.000000, 1) PlaceSmd(1.375000, 17.000000, 0.450000, 0.400000, 0.000000, 1) PlaceInstance("R0201", 4.064000, 21.082000, False, 270.000000) PlaceSmd(4.064000, 21.337000, 0.430000, 0.280000, 0.000000, 1) PlaceSmd(4.064000, 20.827000, 0.430000, 0.280000, 0.000000, 1) curves = [] curves.append( rs.AddArc3Pt((12.887300, 33.495000, 0), (21.112700, 33.495000, 0), (17.000000, -0.000254, 0))) curves.append(rs.AddLine((21.112700, 33.495000, 0), (12.887300, 33.495000, 0))) curves.append( rs.AddCircle3Pt((21.679000, 29.210000, 0), (23.279000, 29.210000, 0), (22.479000, 30.010000, 0))) curves.append( rs.AddCircle3Pt((10.757000, 29.210000, 0), (12.357000, 29.210000, 0), (11.557000, 30.010000, 0))) curves.append( rs.AddCircle3Pt((12.916000, 2.032000, 0), (14.516000, 2.032000, 0), (13.716000, 2.832000, 0))) PlacePCB(curves)
def draw_offset_line(p1, p2, offset_vector): p1a = map(offset_coord, p1, offset_vector) p2a = map(offset_coord, p2, offset_vector) rs.AddLine(p1a, p2a)
def Grafo_Viga(viga, F_ext, Plano, dicPF, cirDir, Bconect, reac, nome_viga): bs, nbs, dg, ndg, bi, nbi = Elementos_vigas(viga) Bconect = rs.ExplodeCurves(Bconect) ptos = [] dicUp2 = {} for i in range(len(ndg) - 1): no = ndg[i] nomesNo = [] elementos = [] j = i // 2 #se banzo superior if i % 2 == 1: #Força extena f_ext = F_ext[j] p1 = f_ext.PointAt(0) p2 = f_ext.PointAt(1) f_ext = rs.AddLine(p1, p2) nomesNo.append('P' + str(j) + '_' + nome_viga) elementos.append(f_ext) #banzo superior nomesNo.append('bs' + str(j) + '_' + nome_viga) elementos.append(bs[j]) if not j == 0: nomesNo.append('bs' + str(j - 1) + '_' + nome_viga) elementos.append(bs[j - 1]) #diagonais nomesNo.append('dg' + str(i - 1) + '_' + nome_viga) elementos.append(dg[i - 1]) nomesNo.append('dg' + str(i) + '_' + nome_viga) elementos.append(dg[i]) #se banzo inferior elif i % 2 == 0: if i == 0: #reação p1 = reac.PointAt(0) p2 = reac.PointAt(1) reac = rs.AddLine(p1, p2) nome_reac = 'R' + '_' + nome_viga nomesNo.append(nome_reac) elementos.append(reac) if not j == 0: #diagonal anterior nomesNo.append('dg' + str(i - 1) + '_' + nome_viga) elementos.append(dg[i - 1]) #banzo inferior anterior nomesNo.append('bi' + str(j - 1) + '_' + nome_viga) elementos.append(bi[j - 1]) #diagonal posterior nomesNo.append('dg' + str(i) + '_' + nome_viga) elementos.append(dg[i]) #banzo inferior posterior nomesNo.append('bi' + str(j) + '_' + nome_viga) elementos.append(bi[j]) #ordenar linhas de ação em torno do nó nomesNo, elementos, countPF, countCalcular = OrdenaLinhasDeAcao( no, cirDir, elementos, nomesNo, dicPF, Plano) if countCalcular == 2: dicUp, ptos1 = Cremona2(no, nomesNo, elementos, countPF, dicPF) if countCalcular == 1: dicUp, ptos1 = Cremona1(no, nomesNo, elementos, countPF, dicPF) ptos += ptos1 dicPF.update(dicUp) dicUp2.update(dicUp) ####------conector------#### # ùltimo no do banzo superior no = nbs[-1] #elementos do conector elementos, nomesNo = elemntos_node(no, Bconect, 'bc', 'c') #ùltimo elemento do banzo superior elementos.append(bs[-1]) nomesNo.append('bs' + str(len(bs) - 1) + '_' + nome_viga) #Força externa f_ext = F_ext[len(F_ext) - 1] p1 = f_ext.PointAt(0) p2 = f_ext.PointAt(1) f_ext = rs.AddLine(p1, p2) nomesNo.append('P' + str(len(F_ext) - 1) + '_' + nome_viga) elementos.append(f_ext) #diagonal if len(dg) % 2 == 1: elementos.append(dg[-1]) nomesNo.append('dg' + str(len(dg) - 1) + '_' + nome_viga) nomesNo, elementos, countPF, countCalcular = OrdenaLinhasDeAcao( no, cirDir, elementos, nomesNo, dicPF, Plano) dicUp, ptos1 = Cremona2(no, nomesNo, elementos, countPF, dicPF) ptos += ptos1 dicPF.update(dicUp) dicUp2.update(dicUp) return dicUp2, ptos
#!/usr/bin/env python import rhinoscriptsyntax as rs import json data = json.load(open('/Users/dtasse/src/city_blocks/rhino_data.json')) for nghd in data: # if nghd['name'] != 'Central Oakland': # continue # uncomment the above to try out one nghd border_points = nghd['border'] curve = rs.AddPolyline(border_points) surface = rs.AddPlanarSrf(curve) extrusion_line = rs.AddLine((0,0,0), (0,0,3)) solid = rs.ExtrudeSurface(surface, extrusion_line) rs.DeleteObjects([curve, surface, extrusion_line]) for pipe in nghd['pipes']: p0 = pipe[0] p1 = pipe[1] pipe_line = rs.AddLine((p0[0], p0[1], -.5), (p1[0], p1[1], 3.5)) pipe = rs.AddPipe(pipe_line, 0, 0.5, cap=2) rs.DeleteObject(pipe_line) new_solid = None try: new_solid = rs.BooleanDifference([solid], [pipe]) except: print "a boolean difference failed in " + nghd['name'] rs.DeleteObject(pipe) continue
plate = rs.ExtrudeCurve(path, side) rs.DeleteObject(path) rs.DeleteObject(side) return plate def draw_rectangle1((x, y, z), theta): t = 1 p = (x, y, z) p0 = rs.AddPoint(p) p1 = rs.CopyObject(p0, polar(0.115, theta + 90, 0)) p2 = rs.CopyObject(p0, polar(0.115, theta - 90, 0)) p3 = rs.CopyObject(p2, polar(1.0, theta, 0)) p4 = rs.CopyObject(p1, polar(1.0, theta, 0)) rec = [ rs.AddLine(p1, p2), rs.AddLine(p2, p3), rs.AddLine(p3, p4), rs.AddLine(p4, p1) ] rs.MoveObject(rec, polar(0.4, theta, 0)) rect = rs.RotateObjects(rec, (0, 0, z), 90, (x, y, 0), True) rect = rs.MoveObjects(rect, polar(-1, theta, 0)) return rect def wakame(): h1 = 3 h2 = 6 p1_box = [] p2_box = []
def __init__(self): self.group_name = rs.AddGroup() self.line_guid = rs.AddLine((0, 0, 0), (5, 5, 0)) rs.AddObjectToGroup(self.line_guid, self.group_name)
def wakame(): h1 = 3 h2 = 6 p1_box = [] p2_box = [] for t in rs.frange(0, 360, 10): rg = ma.sin(ma.radians(t / 3 + 30)) / 2 + 1.3 hg = ma.sin(ma.radians(t / 2)) / 4 + 0.5 tt = 0.7 r_1 = 5 theta_1 = t h_1 = 0 p_1 = polar(r_1, theta_1, h_1) r_2 = 6 theta_2 = t h_2 = 11 * hg p_2 = polar(r_2, theta_2, h_2) r_3 = 10 * rg theta_3 = t h_3 = 15 * hg p_3 = polar(r_3, theta_3, h_3) r_4 = 15 * rg theta_4 = t h_4 = 15 * hg p_4 = polar(r_4, theta_4, h_4) r_5 = 5 + tt theta_5 = t h_5 = 0 p_5 = polar(r_5, theta_5, h_5) r_6 = 6 + tt theta_6 = t h_6 = 11 * hg - tt p_6 = polar(r_6, theta_6, h_6) r_7 = 10 * rg + tt theta_7 = t h_7 = 15 * hg - tt p_7 = polar(r_7, theta_7, h_7) r_8 = 15 * rg theta_8 = t h_8 = 15 * hg - tt p_8 = polar(r_8, theta_8, h_8) p_1_box = [p_1, p_2, p_3, p_4] cu1 = rs.AddCurve(p_1_box) p_2_box = [p_5, p_6, p_7, p_8] cu2 = rs.AddCurve(p_2_box) l1 = rs.AddLine(p_1, p_5) l2 = rs.AddLine(p_4, p_8) si = draw_sikaku(h1) p1 = rs.CurveSurfaceIntersection(cu1, si) p1_box.append(p1[0][1]) si = draw_sikaku(h2) p2 = rs.CurveSurfaceIntersection(cu1, si) p2_box.append(p2[0][1]) r1 = draw_rectangle1(p1[0][1], t) r2 = draw_rectangle1(p2[0][1], t) rs.RotateObjects(r1, (0, 0, 0), 90, polar(12, t, 0), False) rs.MoveObjects(r1, polar(0, t, 0)) rs.RotateObjects(r1, (0, 0, 0), -t, None, False) rs.MoveObjects(r1, (t * 0.12, t * 0.12, 0)) rs.RotateObjects(r2, (0, 0, 0), 90, polar(12, t, 0), False) rs.MoveObjects(r2, polar(0, t, 0)) rs.RotateObjects(r2, (0, 0, 0), -t, None, False) rs.MoveObjects(r2, (t * 0.12, t * 0.12, 0)) all = [l1, l2, cu1, cu2] rs.RotateObjects(all, (0, 0, 0), 90, polar(12, t, 0), False) rs.MoveObjects(all, polar(0, t, 0)) rs.RotateObjects(all, (0, 0, 0), -t, None, False) rs.MoveObjects(all, (t * 0.12, t * 0.12, 0)) c1 = rs.AddInterpCurve(p1_box) c2 = rs.AddInterpCurve(p2_box) rs.ScaleObject(c1, (0, 0, h1), (1.2, 1.2, 1), True) rs.ScaleObject(c2, (0, 0, h2), (1.1, 1.1, 1), True) rs.ScaleObject(c1, (0, 0, h1), (0.6, 0.6, 0.75), True) rs.ScaleObject(c2, (0, 0, h2), (0.9, 0.9, 1), True) rs.DeleteObject(c1) rs.DeleteObject(c2) all = [cu1, cu2] return all
import rhinoscriptsyntax as rs curves = rs.ObjectsByType(4) picturePlane = rs.GetObject("select the surface to use as the picture plane", 8) eyePoint = rs.GetObject( "select the point to use as the eye, the point at which the projected content will converge", 1) #note that we wouldn't need an eye point if our projectors are paralell for curve in curves: pointsOnCurve = rs.DivideCurve(curve, 100) intersectionPoints = [] for point in pointsOnCurve: projector = rs.AddLine(point, eyePoint) intersections = rs.CurveSurfaceIntersection(projector, picturePlane) if intersections: intersectionPoint = intersections[0][1] intersectionPoints.append(intersectionPoint) rs.AddPoints(intersectionPoints) rs.AddInterpCurve( intersectionPoints, 1) #what would be a more precise way to reconstruct the curve? #add layer management to sep process content from finish content, and to use close/far distinction
def stairHeight(route, width=48, height=120): """ Makes a stair to specified height. input: route(pline), width (num), height(num) returns: Geo """ try: rs.EnableRedraw(False) rs.SimplifyCurve(route) if route is None: print("ERROR: No path selected") return if (rs.UnitSystem() == 2): #if mm maxRiserHeight = 180 thickness = 200 if (rs.UnitSystem() == 4): #if m maxRiserHeight = .180 thickness = .200 if (rs.UnitSystem() == 8): #if in" maxRiserHeight = 7 thickness = 9 negativeBoo = False if (height < 0): #if the stair negativeBoo = True landingEdges = [] landings = [] segments = rs.ExplodeCurves(route) if len(segments) < 1: segments = [rs.CopyObject(route)] landingHeight = [] geometry = [] #Check that all segments are lines for i in range(0, len(segments)): if not (rs.IsLine(segments[i])): print( "ERROR: This function only accepts lines. No arcs or nurb curves." ) rs.DeleteObjects(segments) return #first landing edge norm = rs.VectorRotate(rs.CurveTangent(segments[0], 0), 90, [0, 0, 1]) norm = rs.VectorScale(rs.VectorUnitize(norm), width / 2) side1Pt = rs.VectorAdd(rs.CurveStartPoint(segments[0]), norm) side2Pt = rs.VectorAdd(rs.CurveStartPoint(segments[0]), -norm) landingEdges.append(rs.AddLine(side1Pt, side2Pt)) #middle landing edges for i in range(0, len(segments) - 1): edgeList, landing = rampIntersection(segments[i], segments[i + 1], width) landingEdges.append(edgeList[0]) landingEdges.append(edgeList[1]) landings.append(landing) #last landing edge norm = rs.VectorRotate( rs.CurveTangent(segments[-1], rs.CurveParameter(segments[-1], 1)), 90, [0, 0, 1]) norm = rs.VectorScale(rs.VectorUnitize(norm), width / 2) side1Pt = rs.VectorAdd(rs.CurveEndPoint(segments[-1]), norm) side2Pt = rs.VectorAdd(rs.CurveEndPoint(segments[-1]), -norm) landingEdges.append(rs.AddLine(side1Pt, side2Pt)) #Add risers riserCrvs = [] treadVecs = [] numRisersPerRun = [] numRisers = abs(int(math.ceil(height / maxRiserHeight))) risersSoFar = 0 totalRun = getTotalRun(landingEdges) optTreadDepth = totalRun / (numRisers - 1) #2R+T = 635 riserHeight = height / numRisers if (negativeBoo): curRiserHeight = 0 else: curRiserHeight = riserHeight for i in range(0, len(landingEdges), 2): #find numRisers in each run a = rs.CurveMidPoint(landingEdges[i]) b = rs.CurveMidPoint(landingEdges[i + 1]) runDist = rs.Distance(a, b) numRisersThisRun = int(round((runDist / optTreadDepth), 0)) if (numRisersThisRun == 0): numRisersThisRun = 1 if (i == len(landingEdges) - 2): #if last run, add the rest of the risers numRisersThisRun = numRisers - risersSoFar else: risersSoFar = risersSoFar + numRisersThisRun numRisersPerRun.append(numRisersThisRun) #Create Risers on Plan for i in range(0, len(landingEdges), 2): run = [] a = rs.CurveMidPoint(landingEdges[i]) b = rs.CurveMidPoint(landingEdges[i + 1]) centerStringer = rs.AddLine(a, b) runDist = rs.Distance(a, b) numRisersThisRun = numRisersPerRun[int(i / 2)] #risers in this run tarPts = rs.DivideCurve(centerStringer, numRisersThisRun, create_points=False) rs.DeleteObject(centerStringer) for j in range(0, numRisersThisRun + 1): if (j == 0): treadVecs.append(rs.VectorCreate(tarPts[0], tarPts[1])) transVec = rs.VectorCreate(tarPts[0], tarPts[j]) run.append(rs.CopyObject(landingEdges[i], -transVec)) riserCrvs.append(run) print('Flight {0} has {1} risers: {3}" tall, Treads: {2}" deep'. format( int(i / 2) + 1, numRisersThisRun, rs.VectorLength(treadVecs[int(i / 2)]), riserHeight)) #Move riser edges vertically for i in range(0, len(riserCrvs)): triangles = [] if (negativeBoo): for j in range(0, len(riserCrvs[i]) - 1): #if stairs descending rs.MoveObject( riserCrvs[i][j], rs.VectorAdd([0, 0, curRiserHeight], -treadVecs[i])) riserGeo = rs.ExtrudeCurveStraight(riserCrvs[i][j], [0, 0, 0], [0, 0, riserHeight]) treadGeo = rs.ExtrudeCurveStraight(riserCrvs[i][j], [0, 0, 0], treadVecs[i]) stPt = rs.AddPoint(rs.CurveStartPoint(riserCrvs[i][j])) pt1 = rs.CopyObject( stPt, [0, 0, riserHeight]) #first riser in run pt2 = rs.CopyObject(stPt, treadVecs[i]) #last riser in run triCrv = rs.AddPolyline([stPt, pt1, pt2, stPt]) triangles.append(rs.AddPlanarSrf(triCrv)) geometry.append(riserGeo) #riser geometry.append(treadGeo) #tread curRiserHeight = curRiserHeight + riserHeight rs.MoveObject(riserCrvs[i][j], treadVecs[i]) #cleanup rs.DeleteObject(triCrv) rs.DeleteObject(stPt) rs.DeleteObject(pt1) rs.DeleteObject(pt2) else: for j in range(0, len(riserCrvs[i]) - 1): #if stairs ascend rs.MoveObject(riserCrvs[i][j], [0, 0, curRiserHeight]) stPt = rs.AddPoint(rs.CurveStartPoint(riserCrvs[i][j])) pt1 = rs.CopyObject( stPt, [0, 0, -riserHeight]) #first riser in run pt2 = rs.CopyObject(stPt, -treadVecs[i]) #last riser in run triCrv = rs.AddPolyline([stPt, pt1, pt2, stPt]) triangles.append(rs.AddPlanarSrf(triCrv)) riserGeo = rs.ExtrudeCurveStraight(riserCrvs[i][j], [0, 0, 0], [0, 0, -riserHeight]) treadGeo = rs.ExtrudeCurveStraight(riserCrvs[i][j], [0, 0, 0], -treadVecs[i]) geometry.append(riserGeo) #riser geometry.append(treadGeo) #tread curRiserHeight = curRiserHeight + riserHeight #cleanup rs.DeleteObject(triCrv) rs.DeleteObject(stPt) rs.DeleteObject(pt1) rs.DeleteObject(pt2) #Make Stringer if (negativeBoo): firstStartPt = rs.AddPoint(rs.CurveStartPoint(riserCrvs[i][0])) lastStartPt = rs.AddPoint(rs.CurveStartPoint(riserCrvs[i][-2])) #rs.MoveObject(firstStartPt, [0,0,riserHeight]) #first riser in run rs.MoveObject(lastStartPt, -treadVecs[i]) #last riser in run rs.MoveObject(lastStartPt, [0, 0, riserHeight]) #last riser in run else: firstStartPt = rs.AddPoint(rs.CurveStartPoint(riserCrvs[i][0])) lastStartPt = rs.AddPoint(rs.CurveStartPoint(riserCrvs[i][-2])) rs.MoveObject(firstStartPt, [0, 0, -riserHeight]) #first riser in run rs.MoveObject(lastStartPt, -treadVecs[i]) #last riser in run stringerCrv = rs.AddLine(firstStartPt, lastStartPt) stringerSrf = rs.ExtrudeCurveStraight(stringerCrv, [0, 0, 0], [0, 0, -thickness]) triangles.append(stringerSrf) stringer = makeFace(triangles) stringerVec = rs.VectorCreate(rs.CurveEndPoint(riserCrvs[i][0]), rs.CurveStartPoint(riserCrvs[i][0])) underside = rs.ExtrudeCurveStraight( stringerCrv, rs.CurveStartPoint(riserCrvs[i][0]), rs.CurveEndPoint(riserCrvs[i][0])) geometry.append(rs.MoveObject(underside, [0, 0, -thickness])) geometry.append(rs.CopyObject(stringer, stringerVec)) geometry.append(stringer) #cleanup rs.DeleteObject(firstStartPt) rs.DeleteObject(lastStartPt) rs.DeleteObject(stringerCrv) rs.DeleteObject(stringerSrf) #Move Landings lastLandingHeight = 0 for i in range(0, len(segments) - 1): landingHeight = lastLandingHeight + numRisersPerRun[i] * riserHeight rs.MoveObject(landings[i], [0, 0, landingHeight]) landingTopSrf = rs.AddPlanarSrf(landings[i]) landingBtmSrf = rs.CopyObject(landingTopSrf, [0, 0, -thickness]) geometry.append(landingTopSrf) geometry.append(landingBtmSrf) lastLandingHeight = landingHeight landingEdgesToEx = rs.ExplodeCurves(landings[i]) geometry.append( rs.ExtrudeCurveStraight(landingEdgesToEx[1], [0, 0, 0], [0, 0, -thickness])) geometry.append( rs.ExtrudeCurveStraight(landingEdgesToEx[2], [0, 0, 0], [0, 0, -thickness])) rs.DeleteObjects(landingEdgesToEx) #Create final geometry joinedGeo = rs.JoinSurfaces(geometry, True) holes = rs.DuplicateSurfaceBorder(joinedGeo) cap = rs.AddPlanarSrf(holes) newGeo = rs.ExplodePolysurfaces(joinedGeo, True) for i in cap: newGeo.append(i) FinalGeo = rs.JoinSurfaces(newGeo, True) #cleanup try: rs.DeleteObjects(segments) except: rs.DeleteObject(segments) rs.DeleteObjects(holes) rs.DeleteObjects(landings) rs.DeleteObjects(landingEdges) for i in riserCrvs: rs.DeleteObjects(i) rs.EnableRedraw(True) return FinalGeo except: print "Error" return None
def AddVector(vecdir, base_point=None): # Draws a vector (for visualization purposes) base_point = base_point or [0, 0, 0] tip_point = rs.PointAdd(base_point, vecdir) line = rs.AddLine(base_point, tip_point) if line: return rs.CurveArrows(line, 2) # adds an arrow tip
import rhinoscriptsyntax as rs num = rs.GetReal("line length x-dir") line = rs.AddLine([9, 7, 2], [num, 0, 0]) print "curve inserted with id", line
def Main(): rectangle = rs.GetObject( "Select rectangle to create mortise and tenon from", rs.filter.curve, True, True) if rs.IsCurveClosed(rectangle): x = 0 else: print "Failed....Curve must be closed and rectangular" return if rs.IsCurvePlanar(rectangle): x = 0 else: print "Failed....Curve must be planar" return lines = rs.ExplodeCurves(rectangle) count = 0 for line in lines: count = count + 1 if count != 4: print "Failed....To many line segments, redraw rectangle" return if rs.IsLine(lines[0]): x = 0 else: print "Failed....Curve must be rectangular" return if rs.IsLine(lines[1]): x = 0 else: print "Failed....Curve must be rectangular" return if rs.IsLine(lines[2]): x = 0 else: print "Failed....Curve must be rectangular" return if rs.IsLine(lines[3]): x = 0 else: print "Failed....Curve must be rectangular" return face = rs.GetObject("Select tenon surface", rs.filter.surface, False, True, None, True) length = rs.GetReal("Enter tenon length", number=None) if length and length != 0: x = 0 else: print "Failed....No length was entered" return depth = rs.GetReal("Enter mortise depth", number=length + 0.05) if depth and depth != 0: x = 0 else: print "Failed....No depth was entered" return fit = rs.GetReal("Enter mortise fit", number=0.01) line1 = rs.AddLine(rs.CurveStartPoint(lines[0]), rs.CurveEndPoint(lines[0])) line2 = rs.AddLine(rs.CurveStartPoint(lines[1]), rs.CurveEndPoint(lines[1])) line3 = rs.AddLine(rs.CurveStartPoint(lines[2]), rs.CurveEndPoint(lines[2])) line4 = rs.AddLine(rs.CurveStartPoint(lines[3]), rs.CurveEndPoint(lines[3])) rs.DeleteObjects(lines) lines = line1, line2, line3, line4 if rs.CurveLength(lines[0]) > rs.CurveLength(lines[1]): smallside = rs.CurveLength(lines[1]) longside1 = lines[0] longside2 = lines[2] else: smallside = rs.CurveLength(lines[0]) longside1 = lines[1] longside2 = lines[3] filletRadius = smallside / 2 fillet1 = rs.CurveFilletPoints(lines[0], lines[1]) fillet2 = rs.CurveFilletPoints(lines[1], lines[2]) fillet3 = rs.CurveFilletPoints(lines[2], lines[3]) fillet4 = rs.CurveFilletPoints(lines[3], lines[0]) arc1 = rs.AddFilletCurve(lines[0], lines[1], radius=filletRadius) arc2 = rs.AddFilletCurve(lines[1], lines[2], radius=filletRadius) arc3 = rs.AddFilletCurve(lines[2], lines[3], radius=filletRadius) arc4 = rs.AddFilletCurve(lines[3], lines[0], radius=filletRadius) arcs = arc1, arc2, arc3, arc4 arcs = rs.JoinCurves(arcs) arcEnd1 = rs.CurveEndPoint(arcs[0]) arcStart1 = rs.CurveStartPoint(arcs[0]) arcEnd2 = rs.CurveEndPoint(arcs[1]) arcStart2 = rs.CurveStartPoint(arcs[1]) if rs.Distance(arcEnd1, arcEnd2) > rs.Distance(arcEnd1, arcStart2): temp = arcEnd2 arcEnd2 = arcStart2 arcStart2 = temp line1 = rs.AddLine(arcEnd1, arcEnd2) line2 = rs.AddLine(arcStart1, arcStart2) curves = line1, arcs[0], arcs[1], line2 tenonOut = rs.JoinCurves(curves) tenonSurf = rs.AddPlanarSrf(tenonOut) point = rs.SurfacePoints(face) param = rs.SurfaceClosestPoint(face, point[0]) normal = rs.SurfaceNormal(face, param) normal = normal * length vect = rs.AddLine(arcEnd1, arcEnd1 + normal) tenon = rs.ExtrudeSurface(tenonSurf, vect, cap=True) rs.DeleteObjects(curves) arcs = arc1, arc2, arc3, arc4 rs.DeleteObjects(arcs) rs.DeleteObject(rectangle) rs.ExtendCurveLength(longside1, 0, 0, fit) rs.ExtendCurveLength(longside1, 0, 1, fit) rs.ExtendCurveLength(longside2, 0, 0, fit) rs.ExtendCurveLength(longside2, 0, 1, fit) if rs.Distance(rs.CurveEndPoint(longside1), rs.CurveEndPoint(longside2)) < rs.Distance( rs.CurveStartPoint(longside1), rs.CurveEndPoint(longside2)): line1Start = rs.CurveEndPoint(longside1) line1End = rs.CurveEndPoint(longside2) line2Start = rs.CurveStartPoint(longside1) line2End = rs.CurveStartPoint(longside2) else: line1Start = rs.CurveStartPoint(longside1) line1End = rs.CurveEndPoint(longside2) line2Start = rs.CurveEndPoint(longside1) line2End = rs.CurveStartPoint(longside2) shortside1 = rs.AddLine(line1Start, line1End) shortside2 = rs.AddLine(line2Start, line2End) arc1 = rs.AddFilletCurve(longside1, shortside1, radius=filletRadius) arc2 = rs.AddFilletCurve(shortside1, longside2, radius=filletRadius) arc3 = rs.AddFilletCurve(longside2, shortside2, radius=filletRadius) arc4 = rs.AddFilletCurve(shortside2, longside1, radius=filletRadius) arcs = arc1, arc2, arc3, arc4 arcs = rs.JoinCurves(arcs) arcEnd1 = rs.CurveEndPoint(arcs[0]) arcStart1 = rs.CurveStartPoint(arcs[0]) arcEnd2 = rs.CurveEndPoint(arcs[1]) arcStart2 = rs.CurveStartPoint(arcs[1]) if rs.Distance(arcEnd1, arcEnd2) > rs.Distance(arcEnd1, arcStart2): temp = arcEnd2 arcEnd2 = arcStart2 arcStart2 = temp line1 = rs.AddLine(arcEnd1, arcEnd2) line2 = rs.AddLine(arcStart1, arcStart2) curves = line1, arcs[0], arcs[1], line2 mortiseOut = rs.JoinCurves(curves) mortiseSurf = rs.AddPlanarSrf(mortiseOut) param = rs.SurfaceClosestPoint(face, point[0]) normal = rs.SurfaceNormal(face, param) normal = normal * depth vect = rs.AddLine(arcEnd1, arcEnd1 + normal) mortise = rs.ExtrudeSurface(mortiseSurf, vect, cap=True) rs.DeleteObject(shortside1) rs.DeleteObject(shortside2) rs.DeleteObject(mortiseOut) rs.DeleteObject(mortiseSurf) rs.DeleteObjects(curves) rs.DeleteObjects(lines) arcs = arc1, arc2, arc3, arc4 rs.DeleteObjects(arcs) rs.DeleteObject(rectangle) rs.DeleteObject(tenonOut) rs.DeleteObject(tenonSurf) return
def AddVector(base, vec): tip = rs.PointAdd(base, vec) line = rs.AddLine(base, tip) rs.CurveArrows(line, 2)
# Structure mdl = Structure(name='beam_simple', path='C:/Temp/') # Clear clear_layers(['elset_lines', 'nset_left', 'nset_right', 'nset_weights']) rs.EnableRedraw(False) # Lines L = 1.0 m = 100 x = [i * L / m for i in range(m + 1)] rs.CurrentLayer('elset_lines') [rs.AddLine([x[i], 0, 0], [x[i + 1], 0, 0]) for i in range(m)] # Points n = 5 rs.CurrentLayer('nset_left') rs.AddPoint([0, 0, 0]) rs.CurrentLayer('nset_right') rs.AddPoint([L, 0, 0]) rs.CurrentLayer('nset_weights') for xi in x[n::n]: rs.AddPoint([xi, 0, 0]) rs.EnableRedraw(True) # Elements
def render(self): #rs.AddSphere (self.pos, rnd.random() * 1) #rs.AddPoint (self.pos) rs.AddLine(self.pos, self.posP)
bottom_planes.append(planes) # Rotate planes on ZAxis rotated_planes = [] for i in bottom_planes: plane = rs.ViewCPlane() rndm_angle = random.randrange(-5, 5) rotated_z = rs.RotatePlane(i, rndm_angle, planes.ZAxis) # Tilt control tilt = random.randrange(-5, 5) * max_tilt rotated_x = rs.RotatePlane(rotated_z, tilt, planes.XAxis) rotated_planes.append(rotated_x) # Create solids solids = [] lines = [] for j in range(0, len(rotated_planes)): line = rs.AddLine(bottom_pts[j], top_pts[j]) lines.append(line) tilt = random.randrange(-5, 5) * max_tilt rot_lines = rs.RotateObject(line, bottom_pts[j], tilt, planes.XAxis, copy=False) rct = rs.AddRectangle( rotated_planes[j], rg.Interval(-0.5 * block_w, 0.5 * block_w), rg.Interval(-0.5 * block_d, 0.5 * block_d)) solid = rs.ExtrudeCurve(rct, rot_lines) sld = rs.CapPlanarHoles(solid) solids.append(solid) print('Ivan Perez | [email protected] | Bogotá | Colombia')
import rhinoscriptsyntax as rs from random import random as r from time import sleep from Rhino import RhinoApp rs.AddRectangle(rs.WorldXYPlane(), 4, 4) for i in range(1, 4): line = rs.AddLine([i, 0, 0], [i, 4, 0]) rs.ObjectLinetype(line, 'Hidden') line = rs.AddLine([0, i, 0], [4, i, 0]) rs.ObjectLinetype(line, 'Hidden') rs.AddTextDot('<', [1, 6, 0]) rs.AddTextDot('^', [2, 7, 0]) rs.AddTextDot('>', [3, 6, 0]) rs.AddTextDot('v', [2, 5, 0]) rs.ZoomExtents() winText = 0 win = 0 pts = [[0 for j in range(4)] for i in range(4)] c = 0 d = 0 recs = [[0 for j in range(4)] for i in range(4)] tags = [[0 for j in range(4)] for i in range(4)] def fill(pts): a = int(r() * 4)