def RunCommand(is_interactive): # Get existing props name_Exg = getAttrs(rs.SelectedObjects(), 'Object Name') act_Exg = getAttrs(rs.SelectedObjects(), 'Object Activ_Disc') dialog = Dialog_WindowProperties(name_Exg, act_Exg) rc = dialog.ShowModal(Rhino.UI.RhinoEtoApp.MainWindow) name_New, act_New = dialog.GetUserInput() try: update = dialog.GetUpdateStatus() except: update = False if update == True: for eachObj in rs.SelectedObjects(): rs.SetUserText(eachObj, 'Object Name', '%<ObjectName("{}")>%'.format(str(eachObj))) if 'varies' not in str(name_New): rs.ObjectName(eachObj, name_New) if 'varies' not in str(act_New): rs.SetUserText(eachObj, 'Object Activ_Disc', str(act_New)) return 0
def main(): print "Checking model" #Check model units if rs.UnitSystem() != 8: rs.MessageBox("Your model is not in inches.", 16) print "Unit warning" #Check bad objects rs.Command('-_SelBadObjects ') objs = rs.SelectedObjects() if len(objs) > 0: message = "You have {} bad objects. Use SelBadObjects to delete them.".format( len(objs)) rs.MessageBox(message, 16) rs.UnselectAllObjects() #SelDup rs.Command('-_SelDup ') objs = rs.SelectedObjects() if len(objs) > 0: message = "You have {} duplicate objects. Use SelDup to delete them.".format( len(objs)) rs.MessageBox(message, 16) rs.UnselectAllObjects() #SelSmall rs.Command('-_SelSmall .01 ') objs = rs.SelectedObjects() if len(objs) > 0: message = "You have {} tiny objects. Use SelSmall to delete them.".format( len(objs)) rs.MessageBox(message, 16) rs.UnselectAllObjects()
def RunCommand( is_interactive ): # First, get any properties of the existing object(s) selected exg_edge_typeName = getAttrs( rs.SelectedObjects(), 'Typename', _defaultVal=None) exg_edge_group = getAttrs( rs.SelectedObjects(), 'Group', _defaultVal=None ) # Call the Dialog Window dialog = Dialog_TB_Properties(exg_edge_typeName, exg_edge_group) rc = dialog.ShowModal(Rhino.UI.RhinoEtoApp.MainWindow) new_typename, new_group_number = dialog.GetUserInput() # Get the user-input data try: update = dialog.Update #True if 'OK', False if 'Cancel' except: update = False # on any error with the user input # Apply the User Inputs to the Object's Attributes if update==True if update: for eachObj in rs.SelectedObjects(): if 'varies' not in str(new_typename) or str(new_group_number): setAttrs(eachObj, 'Typename', str(new_typename) ) setAttrs(eachObj, 'Group', str(new_group_number) ) return 1 # temp for debuggin in editor #RunCommand(True)
def RunCommand(is_interactive): # First, get any properties of the existing object(s) tfa_Exg = getAttrs(rs.SelectedObjects(), 'TFA_Factor', _defaultVal=1) name_Exg = getAttrs(rs.SelectedObjects(), 'Object Name', _defaultVal=None) number_Exg = getAttrs(rs.SelectedObjects(), 'Room_Number', _defaultVal=None) v_sup_Exg = getAttrs(rs.SelectedObjects(), 'V_sup', _defaultVal=0) v_eta_Exg = getAttrs(rs.SelectedObjects(), 'V_eta', _defaultVal=0) v_trans_Exg = getAttrs(rs.SelectedObjects(), 'V_trans', _defaultVal=0) use_Exg = getAttrs(rs.SelectedObjects(), 'useType', _defaultVal='-') lighting_Exg = getAttrs(rs.SelectedObjects(), 'lighting', _defaultVal='-') motion_Exg = getAttrs(rs.SelectedObjects(), 'motion', _defaultVal='-') # Call the Dialog Window dialog = Dialog_WindowProperties(tfa_Exg, name_Exg, number_Exg, v_sup_Exg, v_eta_Exg, v_trans_Exg, use_Exg, lighting_Exg, motion_Exg) rc = dialog.ShowModal(Rhino.UI.RhinoEtoApp.MainWindow) number_New, name_New, tfa_New, vSup, vEta, vTrans, use, lighting, motion = dialog.GetUserInput( ) try: update = dialog.GetUpdateStatus() #True if 'OK', False if 'Cancel' except: update = False # on any error with the user input # Apply the User Inputs to the Object's Attributes if Update==True if update == True: for eachObj in rs.SelectedObjects(): # Sort out the name rs.SetUserText( eachObj, 'Object Name', '%<ObjectName("{}")>%'.format(str(eachObj)) ) # Formula to auto-set the obj's name in Attribute Inspector if 'varies' not in str(name_New): rs.ObjectName(eachObj, name_New) # Set the rest of the Surface Attributes if use != '<varies>': rs.SetUserText(eachObj, 'useType', use) if lighting != '<varies>': rs.SetUserText(eachObj, 'lighting', lighting) if motion != '<varies>': rs.SetUserText(eachObj, 'motion', motion) if number_New != '<varies>': rs.SetUserText(eachObj, 'Room_Number', number_New) if str(tfa_New) != '<varies>': rs.SetUserText(eachObj, 'TFA_Factor', str(tfa_New)) if str(vSup) != '<varies>': rs.SetUserText(eachObj, 'V_sup', str(vSup)) if str(vEta) != '<varies>': rs.SetUserText(eachObj, 'V_eta', str(vEta)) if str(vTrans) != '<varies>': rs.SetUserText(eachObj, 'V_trans', str(vTrans)) return 0 # temp for debuggin in editor #RunCommand(True)
def importfile(filename): commandString = "_-Import " + filename + " _Enter" rs.Command(commandString) sc.doc = Rhino.RhinoDoc.ActiveDoc objs = rs.SelectedObjects() rs.UnselectObjects(objs) return objs[0]
def TryLoadBlock(type, name): if type == '3D People': typeFolder = 'People 3D Folder' elif type == '2D People': typeFolder = 'People 2D Folder' elif type == '2D Trees': typeFolder = 'Vegetation 2D Folder' elif type == '3D Trees': typeFolder = 'Vegetation 3D Folder' elif type == '3D Vehicles': typeFolder = 'Vehicle 3D Folder' if rs.IsBlock(name): return True else: folderpath = fileLocations[typeFolder] files = os.listdir(folderpath) for file in files: if os.path.splitext(file)[1] == '.3dm': shortName = os.path.splitext(file)[0] if shortName == name: filepath = os.path.join(folderpath, file) filepath2 = '"' + filepath + '"' if os.path.isfile(filepath): rs.Command('-_Insert ' + filepath2 + ' B 0 1 0 ', False) objs = rs.SelectedObjects() for obj in objs: rs.DeleteObject(obj) return True
def RunCommand(is_interactive): dialog = Controller(rs.SelectedObjects()) dialog.main() # Use for debuging in editor #RunCommand(True)
def onSelectObjects(self, sender, e): try: sel = rs.SelectedObjects() self.selectedRhiObjects = sel txt = 'sel ' + str(len(sel)) + ':' for o in sel: txt += shortGuid(o) + ',' #print(txt) self.logToRhiPanel(txt) if len(sel) == 0: self.selectedRhiObject = None self.selectedObject = None self.form.UI_GENBLOCK.lb_selected_block.Text = 'Select block to edit' if len(sel) == 1: guid = sel[0] self.selectedRhiObject = guid txt = self.inspectObject(guid) self.logToObjPanel(txt) #obj=self.getObjectByGuid(guid) obj = None for po in self.data.flattern(): if po.guid == guid: obj = po po.is_selected = True else: po.is_selected = False if obj is not None: self.selectedObject = obj #try to update the block panel if obj.phase == 'BLOCK': self.update_GENBLOCK_PROPS() self.logDataTree() except: PrintException()
def LockAllOtherLayers(): try: obj = rs.GetObject(message="Select the object on the layer you want to stay unlocked", filter=0, preselect=True, select=False, custom_filter=None, subobjects=False) rs.EnableRedraw(False) groupName = random.random() layer = rs.ObjectLayer(obj) objs = rs.ObjectsByLayer(layer, select=False) allobj = rs.AllObjects(select=True, include_lights=False, include_grips=False, include_references=False) rs.UnselectObjects(objs) toBeLockedObj = rs.SelectedObjects() rs.UnselectAllObjects() group = rs.AddGroup(groupName) rs.AddObjectsToGroup(toBeLockedObj, group) rs.LockGroup(groupName) rs.DeleteGroup(groupName) rs.EnableRedraw(True) except: rs.EnableRedraw(True) print("Failed to execute") return
def ImportObject(self, file): rs.Command("_-Insert _File=_Yes " + self.root + file + ".3dm B 0,0,0 1 0 _Enter") object = rs.SelectedObjects()[0] rs.UnselectAllObjects() object = rs.ExplodeBlockInstance(object)[0] return object
def MakeSimpleSec(dir, nam, num, line, mode, ext): s = time.time() rs.Command("_CPlane " + "_W " + "_T ") rs.Command("_CPlane " + "_I " + ConvertPt(rs.CurveStartPoint(line)) + " " + "_V " + ConvertPt(rs.CurveEndPoint(line)) + " ") rs.Command("_Clippingplane " + "_C " + "0,0,0" + " " + str(1000) + " " + str(1000) + " ") rs.Command("_Plan") rs.Command("_SelAll") rs.Command("_Zoom " + "_S ") rs.Command("_SelNone") if mode == "fast": rs.Command("_SelVisible " + "_Enter") elif mode == "slow": rs.Command("_SelAll") sc.doc = Rhino.RhinoDoc.ActiveDoc select = len(rs.SelectedObjects()) sc.doc = ghdoc print("selected " + str(select) + " objects") if select == 0: print("canceled") else: rs.Command("-_Make2d " + "_D " + "_C " + "_M=はい " + "_Enter") rs.Command("_CPlane " + "_W " + "_T ") if ext == "dwg": rs.Command("-_Export " + dir + nam + "_section_" + str(num) + ".dwg" + " " + "_Enter") else: rs.Command("-_Export " + dir + nam + "_section_" + str(num) + "." + str(ext)) print("exported section") rs.Command("_SelCrv") rs.Command("_SelClippingPlane") rs.Command("_Delete") print("time = " + str(time.time() - s))
def get_two_curves(): # get list of selected objects sel = rs.SelectedObjects() # clear selection rs.UnselectAllObjects() # if there were 2 objects selected... if len(sel) == 2: c1, c2 = sel # ...and they are curves... if rs.IsCurve(c1) and rs.IsCurve(c2): # the closed one is the cross-section, the open one is profile if rs.IsCurveClosed(c2): return c1, c2 elif rs.IsCurveClosed(c1): return c2, c1 # none of the things above worked, ask the user profile = rs.GetObject('Pick the profile curve', rs.filter.curve) # let user cancel if profile is None: return None, None cross = rs.GetObject('Pick the cross-section curve', rs.filter.curve) # return the curves return profile, cross
def try_none_selected(): # g.Grammar.clear_all() f.Frame.new() selected_objects = rs.SelectedObjects() message = "len(selected_objects)" length = len(selected_objects) print("%s: %i" % (message, length))
def RunCommand(is_interactive): print "Setting the name(s) for the selected object(s)" dialog = Controller(rs.SelectedObjects()) dialog.main() # Use for debuging in editor #RunCommand(True)
def RunCommand(is_interactive): print "Applying PHPP Window Types to Selected Object(s)" dialog = Controller(rs.SelectedObjects()) dialog.main() # Use for debuging in editor #RunCommand(True)
def MakeRoofPlan(dir, nam, mode, ext): s = time.time() rs.Command("_Plan") rs.Command("_SelCrv") rs.Command("_Invert") rs.Command("_Zoom " + "_S ") rs.Command("_SelNone") rs.Command("_SelCrv") sc.doc = Rhino.RhinoDoc.ActiveDoc select = len(rs.SelectedObjects()) sc.doc = ghdoc print("selected " + str(select) + " objects") if select == 0: print("canceled") else: rs.Command("-_Make2d " + "_D " + "_U " + "_M=はい " + "_Enter") rs.Command("_Lock") rs.Command("_SelCrv") rs.Command("_Hide") if mode == "fast": rs.Command("_SelVisible " + "_Enter") elif mode == "slow": rs.Command("_SelAll") sc.doc = Rhino.RhinoDoc.ActiveDoc select = len(rs.SelectedObjects()) sc.doc = ghdoc print("selected " + str(select) + " objects") if select == 0: print("canceled") else: rs.Command("-_Make2d " + "_D " + "_U " + "_M=はい " + "_Enter") rs.Command("_Unlock") rs.Command("_SelCrv") rs.Command("-_Make2d " + "_D " + "_C " + "_M=はい " + "_Enter") rs.Command("_CPlane " + "_W " + "_T ") if ext == "dwg": rs.Command("-_Export " + dir + nam + "_roof" + ".dwg" + " " + "_Enter") else: rs.Command("-_Export " + dir + nam + "_roof" + "." + str(ext)) rs.Command("_SelCrv") rs.Command("_Delete") rs.Command("_Unlock") rs.Command("_Show") print("time = " + str(time.time() - s))
def RunCommand(is_interactive): # First, get any properties of the existing object(s) selected exg_pipe_diam = getAttrs(rs.SelectedObjects(), 'pipe_diameter', _defaultVal=None) exg_pipe_insulThickness = getAttrs(rs.SelectedObjects(), 'insulation_thickness', _defaultVal=None) exg_pipe_insulConductivity = getAttrs(rs.SelectedObjects(), 'insulation_conductivity', _defaultVal=None) exg_pipe_insulReflective = getAttrs(rs.SelectedObjects(), 'insulation_reflective', _defaultVal=True) # Call the Dialog Window dialog = Dialog_RecircPipe(exg_pipe_diam, exg_pipe_insulThickness, exg_pipe_insulReflective, exg_pipe_insulConductivity) rc = dialog.ShowModal(Rhino.UI.RhinoEtoApp.MainWindow) nw_diam, nw_thkns, nw_lambda, nw_reflec = dialog.GetUserInput() # Get the user-input data try: update = dialog.Update #True if 'OK', False if 'Cancel' except: update = False # on any error with the user input print('Error. Not changing any object parameters.') # Apply the User Inputs to the Object's Attributes if update==True if update: for eachObj in rs.SelectedObjects(): if 'varies' not in [str(nw_diam), str(nw_thkns)]: setAttrs(eachObj, 'pipe_diameter', str(nw_diam)) setAttrs(eachObj, 'insulation_thickness', str(nw_thkns)) setAttrs(eachObj, 'insulation_conductivity', str(nw_lambda)) setAttrs(eachObj, 'insulation_reflective', str(nw_reflec)) return 1 # temp for debuggin in editor #RunCommand(True)
def main(): rs.EnableRedraw(False) selected = rs.SelectedObjects() theObjs = rs.GetObject("Select objects on the layer you wish to select") layer = rs.ObjectLayer(theObjs) layerObjs = rs.ObjectsByLayer(layer) layerObjs.extend(selected) print(layerObjs) rs.SelectObjects(layerObjs) rs.EnableRedraw(True)
def PlaceInstance(file, x, y, mirror, rotate): rs.Command("_-Insert _File=_Yes " + root + "packages/" + file + ".3dm B 0,0,0 1 0 _Enter") objects = rs.SelectedObjects() if not len(objects): return None object = objects[0] rs.UnselectAllObjects() rs.RotateObject(object, (0, 0, 0), rotate) if mirror: rs.RotateObject(object, (0, 0, 0), 180, (0, 1, 0)) rs.MoveObject(object, (0, 0, -boardThickness)) rs.MoveObject(object, (x, y, 0)) return object
def PlaceInstance(file, x, y, mirror, rotate): rs.Command( "_-Insert _File=_Yes /Users/denis/sandbox/denisbohm/firefly-ice-mechanical/scripts/packages/" + file + ".3dm B 0,0,0 1 0 _Enter") objects = rs.SelectedObjects() if not len(objects): return None object = objects[0] rs.UnselectAllObjects() rs.RotateObject(object, (0, 0, 0), rotate) if mirror: rs.RotateObject(object, (0, 0, 0), 180, (0, 1, 0)) rs.MoveObject(object, (0, 0, -boardThickness)) rs.MoveObject(object, (x, y, 0)) return object
def NewPart(): """Create a 'New Part' layer as a sublayer of '30_3D'.""" input_obj = rs.SelectedObjects() layers = rs.LayerNames() if "30_3D" not in layers: rs.AddLayer("30_3D") for i in range(1, 30): new_layer = "30_3D::3{}_Part".format(i) if new_layer not in layers: rs.AddLayer("3{}_Part".format(i), parent="30_3D") if input_obj: rs.ObjectLayer(input_obj, new_layer) return
def handleSelectObj(self,sender,e): sel=rs.SelectedObjects() print('handleSelectObj') if len(sel)==1: print('selected obj ID:',sel[0]) else: print('selected multiple objs, len=',len(sel)) for obj in sel: print('obj :',obj) isGroup=rs.IsGroup(obj) if isGroup: print('group:',obj) items=rs.ObjectsByGroup(obj) for item in items: print('item ',i,':',item)
def _a_rule_name_tag_is_selected(self): """Returns: boolean True, if the selected object is a rule name tag False, otherwise """ return_value = True selected_objects = rs.SelectedObjects() if not len(selected_objects) == 1: return_value = False else: selected_object = selected_objects[0] if not (rs.IsText(selected_object) and cn.ComponentName._component_name_is_listed( 'rule', rs.TextObjectText(selected_object))): return_value = False return return_value
def exportLayers(layerNames, filePath, version=4): '''Export only the items on designated layers to a file.''' # save selection oldSelection = rs.SelectedObjects() # clear selection rs.UnselectAllObjects() # add everything on the layers to selection for name in layerNames: objs = scriptcontext.doc.Objects.FindByLayer(name) guids = [obj.Id for obj in objs] scriptcontext.doc.Objects.Select.Overloads[SCG.IEnumerable[System.Guid]](guids) # export selected items exportFile(filePath, version, selectedOnly=True) #clear selection rs.UnselectAllObjects() # restore selection if oldSelection: scriptcontext.doc.Objects.Select.Overloads[SCG.IEnumerable[System.Guid]](oldSelection)
def IsolateLayers(): """Isolate layers by hiding layers.""" file_name = rs.DocumentName() file_path = rs.DocumentPath() # Select objects input_obj = rs.SelectedObjects() if not input_obj: input_obj = rs.GetObjects("Select objects on layers to isolate") if not input_obj: return # Get all layers names proj_layers = rs.LayerNames() layers_history = {rs.LayerId(l): rs.LayerVisible(l) for l in proj_layers} # Save temp if file_name is None: temp_file_name = "IsolateLayers_temp.json" else: temp_file_name = file_path + 'IsolateLayers_temp_' + file_name.strip( '.3dm') + '.json' with open(temp_file_name, "w+") as f: f.write(json.dumps(layers_history, sort_keys=True, indent=4)) # Get objects layers obj_layers = [rs.ObjectLayer(o) for o in input_obj] layers = [] for l in obj_layers: s = l.split('::') a = 0 while len(s) > a: layers.append("::".join(s[:a + 1])) a += 1 # Set current layer rs.CurrentLayer(layers[0]) # Hide layers layers_to_hide = list(set(proj_layers) - set(layers)) for l in layers_to_hide: rs.LayerVisible(l, False)
def VolumeLiters(): """Report the volume in Litres of closed surfaces, polysurfaces, or meshes.""" input_obj = rs.SelectedObjects() if not input_obj: input_obj = rs.GetObjects("Select objects") if not input_obj: return volume = 0.0 for o in input_obj: if rs.IsMesh(o): a, b, c = rs.MeshVolume(o) volume += b elif rs.IsObjectSolid(o): a, b = rs.SurfaceVolume(o) volume += a if volume == 0.0: return volume = round(volume / (rs.UnitScale(rs.UnitSystem(), 3) * 10)**3, 3) print "Volume = {} liters".format(volume)
def ProjectPlan(objs, plane): print "Projecting Plan" try: rs.SelectObjects(objs) except: rs.SelectObject(objs) rs.AddNamedCPlane('c_prev') rs.AddNamedCPlane('c_temp') rs.ViewCPlane(plane=plane) rs.Command('-_Make2d l c p f _Enter', False) projLines = rs.SelectedObjects() rs.DeleteNamedCPlane('c_temp') rs.RestoreNamedCPlane('c_prev') rs.DeleteNamedCPlane('c_prev') for line in projLines: rs.ObjectColor(line, (200, 200, 200)) return projLines
def handle(self, sender, e): try: rs.UnselectAllObjects() self.engine.clearSelections() objs = rs.SelectedObjects() if len(objs) == 0: objs = rs.GetObjects( 'select obj to change type, and press enter') #case of mesh view for ro in objs: po, upStream = self.engine.getObjectByGuid(ro) upStream.typeIndex = self.index rs.ObjectColor(upStream.guid, SRFTYPECOLORS[self.index]) #TODO:the following line deleted upstream from engine #TODO:color is not updating # self.engine.genTypeMeshObject(upStream) except Exception as e: print(e)
def Run(dir, ext): if dir is None: rs.MessageBox("No directory path defied") return files = [] for file in os.listdir(dir): if file.endswith("." + ext): files.append(dir + "/" + file) rs.EnableRedraw(False) rs.UnselectAllObjects() importedObjs = [] for filepath in files: rs.Command("!_-Import \"" + filepath + "\" -Enter -Enter") selectedObjs = rs.SelectedObjects() importedObjs.extend(selectedObjs) rs.UnselectAllObjects() rs.EnableRedraw(True) return importedObjs
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