def main(): # first, select objects in three orthogonal planes xs = rs.GetObjects("select X objects", filter=16) # polysurface ys = rs.GetObjects("select Y objects", filter=16) zs = rs.GetObjects("select Z objects", filter=16) subdivisions = rs.GetInteger(message="enter subdivisions (odd)", number=5, minimum=2, maximum=None) for positive, negative, hidden in ((xs, ys, zs), (xs, zs, ys), (ys, zs, xs)): rs.HideObjects(hidden) make_fingers(positive, negative, subdivisions) rs.ShowObjects(hidden) # each time make_fingers is run, it fills guid_to_difference # with more fingers to subtract. # after all the fingers are subtracted at once for guid, objs in guid_to_difference.items(): if objs: rs.BooleanDifference(guid, objs)
def MakePlan(elevation, viewDepthZ, geos): objs = rs.CopyObjects(geos) rs.HideObjects(geos) ############################################################################ print "Cutting Plan" allCrvs = [] #Make plane plane = Rhino.Geometry.Plane(rs.coerce3dpoint((0, 0, elevation)), rs.coerce3dvector((0, 0, 1))) planeNeg = Rhino.Geometry.Plane(rs.coerce3dpoint((0, 0, viewDepthZ)), rs.coerce3dvector((0, 0, 1))) ############################################################################ #Partition the geometry partitionedObjs = PartitionGeometry(objs, elevation, viewDepthZ) ############################################################################ #Intersection Curves #interCrvs = IntersectGeos(partitionedObjs[1], plane) ############################################################################ #Split Geometry #Get the bottom half of intersecting objs belowObjs = SplitGeometry(partitionedObjs[1], plane) print "A" #Get the top half of that previous geometry visibleObjs = SplitGeometry(partitionedObjs[0] + belowObjs, planeNeg, -1) rs.SelectObjects(visibleObjs) objs2del = rs.InvertSelectedObjects() rs.DeleteObjects(objs2del) print "A" ############################################################################ #Make 2D allCrvs += ProjectPlan(visibleObjs, plane) rs.DeleteObjects(visibleObjs) print "Plan Cut" rs.ShowObjects(geos) rs.HideObjects(allCrvs) return allCrvs
def GetPointDynamicDrawFuncHide(sender, args): obj_all = rs.VisibleObjects() rs.HideObjects(obj_all) cursPos = rs.GetCursorPos() viewSize = rs.ViewSize() stepSize = int(viewSize[1] / _NUM_LAYER) obj_Layer1 = 'Layer: 000001 Wall1' obj_Layer2 = 'Layer: 000002 Wall1' settings = Rhino.DocObjects.ObjectEnumeratorSettings() settings.HiddenObjects = True settings.NameFilter = obj_Layer1 ids_L1 = [rhobj.Id for rhobj in scriptcontext.doc.Objects.GetObjectList(settings)] settings.NameFilter = obj_Layer2 ids_L2 = [rhobj.Id for rhobj in scriptcontext.doc.Objects.GetObjectList(settings)] z_L1 = rs.BoundingBox(ids_L1[0])[0][2] z_L2 = rs.BoundingBox(ids_L2[0])[0][2] zVal = viewSize[1] - cursPos[3][1] z_level = int(zVal / stepSize) segmentList = ['Wall', 'DenseInfill', 'SparseInfill', 'Brim', 'Skirt', 'Support'] zero_str = '000000' settings = ObjectEnumeratorSettings() settings.HiddenObjects = True for segment in segmentList: i = 0 while 1: i += 1 obj_LayerZ = str('Layer: ' + zero_str[:-len(str(z_level))] + str(z_level) + ' ' + segment + str(i)) try: settings.NameFilter = obj_LayerZ ids_LZ = [rhobj.Id for rhobj in scriptcontext.doc.Objects.GetObjectList(settings)] if len(ids_LZ) == 0: break # rs.SelectObject(ids_LZ) rs.ShowObject(ids_LZ) except: print 'not found' args.Display.DrawDot(args.CurrentPoint, 'Layer ' + str(z_level) + ' - Distance ' + str(z_L2 - z_L1) + ' mm') Rhino.Display.RhinoView.Redraw(scriptcontext.doc.Views.ActiveView) Rhino.RhinoApp.Wait()
def set_mesh_objects(self): sys.path.append(self.pluginPath) object_ids = rs.ObjectsByType(32 | 16, True) objects_visible = True view = rs.CurrentView() for obj in object_ids: rs.HideObjects(obj)
def draw_line_hide(self): obj_all = rs.VisibleObjects() rs.HideObjects(obj_all) # Create an instance of a GetPoint class and add a delegate for the DynamicDraw event gp = Rhino.Input.Custom.GetPoint() # gp = Rhino.Input.Custom.PickContext() gp.DynamicDraw += GetPointDynamicDrawFuncHide gp.Get() obj_all = rs.HiddenObjects() rs.ShowObjects(obj_all)
def generate_part_images(structure): global view_aspect w_l = conf['part_img_width'] h_l = int(w_l / view_aspect) for iSub in xrange(len(structure)): subsystem = structure.keys()[iSub] v = structure[subsystem] utils.show_only(subsystem) utils.hide_children(subsystem) for iStep in xrange(len(v)): step = v.keys()[iStep] vv = v[step] stepnumeral = str(iSub + 1) + '.' + str(iStep + 1) rs.LayerVisible(step, True) for partkind, vvv in vv.items(): rs.HideObjects(vvv) for partkind, vvv in vv.items(): if len(vvv) >= 1: part = vvv[0] rs.ShowObject(part) # create images rs.RestoreNamedView(conf['persp_view']) rs.ZoomExtents() create_view_image( conf['part_img_persp'] % (stepnumeral, partkind), w_l, h_l) rs.RestoreNamedView(conf['top_view']) rs.ZoomExtents() create_view_image( conf['part_img_top'] % (stepnumeral, partkind), w_l, h_l) rs.RestoreNamedView(conf['front_view']) rs.ZoomExtents() create_view_image( conf['part_img_front'] % (stepnumeral, partkind), w_l, h_l) rs.RestoreNamedView(conf['right_view']) rs.ZoomExtents() create_view_image( conf['part_img_right'] % (stepnumeral, partkind), w_l, h_l) # rs.HideObject(part) for partkind, vvv in vv.items(): rs.ShowObject(vvv) rs.LayerVisible(step, False) # utils.show_children(subsystem) utils.show_step_children(subsystem) utils.show_blocks() utils.show_subsystems() rs.ZoomExtents()
def main(): # first, select objects in three orthogonal planes xs = rs.GetObjects("select X objects", filter=16); # polysurface ys = rs.GetObjects("select Y objects", filter=16); zs = rs.GetObjects("select Z objects", filter=16); subdivisions = rs.GetInteger(message="enter subdivisions (o)", number=5, minimum=2, maximum=None) for positive, negative, hidden in ((xs, ys, zs), (xs, zs, ys), (ys, zs, xs)): rs.HideObjects(hidden) finger.make_fingers(positive, negative, subdivisions) rs.ShowObjects(hidden) finger.perform_subtraction()
def isolateLayerObjects(): """ Isolate a layers objects input: None return: None """ objs = rs.GetObjects("Select object on layer to isolate", preselect=True) if objs is None: return rs.EnableRedraw(False) layersToKeep = [] for obj in objs: rs.SelectObjects(rs.ObjectsByLayer(rs.ObjectLayer(obj))) objs2keep = rs.InvertSelectedObjects() if objs2keep is None: return rs.HideObjects(objs2keep) rs.EnableRedraw(True)
def IsolateObjLayer(): try: # Get object and find layer it is on obj = rs.GetObjects('select an object on the layer to isolate', preselect=True) if obj: rs.EnableRedraw(False) # Create list of selected obj layers selectedlayers = [] for i in obj: layer = rs.ObjectLayer(i) selectedlayers.append(layer) # Select all objects on each layer for i in selectedlayers: rs.ObjectsByLayer(i, True) isolate = rs.SelectedObjects() allObjects = rs.AllObjects() for i in isolate: allObjects.remove(i) # Hide selected objects rs.HideObjects(allObjects) rs.UnselectAllObjects() rs.EnableRedraw(True) except: print("Failed to execute") rs.EnableRedraw(True) return
print " " count = rs.GetInteger( "How many GENERATIONS would you like to iterate?", 1, 1, 100) print " " print "CONTINUING iterating for [", count, "] GENERATIONS." rs.EnableRedraw(False) continue print " " print "The iterations have ENDED. [", totalAttempts, "] solutions were tested." print "Your final best fit had a FACTOR of [", bestPoint[ 0], "] and a FITNESS of [", bestPoint[1], "]." fFactor = bestPoint[0] return fFactor rs.HideObjects(sortedCurves) minLenFactor = devLenFactor(sortedCurves) rs.ShowObjects(sortedCurves) minLength = minLength**minLenFactor #Now, split the list into smaller lists, first with defining a function that tests whether the length meets the criteria. Returns either True or False. def meetsLength(len, startCrv, endCrv): objects = [startCrv, endCrv] boundingBox = rs.BoundingBox(objects, in_world_coords=True) curLen = rs.Distance(boundingBox[0], boundingBox[1]) if curLen >= len: return True else: return False
return edges if __name__ == '__main__': crvs = rs.GetObjects("Select mesh edges", 4) lines = get_line_coordinates(crvs) mesh = Mesh.from_lines(lines, delete_boundary_face=True) artist = MeshArtist(mesh, layer='new_lines') artist.draw_edges() artist.redraw() # select edge rs.HideObjects(crvs) edge = mesh_select_edge(mesh, "select a mesh edge") rs.ShowObjects(crvs) # select edge artist.clear_edges() # find "every second" edge (joint lines) new_lines = [] para_edges = get_parallel_edges(mesh, edge) for u, v in para_edges[2::2]: new_lines.append((u, v)) # draw new lines artist.draw_edges(keys=new_lines, color=(255, 0, 0))
rs.MoveObject(pla_obj, pla_pos) #Section start and end points sec_str = pla_pos sec_end = rs.PointAdd(pla_pos, pnt_ste) #Create the section view rs.CurrentLayer(layer='lay_fro_sec') rs.ObjectsByGroup('obj_all', select=True) rs.CurrentView('Top') rs.Command('-_Section ' + str(sec_str) + ' ' + str(sec_end) + ' _Enter') #Prepare the shot rs.CurrentView('Back') rs.CurrentView('Front') rs.HideObjects(obj_all) rs.UnselectAllObjects() #Take the shot img_des = dir_tar + dir_mai + dir_sec + pfx_sec + str(i) + '.png' rs.Command('-_ViewCaptureToFile ' + img_des + ' _DrawGrid=No' + ' _Width=' + str(img_wid) + ' _Height=' + str(img_hei) + ' _Scale=' + str(img_sca) + ' _TransparentBackground=No' + ' _Enter' + ' _Enter') #Prepare the environment for the next iteration pla_pos[1] = pla_pos[1] - vis_ste rs.ShowObjects(obj_all) rs.DeleteObjects(pla_obj) sec_cur = rs.ObjectsByType(4) rs.DeleteObjects(sec_cur)
def relax_mesh_on_surface(): polylines = rs.ObjectsByLayer("re_02_polys") pts_objs = rs.ObjectsByLayer("re_03_points") vis = 5 kmax = 2000 dis = 0.3 dev_threshold = 0.003 angle_max = 30 pts = get_points_coordinates(pts_objs) mesh = Mesh() for i, pt in enumerate(pts): mesh.add_vertex(str(i), {'x': pt[0], 'y': pt[1], 'z': pt[2]}) polys = get_polyline_points(polylines) tris = get_faces_from_polylines(polys, pts) for tri in tris: mesh.add_face(tri) rs.EnableRedraw(False) pts = [] for key, a in mesh.vertices_iter(True): pt1 = (a['x'], a['y'], a['z']) pts.append(pt1) vec = mesh.vertex_normal(key) vec = scale(normalize(vec), dis) pt2 = add_vectors(pt1, vec) pt2 = add_vectors(pt1, vec) a['x2'] = pt2[0] a['y2'] = pt2[1] a['z2'] = pt2[2] a['normal'] = vec #rs.AddLine(pt1,pt2) faces_1 = draw(mesh, dev_threshold) rs.HideObjects(faces_1) for k in range(kmax): nodes_top_dict = {key: [] for key in mesh.vertices()} polys = [] max_distances = [] for u, v in mesh.edges(): pt1 = mesh.vertex_coordinates(u) pt2 = mesh.vertex_coordinates(v) pt3 = mesh.vertex[u]['x2'], mesh.vertex[u]['y2'], mesh.vertex[u][ 'z2'] pt4 = mesh.vertex[v]['x2'], mesh.vertex[v]['y2'], mesh.vertex[v][ 'z2'] points = [pt1, pt2, pt3, pt4] points = rs.coerce3dpointlist(points, True) rc, plane = Rhino.Geometry.Plane.FitPlaneToPoints(points) pt3, pt4 = [plane.ClosestPoint(pt) for pt in points[2:]] vec = scale(normalize(subtract_vectors(pt3, pt1)), dis) pt3 = add_vectors(pt1, vec) vec = scale(normalize(subtract_vectors(pt4, pt2)), dis) pt4 = add_vectors(pt2, vec) nodes_top_dict[u].append(pt3) nodes_top_dict[v].append(pt4) distances = [ distance(pt1, pt2) for pt1, pt2 in zip(points[2:], [pt3, pt4]) ] max_distances.append(max(distances)) for key, a in mesh.vertices_iter(True): cent = centroid(nodes_top_dict[key]) pt = mesh.vertex_coordinates(key) vec = subtract_vectors(cent, pt) norm = a['normal'] if angle_smallest(vec, norm) < angle_max: a['x2'] = cent[0] a['y2'] = cent[1] a['z2'] = cent[2] if k % vis == 0: rs.Prompt( "Iteration {0} of {1} with with deviation sum {2}".format( k, kmax, round(sum(max_distances), 4))) draw_light(mesh, temp=True) if max(max_distances) < dev_threshold or k == kmax: print "Iteration {0} of {1} with deviation sum {2}".format( k, kmax, round(sum(max_distances), 4)) break dfaces_2 = draw(mesh, dev_threshold) rs.ShowObjects(faces_1) rs.EnableRedraw(True) print max(max_distances)
def main(): global inner_curves, outer_curves, curve_coords # save for later orig_hidden_objects = rs.HiddenObjects() # we put reference points in the dogbone-ref layer, so create it if it doesn't exist rs.AddLayer("dogbone-ref") panel, face = getsubsurface.GetSubSurface("select dogbone face") diameter = rs.GetReal("enter cutter diameter", number=0.25) diameter = diameter * 1.1 rs.EnableRedraw(False) # compute the plane normal = rs.VectorUnitize(rs.SurfaceNormal(face, (0.5, 0.5))) plane = rs.PlaneFromNormal(rs.EvaluateSurface(face, 0.5, 0.5), normal) rs.ViewCPlane(plane=plane) rs.ProjectOsnaps(True) outer_curves = rs.DuplicateSurfaceBorder(face, 1) inner_curves = rs.DuplicateSurfaceBorder(face, 2) # make a dict mapping each curve to the coords in that curve curve_coords = dict() for curve in outer_curves + inner_curves: coords = rs.CurvePoints(curve)[:-1] curve_coords[curve] = coords # make a dict mapping each curve to the z component of its cross product at each index curve_cross_zs = dict() for curve, coords in curve_coords.items(): proj_coords = [rs.SurfaceClosestPoint(face, coord) for coord in coords] cross_zs = [] for idx in range(len(proj_coords)): triplet = [ proj_coords[(idx + 1) % len(proj_coords)], proj_coords[idx], proj_coords[(idx - 1) % len(proj_coords)] ] v0 = (triplet[1][0] - triplet[0][0], triplet[1][1] - triplet[0][1], 0) v1 = (triplet[2][0] - triplet[1][0], triplet[2][1] - triplet[1][1], 0) cross_z = rs.VectorCrossProduct(v0, v1)[2] cross_zs.append(cross_z) curve_cross_zs[curve] = cross_zs points = [] bones = [] temp_points = [] rs.EnableRedraw(True) while True: coord = rs.GetPoint("select corner") if coord is None: break try: curve, idx = get_curve_and_idx_for_coord(coord) point = rs.AddPoint(coord) rs.ObjectColor(point, (255, 0, 0)) temp_points.append(point) bones.append((curve, idx)) except ValueError: print "invalid curve point" continue rs.EnableRedraw(False) rs.DeleteObjects(temp_points) # try to automatically identify dogbone points if user selected none if len(bones) == 0: for curve, coords in curve_coords.items(): proj_coords = [ rs.SurfaceClosestPoint(face, coord) for coord in coords ] for idx in range(len(proj_coords)): triplet = [ proj_coords[(idx + 1) % len(proj_coords)], proj_coords[idx], proj_coords[(idx - 1) % len(proj_coords)] ] if curve_cross_zs[curve][idx] > 0: bones.append((curve, idx)) # make the bones extrusions = [] for bone in bones: curve, idx = bone coords = curve_coords[curve] point = rs.AddPoint(coords[idx]) rs.ObjectLayer(point, "dogbone-ref") triplet = [ coords[(idx + 1) % len(coords)], coords[idx], coords[(idx - 1) % len(coords)], ] angle = rs.Angle2( (triplet[1], triplet[0]), (triplet[1], triplet[2]), ) angle = angle[0] # This is a hacky method to determine the handedness of the curve # the cross product SHOULD have worked here, but for some reason # it did not. v0 = triplet[2][0] - triplet[1][0], triplet[2][1] - triplet[1][1], 0 v1 = triplet[1][0] - triplet[0][0], triplet[1][1] - triplet[0][1], 0 _angle = math.degrees( math.atan2(v0[1], v0[0]) - math.atan2(v1[1], v1[0])) while _angle > 180: _angle -= 360 while _angle < -180: _angle += 360 if math.copysign(1, angle) != math.copysign(1, _angle): angle -= 180 point = rs.VectorAdd( triplet[1], rs.VectorRotate( 0.5 * diameter * rs.VectorUnitize(rs.VectorSubtract(triplet[2], triplet[1])), angle / 2, (0, 0, 1))) circle = rs.AddCircle((point.X, point.Y, -10), diameter / 2.0) circle_srf = rs.AddPlanarSrf(circle) p0 = (point.X, point.Y, -10) p1 = (point.X, point.Y, 10) line = rs.AddLine(p0, p1) extrusion = rs.ExtrudeSurface(circle_srf, line) extrusions.append(extrusion) rs.DeleteObjects([circle, circle_srf, line]) rs.BooleanDifference([panel], extrusions, delete_input=True) rs.DeleteObject(panel) rs.DeleteObjects(extrusions) rs.DeleteObjects(points) rs.DeleteObjects(inner_curves) rs.DeleteObjects(outer_curves) rs.DeleteObject(face) rs.ShowObject(rs.AllObjects()) rs.HideObjects(orig_hidden_objects) rs.EnableRedraw(True)
gap = .8 spaceBetweenBricks = length+gap rowCount = 10 rotation = 0 #create the world axis as vectors worldZAxis = rs.VectorCreate([0,0,1],[0,0,0]) #create curves to define wall and loft to get wall surface upperCurve = rs.AddCurve([[0,0,0],[50,0,0]]) lowerCurve = rs.AddCurve([[0,0,0],[50,0,0]]) #lowerCurve = rs.AddCurve(rs.GetPoints(True,True,'Please select points to create lower curve of wall')) #upperCurve = rs.AddCurve(rs.GetPoints(True,True,'Please select points to create upper curve of wall, be sure to start on the same end of the wall as the lower curve')) upperCurve2 = rs.CopyObject(upperCurve,rs.VectorScale(worldZAxis,(height*rowCount))) loftedSurface = rs.AddLoftSrf([lowerCurve,upperCurve2]) rs.HideObjects([loftedSurface,lowerCurve,upperCurve,upperCurve2]) #intersect planes with surface to get the profile of the wall at each row intersected = rs.AddSrfContourCrvs(loftedSurface,([0,0,0], [0,0,(height*rowCount)]),height) rs.HideObjects(intersected) #make list of even and list of odd row profiles intersectedEven = [] intersectedOdd = [] for i in range(len(intersected)): if i%2 == 0 : intersectedEven.append(intersected[i]) else: intersectedOdd.append(intersected[i]) #divide each list of rows and save points and tangents
def hatchedCurve(): """ this script divides a curve by length and makes a hatch-dashed version of it' works only in world top version 1.1 www.studiogijs.nl """ projection = Rhino.Geometry.Vector3d(0, 0, 1) viewprojection = sc.doc.Views.ActiveView.ActiveViewport.CameraZ if not viewprojection == projection: print " this script only works in top view" return getcurves = rs.GetObjects( "select curves to change into hatch-dashed-style", 4, preselect=True) rs.UnselectAllObjects() if not getcurves: return s = sc.sticky['scale'] if sc.sticky.has_key('scale') else 1 scale = rs.GetReal("line-width of the hatch-dashed curve", s, .5, 5) if not scale: return sc.sticky['scale'] = scale f = sc.sticky['factor'] if sc.sticky.has_key('factor') else 5 factor = rs.GetReal("line-length factor of the hatch-dashed curve", f, 1, 10) if not factor: return sc.sticky['factor'] = factor #turn of the lights, magic should be done in darkness rs.EnableRedraw(False) style = Rhino.Geometry.CurveOffsetCornerStyle.Sharp tol = sc.doc.ModelAbsoluteTolerance plane = Rhino.Geometry.Plane.WorldXY subcurvelist = [] offset_curves = [] for curve in getcurves: # ------------------------------------------------------ # offset curves inward and outward to create the borders # ------------------------------------------------------ c = rs.coercecurve(curve) if not rs.IsCurvePlanar(curve): continue #else: #rs.HideObject(curve) offsets = c.Offset(plane, scale / 2, tol, style) if offsets: offset = sc.doc.Objects.Add(offsets[0]) offset_curves.append(offset) offsets = c.Offset(plane, -scale / 2, tol, style) if offsets: offset = sc.doc.Objects.Add(offsets[0]) offset_curves.append(offset) # ----------------------------------- # explode c into segments if possible # ----------------------------------- exploded = rs.ExplodeCurves(c) if exploded: for segment in exploded: subcurvelist.append(segment) else: #it appears this is for single lines only subcurvelist.append(rs.CopyObject(curve)) segments = [] # ------------------------------------------------------- # divide subcurves into shorter segments (dashed pattern) # ------------------------------------------------------- for curve in subcurvelist: closed = False if rs.coercecurve(curve).IsClosed: closed = True if rs.CurveLength(curve) > (scale * factor): segment_count = int(rs.CurveLength(curve) / (scale * factor / 2)) while True: #we need to start with 1/2 segment, then full space, then half segment #so #of segments needs to be a multiple of 4 if segment_count % 4 == 0: break else: segment_count += 1 pts = rs.DivideCurve(curve, segment_count) if closed: pts = pts[ 1:] #remove only first point, since last point == first pts = pts[1:-1] #remove first and last point pts = pts[::2] #remove every other point # -------------- # dash the curve # -------------- for i, pt in enumerate(pts): t = rs.CurveClosestPoint(curve, pt) curves = rs.SplitCurve(curve, t) curve = curves[1] segment = curves[0] if closed: #delete every odd segment if i % 2 == 0: rs.DeleteObject(segment) else: segments.append(segment) else: #delete every even segment if i % 2 == 1: rs.DeleteObject(segment) else: segments.append(segment) #append the remaining part segments.append(curve) def hatchthis(s): #offset all segments s = rs.coercecurve(s) offsets = s.Offset(plane, scale / 2, tol, style) if offsets: p1, p2, curve1 = getPointsAndLines(offsets) offsets = s.Offset(plane, -scale / 2, tol, style) if offsets: p3, p4, curve2 = getPointsAndLines(offsets) if not (p1 and p2 and p3 and p4): return #create end lines between the two offset curves line1 = rs.AddLine(p1, p3) line2 = rs.AddLine(p2, p4) polyline = rs.JoinCurves([line1, line2, curve1, curve2], True, tol) # FINALLY: hatch the bloody thing hatch = rs.AddHatch(polyline, 'Solid') #clean up rs.DeleteObject(polyline) return hatch if segments: segments = rs.JoinCurves(segments, True) layer = "hatched_curves" if not rs.IsLayer(layer): rs.AddLayer(layer) hatches = [] #create the hatches for s in segments: rs.ObjectLayer(hatchthis(s), layer) for offset in offset_curves: rs.ObjectLayer(offset, layer) #clean up rs.DeleteObjects(segments) rs.HideObjects(getcurves) rs.DeleteObjects(curves) #put on the lights, it's the result that counts rs.EnableRedraw(True)
def __generate_individual_levels(self, crosssectionplane, loft_height): cplane = rs.ViewCPlane(None, crosssectionplane) level_points = [] spikiness = self.emotion_properties["spikiness"] # max spikiness = 1 scaling_factor_aid = 0.2 * spikiness #draws profile curves on each spine level for i in xrange(self.emotion_properties["horizontal_AR"][loft_height] ["points_in_curve"]): scaling_factor = 1 - scaling_factor_aid if i % 2 == 0 else 1 #ranges from a difference in 0.8 and 1 (no difference) angle = 2 * math.pi * i / self.emotion_properties["horizontal_AR"][ loft_height]["points_in_curve"] x_point = scaling_factor * self.dimensions[ "actual_height"] * self.dimensions[ "vertical_AR"] * self.emotion_properties["vertical_AR"][ loft_height] * self.emotion_properties[ "horizontal_AR"][loft_height][ "level_horizontal_AR_x"] * math.cos(angle) / 2 y_point = scaling_factor * self.dimensions[ "actual_height"] * self.dimensions[ "vertical_AR"] * self.emotion_properties["vertical_AR"][ loft_height] * self.emotion_properties[ "horizontal_AR"][loft_height][ "level_horizontal_AR_y"] * math.sin(angle) / 2 z_point = 0 point = rs.XformCPlaneToWorld([x_point, y_point, z_point], cplane) level_points.append(rs.AddPoint(point)) connecting_point = level_points[0] level_points.append(rs.AddPoint(connecting_point)) level_curve = rs.AddCurve( level_points, self.emotion_properties["horizontal_AR"][str( loft_height)]["horizontal_smoothness"]) #twists curve start point 180deg if it is below the spine_x point (to make sure loft doesn't twist) crvStart = rs.CurveStartPoint(level_curve) if crvStart[0] <= self.x_points[int(loft_height) - 1]: crvDomain = rs.CurveDomain(level_curve) rs.CurveSeam(level_curve, (crvDomain[0] + crvDomain[1]) / 2) # add planar surface to top and bottom of bottle if loft_height == "5" or loft_height == "1": rs.AddPlanarSrf(level_curve) # hide curves and points on level profiles rs.HideObjects(level_curve) rs.HideObjects(level_points) # object finishing features if (self.object_id == "Bottle"): if loft_height == "5": rs.AddCylinder(cplane, 14.5, 7.4, cap=True) if (self.object_id == "Chair"): if loft_height == "5": rs.AddCylinder(cplane, 14.5, 7.4, cap=True) if (self.object_id == "Jewelry"): if loft_height == "5": major_radius = 5.0 minor_radius = major_radius - 1.5 # rotated_cplane = rs.RotatePlane(cplane, 45.0, cplane.XAxis) direction = rs.AddPoint((0, 0, 1)) rs.AddTorus(cplane.Origin, major_radius, minor_radius, direction) if (self.object_id == "Totem"): if loft_height == "1": base_width = 80 base_length = 60 base_depth = -10 base_points = [(-base_width / 2, -base_length / 2, 0), (base_width / 2, -base_length / 2, 0), (base_width / 2, base_length / 2, 0), (-base_width / 2, base_length / 2, 0), (-base_width / 2, -base_length / 2, base_depth), (base_width / 2, -base_length / 2, base_depth), (base_width / 2, base_length / 2, base_depth), (-base_width / 2, base_length / 2, base_depth)] rs.AddBox(base_points) return level_curve
import rhinoscriptsyntax as rs #delete all existing objects rs.DeleteObjects(rs.AllObjects('select')) #variables flowerRadius = 10 centerRadius = 2 petalCount = 15 flowerCenter = (0, 0, 0) petalWidth = 4 petalCurves = [] outerCircle = rs.AddCircle(flowerCenter, flowerRadius) points = rs.AddPoints(rs.DivideCurve(outerCircle, petalCount)) rs.HideObjects(points) for i in range(len(points)): centerLine = rs.AddLine(points[i], flowerCenter) rs.HideObject(centerLine) petalMidpoint = rs.AddPoint(rs.CurveMidPoint(centerLine)) rs.HideObjects(petalMidpoint) vector = rs.VectorCreate(points[i], petalMidpoint) vector = rs.VectorUnitize(vector) vector = rs.VectorScale(vector, (petalWidth / 2)) vector = rs.VectorRotate(vector, 90, [0, 0, 1]) petalEdgePoint = rs.CopyObject(petalMidpoint) petalEdgePoint = rs.MoveObject(petalEdgePoint, vector) curve = rs.AddArc3Pt(flowerCenter, points[i], petalEdgePoint) vector2 = rs.VectorRotate(vector, 180, [0, 0, 1]) petalEdgePoint2 = rs.CopyObject(petalMidpoint)
return [(u, v) if (u, v) in edgeset else (v, u) for u, v in edges] if __name__ == '__main__': edge_crvs = rs.GetObjects("Select edges", 4) lines = get_line_coordinates(edge_crvs) mesh = Mesh.from_lines(lines, delete_boundary_face=True) # draw edges for selection artist = MeshArtist(mesh, layer='joint_lines') artist.draw_edges() artist.redraw() # select edge rs.HideObjects(edge_crvs) edges = mesh_select_edges(mesh) rs.ShowObjects(edge_crvs) # clear edges artist.clear_edges() # find "every second" edge (joint lines) joint_lines = [] for i, uv in enumerate(edges): para_edges = get_parallel_edges(mesh,uv) for u, v in para_edges[i%2::2]: joint_lines.append((u,v)) # draw joint lines artist.draw_edges(keys=joint_lines, color=(255,0,0))
vector, (petalWidth / 2)) #scale vector to make length = half petal width vector = rs.VectorRotate( vector, 90, [0, 0, 1]) #rotate vector 90 degrees to centerline vector2 = rs.VectorRotate( vector, 180, [0, 0, 1]) #draw the opposite vector for the other side of the petal #add a points on the edge of each petal petalEdgePoint = rs.CopyObject(petalMidpoint) petalEdgePoint = rs.MoveObject(petalEdgePoint, vector) petalEdgePoint2 = rs.CopyObject(petalMidpoint) petalEdgePoint2 = rs.MoveObject(petalEdgePoint2, vector2) #draw edges of the petals curve = rs.AddArc3Pt(flowerCenter, points[i], petalEdgePoint) curve2 = rs.AddArc3Pt(flowerCenter, points[i], petalEdgePoint2) #add petal outline to list of petals petals.append(rs.JoinCurves([curve, curve2])) #draw the flower center and raise it slightly flowerCenterLine = rs.AddCircle(flowerCenter, centerRadius) flowerCenterSrf = rs.MoveObject(rs.AddPlanarSrf(flowerCenterLine), [0, 0, .1]) #draw a surface for each petal petalSrfs = rs.AddPlanarSrf(petals) #hide the curves and points rs.HideObjects(rs.ObjectsByType(4 | 1, True))
def HideSpecial(): ids = rs.GetObjects("Select objects to hide.", preselect=True) if not ids: return sc.sticky['HIDE_SPECIAL'] = ids rs.HideObjects(ids)
rs.EnableRedraw(False) rs.HideObject(srf) u_div = rs.GetInteger("Panel division in u direction",20) v_div = rs.GetInteger("Panel division in v direction",12) dev_threshold = rs.GetReal("Threshold in m",0.01) mesh = create_quad_mesh(srf,u_div,v_div) max_dev = mesh_max_deviation(mesh) mesh_faces = color_mesh(mesh,max_dev,0) rs.AddObjectsToGroup(mesh_faces,rs.AddGroup()) rs.HideObjects(mesh_faces) kmax = 1000 vis = 2 diagonal_prop = 0.15 edge_prop = 0.1 edge_min = 1 edge_max = 5 max_srf_dis = 1
egi.clear() cell.clear() with conduit.enabled(): cell_planarise(cell, kmax=2000, target_areas=target_areas, target_normals=target_normals, collapse_edge_length=collapse_edge_length, callback=callback, print_result_info=True) # ------------------------------------------------------------------------------ # 5. draw results # ------------------------------------------------------------------------------ rs.HideObjects(lines) # get index colors colordict = get_index_colordict(vectors.keys()) # draw initial vectors and target areas input_vector_labels = [] input_vectors = [] for i in vectors: label = 'target : ' + str(round(target_areas[i], 5)) input_vector_labels.append({ 'pos': midpts[i], 'text': label, 'color': colordict[i] }) input_vectors.append({
---------- form : compas_tna.diagrams.FormDiagram The form diagram. zmax : float The maximum z-coordinate of all vertices of the equilibrium network. """ formdata, scale = tna.vertical_from_zmax_proxy(form.to_data(), zmax) form.data = formdata return scale # 1. make the form diagram from selected line elements guids = compas_rhino.select_lines() rs.HideObjects(guids) form = FormDiagram.from_rhinolines(guids) form.draw(layer='TNA::FormDiagram', clear_layer=True) # 2. identify the supports keys = DiagramHelper.select_vertices(form) if keys: form.set_vertices_attributes(['is_anchor', 'is_fixed'], [True, True], keys=keys) form.draw(layer='TNA::FormDiagram', clear_layer=True) # 3. update the boundaries # Note: add only one foot per support to control the direction of the horizontal component
import rhinoscriptsyntax as rs import random x = random.randint(0, 50) y = random.randint(0, 50) z = random.randint(0, 50) xx = random.randint(51, 100) yy = random.randint(51, 100) zz = random.randint(51, 100) p = rs.AddPoint(x, y, z) pp = rs.AddPoint(xx, yy, zz) for i in range(100): x1 = random.randint(x, xx) y1 = random.randint(y, yy) z1 = random.randint(z, zz) p1 = rs.AddPoint(x1, y1, z1) rs.HideObjects(p1) r = random.randint(0, 255) g = random.randint(0, 255) b = random.randint(0, 255) c = rs.AddInterpCurve([p, p1, pp], 3, 0, None, None) rs.ObjectColor(c, [r, g, b])