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 CopyObjectsToLayer(): "Copy selected objects to a different layer" # Get the objects to copy objectIds = rs.GetObjects("Select objects") # Get all layer names layerNames = rs.LayerNames() if (objectIds == None or layerNames == None): return # Make sure select objects are unselected rs.UnselectObjects(objectIds) layerNames.sort() # Get the destination layer layer = rs.ComboListBox(layerNames, "Destination Layer <" + rs.CurrentLayer() + ">") if layer: # Add the new layer if necessary if (not rs.IsLayer(layer)): rs.AddLayer(layer) # Copy the objects newObjectIds = rs.CopyObjects(objectIds) # Set the layer of the copied objects [rs.ObjectLayer(id, layer) for id in newObjectIds] # Select the newly copied objects rs.SelectObjects(newObjectIds)
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 CurveLength(): "Calculate the length of one or more curves" # Get the curve objects arrObjects = rs.GetObjects("Select Objects", rs.filter.curve, True, True) if (arrObjects == None): return rs.UnselectObjects(arrObjects) length = 0.0 count = 0 for object in arrObjects: if rs.IsCurve(object): #Get the curve length length += rs.CurveLength(object) count += 1 if (count > 0): print "Curves selected:", count, " Total Length:", length
def arrayObjs(): arrObjects = rs.GetObjects("Select Array Objects", rs.filter.curve, True, True) if (arrObjects == None): return rs.UnselectObjects(arrObjects) list = [] amntObj = 0 lenObj = getLength(arrObjects[0]) for object in arrObjects: if rs.IsCurve(object): #Get the curve length amntObj += 1 list.append(str(object)) return list, amntObj, lenObj
def RandomUnselect(): try: ids = rs.GetObjects("Select objects to unselect", preselect=True) if not ids: return if len(ids) == 1: return rs.SelectObjects(ids) if sc.sticky.has_key("RandomUnselect_percent"): percent_default = sc.sticky["RandomUnselect_percent"] else: percent_default = 50 percent = rs.GetInteger("Percent to deselect", percent_default, 1, 99) if not percent: return objs = random.sample(ids, int(percent * len(ids) / 100)) rs.UnselectObjects(objs) sc.sticky["RandomUnselect_percent"] = percent return True except: return False
def unselect_edges(mesh, keys): guids = match_edges(mesh, keys) rs.EnableRedraw(False) rs.UnselectObjects(guids) rs.EnableRedraw(True)
def unselectZoom(): selObjs = rs.SelectedObjects() rs.UnselectObjects(selObjs) zoomToPoint() rs.SelectObjects(selObjs)
import rhinoscriptsyntax as rs import trkRhinoPy as trp crvs = rs.GetObjects("select crvs", rs.filter.curve, preselect=True) dist = rs.GetReal("dist") def Func(x): return trp.offsetInside(x, dist) offsetcrvs = map(Func, crvs) rs.UnselectObjects(crvs) rs.SelectObjects(offsetcrvs)
def unhighlight_vertices(diagram, keys): guids = match_vertices(diagram, keys) rs.EnableRedraw(False) rs.UnselectObjects(guids) rs.EnableRedraw(True)
import rhinoscriptsyntax as rs import trkRhinoPy as trp objs = rs.GetObjects("Select a srf", rs.filter.surface, preselect=True) rs.EnableRedraw(False) def createHatch(obj): hatch = trp.hatchFromSrf(obj) trp.copySourceLayer(hatch, obj) return hatch rs.UnselectObjects(objs) hatches = map(createHatch, objs) rs.SelectObjects(hatches) group = rs.AddGroup() rs.AddObjectsToGroup(hatches, group) rs.EnableRedraw(True)