def offsetext(): def RepresentsInt(s): try: int(s) return True except ValueError: return False viste = rs.ViewNames() for viewport in viste: rs.ViewDisplayMode(viewport,"Shaded") diametro = rs.StringBox("dimensione della punta","10","scontornatura") if RepresentsInt(diametro): diametro = int(diametro) else: diametro = 10 brep = rs.GetObjects("dammi un solido",16) brepexp = rs.ExplodePolysurfaces(brep) get_val = rs.GetEdgeCurves("dammi le curve") surf_edge = [] for i in get_val: surf_edge.append(i[0]) surf_edge = rs.coerceguidlist(surf_edge) if len(surf_edge)>1: surf_edge = rs.JoinCurves(surf_edge,True) surface = rs.GetObjects("conferma la selezione",8,False,True,1,1) print surf_edge uv= [] temp_edge = rs.ExplodeCurves(surf_edge,False) new_surface = rs.CopyObject(surface,(0,0,0)) list_evpt =[] for i in temp_edge: evpt =rs.CurveMidPoint(i) print evpt list_evpt.append(evpt) for i in list_evpt: bord= rs.SurfaceClosestPoint(new_surface,i) uv.append(bord) for i in uv: rs.ExtendSurface(new_surface,i,diametro*10) edge = rs.OffsetCurveOnSurface(surf_edge,new_surface,-diametro) print edge if rs.CurveLength(edge)<rs.CurveLength(surf_edge): rs.DeleteObject(edge) edge = rs.OffsetCurveOnSurface(surf_edge,new_surface,diametro) surf_edge = rs.ExplodeCurves(surf_edge,True) print edge rs.ObjectColor(edge,(0,0,255)) for i in brepexp: rs.DeleteObject(i) for i in temp_edge: rs.DeleteObject(i) for i in surf_edge: rs.DeleteObject(i) rs.DeleteObjects([new_surface,surface])
def SetToRendered(): views = rs.ViewNames() modes = rs.ViewDisplayModes() viewtype = "Rendered" rs.EnableRedraw(False) if viewtype in modes: for view in views: rs.ViewDisplayMode(view, viewtype)
def final_view(): """Applies rendering and redraws all objects.""" sc.doc.Views.Redraw() layer('OBS') for l in [ 'Default', 'TOP', 'BOTTOM', 'LEFT', 'RIGHT', 'FRONT', 'BACK', 'INTS', 'INTS_BOX' ]: rs.LayerVisible(l, False) [rs.ViewDisplayMode(view, 'Ghosted') for view in rs.ViewNames()]
def view(camera=False, target=False, lens=False): if camera and target and lens: if not rh.IsViewMaximized("Perspective"): rh.MaximizeRestoreView("Perspective") rh.ViewProjection("Perspective", 2) rh.ViewCameraLens("Perspective", lens) rh.ViewCameraTarget("Perspective", Pt(camera), Pt(target)) rh.ViewDisplayMode("Perspective", "Shaded") vs.Redraw() return (camera, target, lens) else: rh.CurrentView("Perspective") camera, target, lens = rh.ViewCamera(), rh.ViewTarget( ), rh.ViewCameraLens() return (fromPt(camera), fromPt(target), lens)
def extr_bld_flr(): # Extrude all buildings according to NUM_FLOORS attribute multiplied by FLOOR_HEIGHT constant # get all objects in building layer building_objs = rs.ObjectsByLayer(relevant_layers_dict["buildings"]) for building_obj in building_objs: if rs.IsCurve(building_obj) and rs.IsCurveClosed( building_obj ) and rs.CurveArea(building_obj)[0] > MIN_BUILDING_AREA_SQM: crv = rs.coercecurve(building_obj) num_of_floors = rs.GetUserText(building_obj, "NUM_FLOORS") building_height = FLOOR_HEIGHT_M * int(num_of_floors) srf = rs.ExtrudeCurveStraight(crv, (0, 0, 0), (0, 0, building_height)) rs.CapPlanarHoles(srf) rs.ViewDisplayMode(rs.CurrentView(), "Shaded")
def capture_image_size_w_all_option(self, file_name, ww, hh): ### Change Viewport rs.CurrentView("Top") rs.ViewDisplayMode("Top", 'Rendered') ### Capture query = "-ViewCaptureToFile W={} H={} S=1 D=_No R=_No A=_No T=_Yes {}" \ .format(ww, hh, file_name) rs.Command(query) ### Delete ALL self.delete_all() ### Change Viewport rs.CurrentView("Perspective")
MIN_BUILDING_AREA_SQM): crv = rs.coercecurve(building_obj) if rs.PointInPlanarClosedCurve(related_building_pnt, crv): xy_found = True for attr_label, attr_val in zip(attribute_labels_list, attributes_row): rs.SetUserText(building_obj, attr_label, attr_val) if not xy_found: rs.SelectObject(building_obj) print(x_val, y_val, z_val) print(out_loop_counter) ########################################################################################################################################## # Extrude all buildings according to NUM_FLOORS attribute multiplied by FLOOR_HEIGHT constant # get all objects in building layer building_objs = rs.ObjectsByLayer(relevant_layers_dict["buildings"]) for building_obj in building_objs: if rs.IsCurve(building_obj) and rs.IsCurveClosed( building_obj ) and rs.CurveArea(building_obj)[0] > MIN_BUILDING_AREA_SQM: crv = rs.coercecurve(building_obj) num_of_floors = rs.GetUserText(building_obj, "NUM_FLOORS") if num_of_floors == None: pass # building_height = FLOOR_HEIGHT_M * num_of_floors srf = rs.ExtrudeCurveStraight(crv, (0, 0, 0), (0, 0, 20)) rs.CapPlanarHoles(srf) rs.ViewDisplayMode(rs.CurrentView(), "Shaded")
import rhinoscriptsyntax as rs import scriptcontext as sc import Rhino as rh viste = rs.ViewNames() for viewport in viste: rs.ViewDisplayMode(viewport, "Shaded") diametro = 1 brep = rs.GetObjects("dammi un solido", 16) brepexp = rs.ExplodePolysurfaces(brep) surface = rs.GetObject("dammi la superficie", 8) surf_edge = rs.DuplicateSurfaceBorder(surface, 1) new_surface = rs.CopyObject(surface, (0, 0, 0)) uv = [] temp_edge = rs.ExplodeCurves(surf_edge, False) list_evpt = [] for i in temp_edge: evpt = rs.CurveMidPoint(i) print evpt list_evpt.append(evpt) for i in list_evpt: bord = rs.SurfaceClosestPoint(new_surface, i) uv.append(bord) for i in uv: rs.ExtendSurface(new_surface, i, diametro * 10) edge = rs.OffsetCurveOnSurface(surf_edge, new_surface, -diametro) print edge if rs.CurveLength(edge) < rs.CurveLength(surf_edge): rs.DeleteObject(edge)
def update_views(): [rs.ViewDisplayMode(view, 'Ghosted') for view in rs.ViewNames()] sc.doc.Views.Redraw()
def CaptureDisplayModesToFile(): try: displayModeNames = [] displayModeBool = [] displayModesChecked = [] ######## #Get current display mode originalDisplayMode = rc.RhinoDoc.ActiveDoc.Views.ActiveView.ActiveViewport.DisplayMode.LocalName ######## #Get default display mode selection if 'CaptureDisplayModes-DisplayModes' in sc.sticky: dict = sc.sticky['CaptureDisplayModes-DisplayModes'] for each in rc.Display.DisplayModeDescription.GetDisplayModes(): displayModeNames.append(each.EnglishName) if each.EnglishName in dict: displayModeBool.append(dict[each.EnglishName]) else: displayModeBool.append(False) else: for each in rc.Display.DisplayModeDescription.GetDisplayModes(): displayModeNames.append(each.EnglishName) displayModeBool.append(False) results = rs.CheckListBox(zip(displayModeNames, displayModeBool), 'Select Display Modes', 'Capture Display Modes To File') if results is None: return ######## #Save display modes to sticky resultDict = {} for each in results: resultDict[each[0]] = each[1] sc.sticky['CaptureDisplayModes-DisplayModes'] = resultDict for each in results: if each[1]: displayModesChecked.append(each[0]) ######## #Get default filename date = utils.GetDatePrefix() activeView = sc.doc.Views.ActiveView.ActiveViewport.Name if activeView is None: activeView = 'VIEW' path = rs.SaveFileName('Export All Display Modes', "PNG (*.png)|*.png||", filename = date+'_'+activeView) if path is None: return ######## #Get sizes from sticky if 'catpureDisplays-width' in sc.sticky: widthDefault = sc.sticky['catpureDisplays-width'] else: widthDefault = 5100 if 'catpureDisplays-height' in sc.sticky: heightDefault = sc.sticky['catpureDisplays-height'] else: heightDefault = 3300 width = rs.GetInteger('Image Width', number = widthDefault, minimum = 200, maximum = 20000) height = rs.GetInteger('Image Height', number = heightDefault, minimum = 200, maximum = 20000) ######## #Save sizes to sticky sc.sticky['catpureDisplays-width'] = width sc.sticky['catpureDisplays-height'] = height ####################################################################### #Export the images count = 0 for name in displayModesChecked: try: rs.ViewDisplayMode(mode = name) exportImage(path, name, width, height) count += 1 except: pass print "{} Images saved to {}".format(count , os.path.abspath(os.path.join(path, os.pardir))) result = True except: result = False ######## #Restore original display mode if originalDisplayMode is not None: rs.ViewDisplayMode(mode = originalDisplayMode) ######## #Save analytics try: utils.SaveFunctionData('IO-Capture Display Modes', [__version__, str(displayModesChecked), width, height, result]) except: print "Failed to save function data" return result
def LanciaBotton(self, sender, e): self.Close(True) #codice point extractor viste = rs.ViewNames() for viewport in viste: rs.ViewDisplayMode(viewport, "Ghosted") def FromEdgetoPlane(): PointPlane = [] CurveIdList = [] Brep = [] edges = rs.GetEdgeCurves() if edges: for edgeinfo in edges: Brep.append(edgeinfo[1]) CurveIdList.append(edgeinfo[0]) for CurveId in CurveIdList: if rs.IsCircle(CurveId): Pt = rs.CircleCenterPoint(CurveId) Normal = rs.CurveNormal(CurveId) LenghtNormal = rs.VectorLength(Normal) LenghNormal = self.m_foronumero.Text LenghNormal = int(LenghNormal) Normal = (LenghNormal * Normal[0], LenghNormal * Normal[1], LenghNormal * Normal[2]) PtStill = rs.AddPoint(Pt) Ptmoved = rs.MoveObject(Pt, Normal) Ptmoved = rs.coerce3dpoint(Ptmoved) PtStill = rs.coerce3dpoint(PtStill) PointPlane.append([ PtStill[0], PtStill[1], PtStill[2], Normal[0], Normal[1], Normal[2] ]) #PointPlane.append([Ptmoved[0],Ptmoved[1],Ptmoved[2],Normal[0],Normal[1],Normal[2]]) return (PointPlane, Brep) def CSVwrite(list, folder): #Get the filename to create filename = folder + "\\" + self.m_textbox.Text + "punti" + ".csv" print filename with open(filename, "wb") as csvfile: csvwriter = csv.writer(csvfile, delimiter=',') for item in list: csvwriter.writerow(item) print "Points written sucessfully to file" def exportBrep(Brep, folder): Brep = Brep[0] rs.SelectObject(Brep) file = folder + "\\" + self.m_textbox.Text + "solido" + ".step" extension = ".step" export = rs.Command("_-Export " + file + " _Enter") def Export(Object): folder = rs.BrowseForFolder( "Questo PC", "seleziona dove vuoi salvare i tuoi file") CSVwrite(Object[0], folder) exportBrep(Object[1], folder) PtNormBrep = FromEdgetoPlane() Export(PtNormBrep) rs.Command("_SelNone") rs.Command("_SelPt") rs.Command("_SelCrv") rs.Command("_Delete") for viewport in viste: rs.ViewDisplayMode(viewport, "Shaded") self.Close(True)
def view_top(): if not rh.IsViewMaximized("Top"): rh.MaximizeRestoreView("Top") rh.ViewProjection("Top", 1) rh.ViewDisplayMode("Top", "Wireframe") vs.Redraw()
class TestViewportsDialog(): #codice point extractor viste = rs.ViewNames() for viewport in viste: rs.ViewDisplayMode(viewport, "Ghosted") def FromEdgetoPlane(): PointPlane = [] CurveIdList = [] Brep = [] edges = rs.GetEdgeCurves() if edges: for edgeinfo in edges: Brep.append(edgeinfo[1]) CurveIdList.append(edgeinfo[0]) print CurveIdList for CurveId in CurveIdList: if rs.IsCircle(CurveId): # print "Sono un cerchio" Pt = rs.CircleCenterPoint(CurveId) Normal = rs.CurveNormal(CurveId) LenghtNormal = rs.VectorLength(Normal) LenghNormal = self.m_foronumero.Text LenghNormal = int(LenghNormal) Normal = (LenghNormal * Normal[0], LenghNormal * Normal[1], LenghNormal * Normal[2]) print Normal PtStill = rs.AddPoint(Pt) Ptmoved = rs.MoveObject(Pt, Normal) Ptmoved = rs.coerce3dpoint(Ptmoved) PtStill = rs.coerce3dpoint(PtStill) # print Ptmoved # print PtStill PointPlane.append([ PtStill[0], PtStill[1], PtStill[2], Normal[0], Normal[1], Normal[2] ]) #PointPlane.append([Ptmoved[0],Ptmoved[1],Ptmoved[2],Normal[0],Normal[1],Normal[2]]) return (PointPlane, Brep) PtNormBrep = FromEdgetoPlane() def CSVwrite(list, folder): #Get the filename to create filename = folder + "punti" + ".csv" print filename with open(filename, "wb") as csvfile: csvwriter = csv.writer(csvfile, delimiter=',') for item in list: csvwriter.writerow(item) print "Points written sucessfully to file" def exportBrep(Brep, folder): Brep = Brep[0] rs.SelectObject(Brep) rs.Command("_-Export " + str(folder) + "solido" + ".step" + " _Enter") def Export(Object): folder = rs.BrowseForFolder("Questo PC", "seleziona dove vuoi salvare i tuoi file") folder = folder + "\\" + "parafango" print str(folder) CSVwrite(Object[0], folder) exportBrep(Object[1], folder) Export(PtNormBrep) rs.Command("_SelNone") rs.Command("_SelPt") rs.Command("_SelCrv") rs.Command("_Delete") for viewport in viste: rs.ViewDisplayMode(viewport, "Shaded") ################################################### fine definizione point extractor def Colorreturner(self): return self.m_slider.Value def CloseButton(self): # Create the default button self.DefaultButton = forms.Button(Text='Close') self.DefaultButton.Click += self.OnCloseButtonClick return self.DefaultButton ################################################################################ # Function to test the viewport dialog ################################################################################ def TestViewportsDialog(): dlg = ViewportsDialog() rc = dlg.ShowModal(Rhino.UI.RhinoEtoApp.MainWindow)