def ObjectPrintWidth(object_ids, width=None): """Returns or modifies the print width of an object Parameters: object_ids = identifiers of object(s) width[opt] = new print width value in millimeters, where width=0 means use the default width, and width<0 means do not print (visible for screen display, but does not show on print). If omitted, the current width is returned. Returns: If width is not specified, the object's current print width If width is specified, the object's previous print width If object_ids is a list or tuple, the number of objects modified """ id = rhutil.coerceguid(object_ids, False) if id: rhino_object = rhutil.coercerhinoobject(id, True, True) rc = rhino_object.Attributes.PlotWeight if width is not None: rhino_object.Attributes.PlotWeightSource = Rhino.DocObjects.ObjectPlotWeightSource.PlotWeightFromObject rhino_object.Attributes.PlotWeight = width rhino_object.CommitChanges() scriptcontext.doc.Views.Redraw() return rc for id in object_ids: rhino_object = rhutil.coercerhinoobject(id, True, True) rhino_object.Attributes.PlotWeightSource = Rhino.DocObjects.ObjectPlotWeightSource.PlotWeightFromObject rhino_object.Attributes.PlotWeight = width rhino_object.CommitChanges() scriptcontext.doc.Views.Redraw() return len(object_ids)
def ObjectColorSource(object_ids, source=None): """Returns of modifies the color source of an object. Paramters: object_ids = single identifier of list of identifiers source[opt] = new color source 0 = color from layer 1 = color from object 2 = color from material 3 = color from parent Returns: if color source is not specified, the current color source is color source is specified, the previous color source if color_ids is a list, then the number of objects modifief """ id = rhutil.coerceguid(object_ids, False) if id: rhobj = rhutil.coercerhinoobject(id, True, True) rc = int(rhobj.Attributes.ColorSource) if source is not None: rhobj.Attributes.ColorSource = System.Enum.ToObject(Rhino.DocObjects.ObjectColorSource, source) rhobj.CommitChanges() scriptcontext.doc.Views.Redraw() return rc else: rc = 0 source = System.Enum.ToObject(Rhino.DocObjects.ObjectColorSource, source) for id in object_ids: rhobj = rhutil.coercerhinoobject(id, True, True) rhobj.Attributes.ColorSource = source rhobj.CommitChanges() rc += 1 if rc: scriptcontext.doc.Views.Redraw() return rc
def ObjectPrintColor(object_ids, color=None): """Returns or modifies the print color of an object Parameters: object_ids = identifiers of object(s) color[opt] = new print color. If omitted, the current color is returned. Returns: If color is not specified, the object's current print color If color is specified, the object's previous print color If object_ids is a list or tuple, the number of objects modified """ id = rhutil.coerceguid(object_ids, False) if id: rhino_object = rhutil.coercerhinoobject(id, True, True) rc = rhino_object.Attributes.PlotColor if color: rhino_object.Attributes.PlotColorSource = Rhino.DocObjects.ObjectPlotColorSource.PlotColorFromObject rhino_object.Attributes.PlotColor = rhutil.coercecolor(color, True) rhino_object.CommitChanges() scriptcontext.doc.Views.Redraw() return rc for id in object_ids: color = rhutil.coercecolor(color, True) rhino_object = rhutil.coercerhinoobject(id, True, True) rhino_object.Attributes.PlotColorSource = Rhino.DocObjects.ObjectPlotColorSource.PlotColorFromObject rhino_object.Attributes.PlotColor = color rhino_object.CommitChanges() scriptcontext.doc.Views.Redraw() return len(object_ids)
def ObjectLayer(object_id, layer=None): """Returns or modifies the layer of an object Parameters: object_id = the identifier of the object(s) layer[opt] = name of an existing layer Returns: If a layer is not specified, the object's current layer If a layer is specified, the object's previous layer If object_id is a list or tuple, the number of objects modified """ if type(object_id) is not str and hasattr(object_id, "__len__"): layer = __getlayer(layer, True) index = layer.LayerIndex for id in object_id: obj = rhutil.coercerhinoobject(id, True, True) obj.Attributes.LayerIndex = index obj.CommitChanges() scriptcontext.doc.Views.Redraw() return len(object_id) obj = rhutil.coercerhinoobject(object_id, True, True) if obj is None: return scriptcontext.errorhandler() index = obj.Attributes.LayerIndex rc = scriptcontext.doc.Layers[index].FullPath if layer: layer = __getlayer(layer, True) index = layer.LayerIndex obj.Attributes.LayerIndex = index obj.CommitChanges() scriptcontext.doc.Views.Redraw() return rc
def ObjectLinetypeSource(object_ids, source=None): """Returns of modifies the linetype source of an object Parameters: object_ids = identifiers of object(s) source[opt] = new linetype source. If omitted, the current source is returned. If object_ids is a list of identifiers, this parameter is required 0 = By Layer 1 = By Object 3 = By Parent Returns: If a source is not specified, the object's current linetype source If source is specified, the object's previous linetype source If object_ids is a list, the number of objects modified """ id = rhutil.coerceguid(object_ids, False) if id: rhino_object = rhutil.coercerhinoobject(id, True, True) oldsource = rhino_object.Attributes.LinetypeSource if source is not None: source = System.Enum.ToObject(Rhino.DocObjects.ObjectLinetypeSource, source) rhino_object.Attributes.LinetypeSource = source rhino_object.CommitChanges() scriptcontext.doc.Views.Redraw() return int(oldsource) source = System.Enum.ToObject(Rhino.DocObjects.ObjectLinetypeSource, source) for id in object_ids: rhino_object = rhutil.coercerhinoobject(id, True, True) rhino_object.Attributes.LinetypeSource = source rhino_object.CommitChanges() scriptcontext.doc.Views.Redraw() return len(object_ids)
def ObjectLinetype(object_ids, linetype=None): """Returns of modifies the linetype of an object Parameters: object_ids = identifiers of object(s) linetype[opt] = name of an existing linetype. If omitted, the current linetype is returned. If object_ids is a list of identifiers, this parameter is required Returns: If a linetype is not specified, the object's current linetype If linetype is specified, the object's previous linetype If object_ids is a list, the number of objects modified """ id = rhutil.coerceguid(object_ids, False) if id: rhino_object = rhutil.coercerhinoobject(id, True, True) oldindex = scriptcontext.doc.Linetypes.LinetypeIndexForObject(rhino_object) if linetype: newindex = scriptcontext.doc.Linetypes.Find(linetype, True) rhino_object.Attributes.LinetypeSource = Rhino.DocObjects.ObjectLinetypeSource.LinetypeFromObject rhino_object.Attributes.LinetypeIndex = newindex rhino_object.CommitChanges() scriptcontext.doc.Views.Redraw() return scriptcontext.doc.Linetypes[oldindex].Name newindex = scriptcontext.doc.Linetypes.Find(linetype, True) if newindex<0: raise Exception("%s does not exist in LineTypes table"%linetype) for id in object_ids: rhino_object = rhutil.coercerhinoobject(id, True, True) rhino_object.Attributes.LinetypeSource = Rhino.DocObjects.ObjectLinetypeSource.LinetypeFromObject rhino_object.Attributes.LinetypeIndex = newindex rhino_object.CommitChanges() scriptcontext.doc.Views.Redraw() return len(object_ids)
def ObjectName(object_id, name=None): """Returns or modifies the name of an object Parameters: object_id = id or ids of object(s) name[opt] = the new object name. If omitted, the current name is returned Returns: If name is not specified, the current object name If name is specified, the previous object name If object_id is a list, the number of objects changed """ id = rhutil.coerceguid(object_id, False) rhino_object = None rhino_objects = None if id: rhino_object = rhutil.coercerhinoobject(id, True, True) else: rhino_objects = [rhutil.coercerhinoobject(id, True, True) for id in object_id] if not rhino_objects: return 0 if len(rhino_objects)==1: rhino_object = rhino_objects[0] rhino_objects = None if name is None: #get the name if rhino_objects: raise Exception("name required when object_id represents multiple objects") return rhino_object.Name if rhino_objects: for rh_obj in rhino_objects: attr = rh_obj.Attributes attr.Name = name scriptcontext.doc.Objects.ModifyAttributes(rh_obj, attr, True) return len(rhino_objects) rc = rhino_object.Name if not type(name) is str: name = str(name) rhino_object.Attributes.Name = name rhino_object.CommitChanges() return rc
def ObjectMaterialSource(object_ids, source=None): """Returns or modifies the rendering material source of an object. Parameters: object_ids = one or more object identifiers source [opt] = The new rendering material source. If omitted and a single object is provided in object_ids, then the current material source is returned. This parameter is required if multiple objects are passed in object_ids 0 = Material from layer 1 = Material from object 3 = Material from parent Returns: If source is not specified, the current rendering material source If source is specified, the previous rendering material source If object_ids refers to multiple objects, the number of objects modified """ id = rhutil.coerceguid(object_ids, False) if id: # working with single object rhino_object = rhutil.coercerhinoobject(id, True, True) rc = int(rhino_object.Attributes.MaterialSource) if source is not None: rhino_object.Attributes.MaterialSource = System.Enum.ToObject(Rhino.DocObjects.ObjectMaterialSource, source) rhino_object.CommitChanges() return rc # else working with multiple objects if source is None: raise Exception("source is required when object_ids represents multiple objects") source = System.Enum.ToObject(Rhino.DocObjects.ObjectMaterialSource, source) for id in object_ids: rhino_object = rhutil.coercerhinoobject(id, True, True) rhino_object.Attributes.MaterialSource = source rhino_object.CommitChanges() return len(object_ids)
def ObjectPrintWidthSource(object_ids, source=None): """Returns or modifies the print width source of an object Parameters: object_ids = identifiers of object(s) source[opt] = new print width source 0 = print width by layer 1 = print width by object 3 = print width by parent Returns: If source is not specified, the object's current print width source If source is specified, the object's previous print width source If object_ids is a list or tuple, the number of objects modified """ id = rhutil.coerceguid(object_ids, False) if id: rhino_object = rhutil.coercerhinoobject(id, True, True) rc = int(rhino_object.Attributes.PlotWeightSource) if source is not None: rhino_object.Attributes.PlotWeightSource = System.Enum.ToObject(Rhino.DocObjects.ObjectPlotWeightSource, source) rhino_object.CommitChanges() scriptcontext.doc.Views.Redraw() return rc for id in object_ids: rhino_object = rhutil.coercerhinoobject(id, True, True) rhino_object.Attributes.PlotWeightSource = System.Enum.ToObject(Rhino.DocObjects.ObjectPlotWeightSource, source) rhino_object.CommitChanges() scriptcontext.doc.Views.Redraw() return len(object_ids)
def MatchMaterial(source, destination): """Copies the material definition from one material to one or more objects Parameters: source = source material index -or- identifier of the source object. The object must have a material assigned destination = indentifier(s) of the destination object(s) Returns: number of objects that were modified if successful None if not successful or on error """ source_id = rhutil.coerceguid(source) source_mat = None if source_id: rhobj = rhutil.coercerhinoobject(source_id, True, True) source = rhobj.Attributes.MaterialIndex mat = scriptcontext.doc.Materials[source] if not mat: return scriptcontext.errorhandler() destination_id = rhutil.coerceguid(destination) if destination_id: destination = [destination] ids = [rhutil.coerceguid(d) for d in destination] rc = 0 for id in ids: rhobj = scriptcontext.doc.Objects.Find(id) if rhobj: rhobj.Attributes.MaterialIndex = source rhobj.Attributes.MaterialSource = Rhino.DocObjects.ObjectMaterialSource.MaterialFromObject rhobj.CommitChanges() rc += 1 if rc>0: scriptcontext.doc.Views.Redraw() return rc
def HatchScale(hatch_id, scale=None): """Returns or modifies the scale applied to the hatch pattern when it is mapped to the hatch's plane Parameters: hatch_id = identifier of a hatch object scale[opt] = scale factor Returns: if scale is not defined, the current scale factor if scale is defined, the previous scale factor None on error Example: import rhinoscriptsyntax as rs objects = rs.NormalObjects() if objects: for obj in objects: if rs.IsHatch(obj) and rs.HatchScale(obj)>1.0: rs.HatchScale(obj, 1.0) See Also: HatchPattern HatchRotation IsHatch """ hatchobj = rhutil.coercerhinoobject(hatch_id) if not isinstance(hatchobj, Rhino.DocObjects.HatchObject): return scriptcontext.errorhandler() rc = hatchobj.HatchGeometry.PatternScale if scale and scale!=rc: hatchobj.HatchGeometry.PatternScale = scale hatchobj.CommitChanges() scriptcontext.doc.Views.Redraw() return rc
def HatchPattern(hatch_id, hatch_pattern=None): """Returns or changes a hatch object's hatch pattern Parameters: hatch_id = identifier of a hatch object hatch_pattern[opt] = name of an existing hatch pattern to replace the current hatch pattern Returns: if hatch_pattern is not specified, the current hatch pattern if hatch_pattern is specified, the previous hatch pattern None on error Example: import rhinoscriptsyntax as rs objects = rs.AllObjects() if objects is not None: for obj in objects: if rs.IsHatch(obj) and rs.HatchPattern(obj)=="Solid": rs.SelectObject(obj) See Also: AddHatch AddHatches HatchRotation HatchScale IsHatch """ hatchobj = rhutil.coercerhinoobject(hatch_id, True, True) if not isinstance(hatchobj, Rhino.DocObjects.HatchObject): return scriptcontext.errorhandler() old_index = hatchobj.HatchGeometry.PatternIndex if hatch_pattern: new_index = scriptcontext.doc.HatchPatterns.Find(hatch_pattern, True) if new_index<0: return scriptcontext.errorhandler() hatchobj.HatchGeometry.PatternIndex = new_index hatchobj.CommitChanges() scriptcontext.doc.Views.Redraw() return scriptcontext.doc.HatchPatterns[old_index].Name
def UnselectObjectGrips(object_id): """Unselects an object's grips. Note, the grips will not be turned off. Parameters: object_id = identifier of the object Returns: Number of grips unselected on success None on failure Example: import rhinoscriptsyntax as rs obj = rs.GetObject("Select object") if rs.ObjectGripsSelected(obj): rs.UnselectObjectGrips(obj) See Also: EnableObjectGrips ObjectGripCount UnselectObjectGrip """ rhobj = rhutil.coercerhinoobject(object_id, True, True) if not rhobj.GripsOn: return scriptcontext.errorhandler() grips = rhobj.GetGrips() if grips is None: return scriptcontext.errorhandler() count = 0 for grip in grips: if grip.Select(False)==0: count += 1 if count>0: scriptcontext.doc.Views.Redraw() return count return scriptcontext.errorhandler()
def UnselectObjectGrip(object_id, index): """Unselects a single grip owned by an object. If the object's grips are not turned on, the grips will not be unselected Parameters: object_id = identifier of the object index = index of the grip to unselect Returns: True or False indicating success or failure Example: import rhinoscriptsyntax as rs obj = rs.GetObject("Select curve", rs.filter.curve) if obj: rs.EnableObjectGrips( obj ) for i in xrange(0,count,2): rs.UnselectObjectGrip( obj, i ) See Also: EnableObjectGrips ObjectGripCount UnselectObjectGrips """ rhobj = rhutil.coercerhinoobject(object_id, True, True) if not rhobj.GripsOn: return False grips = rhobj.GetGrips() if grips is None: return False if index<0 or index>=grips.Length: return False grip = grips[index] if grip.Select(False)==0: scriptcontext.doc.Views.Redraw() return True return False
def SelectedObjectGrips(object_id): """Returns a list of grip indices indentifying an object's selected grips Parameters: object_id = identifier of the object Returns: list of indices on success None on failure or if no grips are selected Example: import rhinoscriptsyntax as rs obj = rs.GetObject("Select curve", rs.filter.curve) if obj: rs.EnableObjectGrips( obj ) for i in xrange(0,count,2): rs.SelectObjectGrip( obj, i ) grips = rs.SelectedObjectGrips(obj) if grips: print len(grips), "grips selected" See Also: EnableObjectGrips SelectObjectGrip SelectObjectGrips """ rhobj = rhutil.coercerhinoobject(object_id, True, True) if not rhobj.GripsOn: return None grips = rhobj.GetGrips() rc = [] if grips: for i in xrange(grips.Length): if grips[i].IsSelected(False): rc.append(i) return rc
def ObjectGripsSelected(object_id): """Verifies that an object's grips are turned on and at least one grip is selected Parameters: object_id = identifier of the object Returns: True or False indicating success or failure Example: import rhinoscriptsyntax as rs obj = rs.GetObject("Select object") if rs.ObjectGripsSelected(obj): rs.UnselectObjectGrips( obj ) See Also: EnableObjectGrips ObjectGripCount ObjectGripsOn SelectObjectGrips UnselectObjectGrips """ rhobj = rhutil.coercerhinoobject(object_id, True, True) if not rhobj.GripsOn: return False grips = rhobj.GetGrips() if grips is None: return False for grip in grips: if grip.IsSelected(False): return True return False
def ObjectGripLocation(object_id, index, point=None): """Returns or modifies the location of an object's grip Parameters: object_id = identifier of the object index = index of the grip to either query or modify point [opt] = 3D point defining new location of the grip Returns: if point is not specified, the current location of the grip referenced by index if point is specified, the previous location of the grip referenced by index None on error Example: import rhinoscriptsyntax as rs obj = rs.GetObject("Select curve", rs.filter.curve) if obj: rs.EnableObjectGrips(obj) point = rs.ObjectGripLocation(obj, 0) rs.ObjectGripLocation(obj, 0, point) rs.EnableObjectGrips(obj, False) See Also: EnableObjectGrips ObjectGripLocations """ rhobj = rhutil.coercerhinoobject(object_id, True, True) if not rhobj.GripsOn: return scriptcontext.errorhandler() grips = rhobj.GetGrips() if not grips or index<0 or index>=grips.Length: return scriptcontext.errorhandler() grip = grips[index] rc = grip.CurrentLocation if point: grip.CurrentLocation = rhutil.coerce3dpoint(point, True) scriptcontext.doc.Objects.GripUpdate(rhobj, True) scriptcontext.doc.Views.Redraw() return rc
def SetUserText(object_id, key, value=None, attach_to_geometry=False): """Sets or removes user text stored on an object. Parameters: object_id = the object's identifier key = the key name to set value[opt] = the string value to set. If omitted, the key/value pair specified by key will be deleted attach_to_geometry[opt] = location on the object to store the user text Returns: True or False indicating success or failure Example: import rhinoscriptsyntax as rs obj = rs.GetObject("Select object") if obj: rs.SetUserText( obj, "PartNo", "KM40-4960" ) rs.SetUserText( obj, "Price", "1.25" ) See Also: GetUserText IsUserText """ obj = rhutil.coercerhinoobject(object_id, True, True) if type(key) is not str: key = str(key) if value and type(value) is not str: value = str(value) if attach_to_geometry: return obj.Geometry.SetUserString(key, value) return obj.Attributes.SetUserString(key, value)
def HatchRotation(hatch_id, rotation=None): """Returns or modifies the rotation applied to the hatch pattern when it is mapped to the hatch's plane Parameters: hatch_id = identifier of a hatch object rotation[opt] = rotation angle in degrees Returns: if rotation is not defined, the current rotation angle if rotation is specified, the previous rotation angle None on error Example: import rhinoscriptsyntax as rs objects = rs.AllObjects() if objects: for obj in objects: if rs.IsHatch(obj) and rs.HatchRotation(obj)>0: rs.HatchRotation(obj,0) See Also: AddHatch AddHatches HatchPattern HatchScale IsHatch """ hatchobj = rhutil.coercerhinoobject(hatch_id, True, True) if not isinstance(hatchobj, Rhino.DocObjects.HatchObject): return scriptcontext.errorhandler() rc = hatchobj.HatchGeometry.PatternRotation rc = Rhino.RhinoMath.ToDegrees(rc) if rotation is not None and rotation!=rc: rotation = Rhino.RhinoMath.ToRadians(rotation) hatchobj.HatchGeometry.PatternRotation = rotation hatchobj.CommitChanges() scriptcontext.doc.Views.Redraw() return rc
def ExplodeHatch(hatch_id, delete=False): """Explodes a hatch object into its component objects. The exploded objects will be added to the document. If the hatch object uses a solid pattern, then planar face Brep objects will be created. Otherwise, line curve objects will be created Parameters: hatch_id = identifier of a hatch object delete[opt] = delete the hatch object Returns: list of identifiers for the newly created objects None on error """ rhobj = rhutil.coercerhinoobject(hatch_id, True, True) pieces = rhobj.HatchGeometry.Explode() if not pieces: return scriptcontext.errorhandler() attr = rhobj.Attributes rc = [] for piece in pieces: id = None if isinstance(piece, Rhino.Geometry.Curve): id = scriptcontext.doc.Objects.AddCurve(piece, attr) elif isinstance(piece, Rhino.Geometry.Brep): id = scriptcontext.doc.Objects.AddBrep(piece, attr) if id: rc.append(id) if delete: scriptcontext.doc.Objects.Delete(rhobj) return rc
def GetUserText(object_id, key=None, attached_to_geometry=False): """Returns user text stored on an object. Parameters: object_id = the object's identifies key[opt] = the key name. If omitted all key names for an object are returned attached_to_geometry[opt] = location on the object to retrieve the user text Returns: if key is specified, the associated value if successful if key is not specified, a list of key names if successful Example: import rhinoscriptsyntax as rs obj = rs.GetObject("Select object") if obj: print rs.GetUserText(obj, "PartNo") print rs.GetUserText(obj, "Price") See Also: IsUserText SetUserText """ obj = rhutil.coercerhinoobject(object_id, True, True) source = None if attached_to_geometry: source = obj.Geometry else: source = obj.Attributes rc = None if key: return source.GetUserString(key) userstrings = source.GetUserStrings() return [userstrings.GetKey(i) for i in range(userstrings.Count)]
def PointCloudHidePoints(object_id, hidden=[]): """Returns or modifies the hidden points of a point cloud object Parameters: object_id: the point cloud object's identifier hidden: list of hidden values if you want to hide certain points Returns: List of point cloud hidden states """ rhobj = rhutil.coercerhinoobject(object_id) if rhobj: pc = rhobj.Geometry else: pc = rhutil.coercegeometry(object_id, True) if isinstance(pc, Rhino.Geometry.PointCloud): rc = None if pc.ContainsHiddenFlags: rc = [item.Hidden for item in pc] if hidden is None: pc.ClearHiddenFlags() elif len(hidden) == pc.Count: for i in range(pc.Count): pc[i].Hidden = hidden[i] if rhobj: rhobj.CommitChanges() scriptcontext.doc.Views.Redraw() return rc
def PointCloudPointColors(object_id, colors=[]): """Returns or modifies the point colors of a point cloud object Parameters: object_id: the point cloud object's identifier colors: list of color values if you want to adjust colors Returns: List of point cloud colors """ rhobj = rhutil.coercerhinoobject(object_id) if rhobj: pc = rhobj.Geometry else: pc = rhutil.coercegeometry(object_id, True) if isinstance(pc, Rhino.Geometry.PointCloud): rc = None if pc.ContainsColors: rc = [item.Color for item in pc] if colors is None: pc.ClearColors() elif len(colors) == pc.Count: for i in range(pc.Count): pc[i].Color = rhutil.coercecolor(colors[i]) if rhobj: rhobj.CommitChanges() scriptcontext.doc.Views.Redraw() return rc
def NextObject(object_id, select=False, include_lights=False, include_grips=False): """Returns the identifier of the next object in the document Parameters: object_id = the identifier of the object from which to get the next object select[opt] = select the object include_lights[opt] = include lights in the potential set include_grips[opt] = include grips in the potential set Returns: identifier of the object on success Example: import rhinoscriptsyntax as rs obj = rs.FirstObject() while obj: print "Object identifier:", obj obj = rs.NextObject(obj) See Also: FirstObject LastObject """ current_obj = rhutil.coercerhinoobject(object_id, True) settings = Rhino.DocObjects.ObjectEnumeratorSettings() settings.IncludeLights = include_lights settings.IncludeGrips = include_grips settings.DeletedObjects = False rhobjs = scriptcontext.doc.Objects.GetObjectList(settings) found = False for obj in rhobjs: if found and obj: return obj.Id if obj.Id == current_obj.Id: found = True
def Area(object_id): "Compute the area of a closed curve, hatch, surface, polysurface, or mesh" rhobj = rhutil.coercerhinoobject(object_id, True, True) mp = Rhino.Geometry.AreaMassProperties.Compute(rhobj.Geometry) if mp is None: raise Exception("unable to compute area mass properties") return mp.Area
def MeshToNurb(object_id, trimmed_triangles=True, delete_input=False): """Duplicates each polygon in a mesh with a NURBS surface. The resulting surfaces are then joined into a polysurface and added to the document Parameters: object_id = identifier of a mesh object trimmed_triangles[opt] = if True, triangles in the mesh will be represented by a trimmed plane delete_input[opt] = delete input object Returns: list of identifiers for the new breps on success Example: import rhinoscriptsyntax as rs obj = rs.GetObject("Select mesh", rs.filter.mesh) if obj: rs.MeshToNurb(obj) See Also: IsMesh MeshFaces MeshVertices """ mesh = rhutil.coercemesh(object_id, True) pieces = mesh.SplitDisjointPieces() breps = [Rhino.Geometry.Brep.CreateFromMesh(piece,trimmed_triangles) for piece in pieces] rhobj = rhutil.coercerhinoobject(object_id, True, True) attr = rhobj.Attributes ids = [scriptcontext.doc.Objects.AddBrep(brep, attr) for brep in breps] if delete_input: scriptcontext.doc.Objects.Delete(rhobj, True) scriptcontext.doc.Views.Redraw() return ids
def IsUserText(object_id): """Verifies that an object contains user text Parameters: object_id = the object's identifier Returns: 0 = no user text 1 = attribute user text 2 = geometry user text 3 = both attribute and geometry user text Example: import rhinoscriptsyntax as rs obj = rs.GetObject("Select object") if obj: usertext_type = rs.IsUserText(obj) if usertext_type==0: print "Object has no user text" elif usertext_type==1: print "Object has attribute user text" elif usertext_type==2: print "Object has geometry user text" elif usertext_type==3: print "Object has attribute and geometry user text" See Also: GetUserText SetUserText """ obj = rhutil.coercerhinoobject(object_id, True, True) rc = 0 if obj.Attributes.UserStringCount: rc = rc|1 if obj.Geometry.UserStringCount: rc = rc|2 return rc
def ObjectDescription(object_id): """Returns a short text description of an object Parameters: object_id = identifier of an object """ rhobj = rhutil.coercerhinoobject(object_id, True, True) return rhobj.ShortDescription(False)
def ObjectGripLocations(object_id, points=None): """Returns or modifies the location of all grips owned by an object. The locations of the grips are returned in a list of Point3d with each position in the list corresponding to that grip's index. To modify the locations of the grips, you must provide a list of points that contain the same number of points at grips Parameters: object_id = identifier of the object points [opt] = list of 3D points identifying the new grip locations Returns: if points is not specified, the current location of all grips if points is specified, the previous location of all grips None if not successful """ rhobj = rhutil.coercerhinoobject(object_id, True, True) if not rhobj.GripsOn: return scriptcontext.errorhandler() grips = rhobj.GetGrips() if grips is None: return scriptcontext.errorhandler() rc = [grip.CurrentLocation for grip in grips] if points and len(points)==len(grips): points = rhutil.coerce3dpointlist(points, True) for i, grip in enumerate(grips): point = points[i] grip.CurrentLocation = point scriptcontext.doc.Objects.GripUpdate(rhobj, True) scriptcontext.doc.Views.Redraw() return rc
def AddMaterialToObject(object_id): """Adds material to an object and returns the new material's index. If the object already has a material, the the object's current material index is returned. Parameters: object_id = identifier of an object Returns: material index of the object Example: import rhinoscriptsyntax as rs obj = rs.GetObject() if obj: index = rs.ObjectMaterialIndex(obj) See Also: IsMaterialDefault ObjectMaterialIndex ObjectMaterialSource """ rhino_object = rhutil.coercerhinoobject(object_id, True, True) attr = rhino_object.Attributes if attr.MaterialSource!=Rhino.DocObjects.ObjectMaterialSource.MaterialFromObject: attr.MaterialSource = Rhino.DocObjects.ObjectMaterialSource.MaterialFromObject scriptcontext.doc.Objects.ModifyAttributes(rhino_object, attr, True) attr = rhino_object.Attributes material_index = attr.MaterialIndex if material_index>-1: return material_index material_index = scriptcontext.doc.Materials.Add() attr.MaterialIndex = material_index scriptcontext.doc.Objects.ModifyAttributes(rhino_object, attr, True) return material_index
def MeshToNurb(object_id, trimmed_triangles=True, delete_input=False): """Duplicates each polygon in a mesh with a NURBS surface. The resulting surfaces are then joined into a polysurface and added to the document Parameters: object_id = identifier of a mesh object trimmed_triangles[opt] = if True, triangles in the mesh will be represented by a trimmed plane delete_input[opt] = delete input object Returns: list of identifiers for the new breps on success """ mesh = rhutil.coercemesh(object_id, True) pieces = mesh.SplitDisjointPieces() breps = [Rhino.Geometry.Brep.CreateFromMesh(piece,trimmed_triangles) for piece in pieces] rhobj = rhutil.coercerhinoobject(object_id, True, True) attr = rhobj.Attributes ids = [scriptcontext.doc.Objects.AddBrep(brep, attr) for brep in breps] if delete_input: scriptcontext.doc.Objects.Delete(rhobj, True) scriptcontext.doc.Views.Redraw() return ids
def PointCloudPointColors(object_id, colors=[]): """Returns or modifies the point colors of a point cloud object Parameters: object_id (guid): the point cloud object's identifier colors ([color, ...]) list of color values if you want to adjust colors Returns: list(color, ...): List of point cloud colors Example: import rhinoscriptsyntax as rs import random def RandomColor(): red = random.randint(0,255) green = random.randint(0,255) blue = random.randint(0,255) return rs.coercecolor((red,green,blue)) obj = rs.GetObject("Select point cloud", rs.filter.pointcloud) if obj: colors = [RandomColor() for i in range(rs.PointCloudCount(obj))] rs.PointCloudColors(obj, colors) See Also: PointCloudHasHiddenPoints PointCloudHasPointColors PointCloudHidePoints """ rhobj = rhutil.coercerhinoobject(object_id) if rhobj: pc = rhobj.Geometry else: pc = rhutil.coercegeometry(object_id, True) if isinstance(pc, Rhino.Geometry.PointCloud): rc = None if pc.ContainsColors: rc = [item.Color for item in pc] if colors is None: pc.ClearColors() elif len(colors) == pc.Count: for i in range(pc.Count): pc[i].Color = rhutil.coercecolor(colors[i]) if rhobj: rhobj.CommitChanges() scriptcontext.doc.Views.Redraw() return rc
def GetUserText(object_id, key=None, attached_to_geometry=False): """Returns user text that is stored on an object. Parameters: object_id = the object's identifies key[opt] = the key name. If omitted all key names for an object are returned attached_to_geometry[opt] = location on the object to retrieve the user text Returns: if key is specified, the associated value if successful if key is not specified, a list of key names if successful """ obj = rhutil.coercerhinoobject(object_id, True, True) source = None if attached_to_geometry: source = obj.Geometry else: source = obj.Attributes rc = None if key: return source.GetUserString(key) else: userstrings = source.GetUserStrings() rc = [userstrings.GetKey(i) for i in range(userstrings.Count)] return rc
def ObjectGripsOn(object_id): """Verifies that an object's grips are turned on Parameters: object_id (guid): identifier of the object Returns: bool: True or False indicating Grips state None: on error Example: import rhinoscriptsyntax as rs obj = rs.GetObject("Select object") if rs.ObjectGripsOn(obj): print "Grip count =", rs.ObjectGripCount(obj) See Also: EnableObjectGrips ObjectGripCount ObjectGripsSelected SelectObjectGrips UnselectObjectGrips """ rhobj = rhutil.coercerhinoobject(object_id, True, True) return rhobj.GripsOn
def ObjectMaterialIndex(object_id, material_index=None): """Returns or changes the material index of an object. Rendering materials are stored in Rhino's rendering material table. The table is conceptually an array. Render materials associated with objects and layers are specified by zero based indices into this array. Parameters: object_id = identifier of an object index = optional. the new material index Returns: If the return value of ObjectMaterialSource is "material by object", then the return value of this function is the index of the object's rendering material. A material index of -1 indicates no material has been assigned, and that Rhino's internal default material has been assigned to the object. None on failure """ rhino_object = rhutil.coercerhinoobject(object_id, True, True) if material_index is not None and material_index < scriptcontext.doc.Materials.Count: attrs = rhino_object.Attributes attrs.MaterialIndex = material_index scriptcontext.doc.Objects.ModifyAttributes(rhino_object, attrs, True) return rhino_object.Attributes.MaterialIndex
def AddMaterialToObject(object_id): """Adds material to an object and returns the new material's index. If the object already has a material, the the object's current material index is returned. Parameters: object_id = identifier of an object Returns: material index of the object """ rhino_object = rhutil.coercerhinoobject(object_id, True, True) attr = rhino_object.Attributes if attr.MaterialSource != Rhino.DocObjects.ObjectMaterialSource.MaterialFromObject: attr.MaterialSource = Rhino.DocObjects.ObjectMaterialSource.MaterialFromObject scriptcontext.doc.Objects.ModifyAttributes(rhino_object, attr, True) attr = rhino_object.Attributes material_index = attr.MaterialIndex if material_index > -1: return material_index material_index = scriptcontext.doc.Materials.Add() attr.MaterialIndex = material_index scriptcontext.doc.Objects.ModifyAttributes(rhino_object, attr, True) return material_index
def MatchMaterial(source, destination): """Copies the material definition from one material to one or more objects Parameters: source (number|guid): source material index -or- identifier of the source object. The object must have a material assigned destination ([guid, ...]) identifiers(s) of the destination object(s) Returns: number: number of objects that were modified if successful None: if not successful or on error Example: import rhinoscriptsyntax as rs obj = rs.GetObject("Select source object") if obj and rs.ObjectMaterialIndex(obj)>-1: objects = rs.GetObjects("Select destination objects") if objects: rs.MatchMaterial( obj, objects ) See Also: CopyMaterial LayerMaterialIndex ObjectMaterialIndex """ source_id = rhutil.coerceguid(source) source_mat = None if source_id: rhobj = rhutil.coercerhinoobject(source_id, True, True) source = rhobj.Attributes.MaterialIndex mat = scriptcontext.doc.Materials[source] if not mat: return scriptcontext.errorhandler() destination_id = rhutil.coerceguid(destination) if destination_id: destination = [destination] ids = [rhutil.coerceguid(d) for d in destination] rc = 0 for id in ids: rhobj = scriptcontext.doc.Objects.Find(id) if rhobj: rhobj.Attributes.MaterialIndex = source rhobj.Attributes.MaterialSource = Rhino.DocObjects.ObjectMaterialSource.MaterialFromObject rhobj.CommitChanges() rc += 1 if rc > 0: scriptcontext.doc.Views.Redraw() return rc
def PointCloudPointColors(object_id, colors=[]): """Returns or modifies the point colors of a point cloud object Parameters: object_id: the point cloud object's identifier colors: list of color values if you want to adjust colors Returns: List of point cloud colors """ rhobj = rhutil.coercerhinoobject(object_id) if rhobj: pc = rhobj.Geometry else: pc = rhutil.coercegeometry(object_id, True) if isinstance(pc, Rhino.Geometry.PointCloud): rc = None if pc.ContainsColors: rc = [item.Color for item in pc] if colors is None: pc.ClearColors() elif len(colors)==pc.Count: for i in range(pc.Count): pc[i].Color = rhutil.coercecolor(colors[i]) if rhobj: rhobj.CommitChanges() scriptcontext.doc.Views.Redraw() return rc
def HatchRotation(hatch_id, rotation=None): """Returns or modifies the rotation applied to the hatch pattern when it is mapped to the hatch's plane Parameters: hatch_id = identifier of a hatch object rotation[opt] = rotation angle in degrees Returns: if rotation is not defined, the current rotation angle if rotation is specified, the previous rotation angle None on error """ hatchobj = rhutil.coercerhinoobject(hatch_id, True, True) if not isinstance(hatchobj, Rhino.DocObjects.HatchObject): return scriptcontext.errorhandler() rc = hatchobj.HatchGeometry.PatternRotation rc = Rhino.RhinoMath.ToDegrees(rc) if rotation is not None and rotation != rc: rotation = Rhino.RhinoMath.ToRadians(rotation) hatchobj.HatchGeometry.PatternRotation = rotation hatchobj.CommitChanges() scriptcontext.doc.Views.Redraw() return rc
def HatchPattern(hatch_id, hatch_pattern=None): """Returns or changes a hatch object's hatch pattern Paramters: hatch_id = identifier of a hatch object hatch_pattern[opt] = name of an existing hatch pattern to replace the current hatch pattern Returns: if hatch_pattern is not specified, the current hatch pattern if hatch_pattern is specified, the previous hatch pattern None on error """ hatchobj = rhutil.coercerhinoobject(hatch_id, True, True) if not isinstance(hatchobj, Rhino.DocObjects.HatchObject): return scriptcontext.errorhandler() old_index = hatchobj.HatchGeometry.PatternIndex if hatch_pattern: new_index = scriptcontext.doc.HatchPatterns.Find(hatch_pattern, True) if new_index < 0: return scriptcontext.errorhandler() hatchobj.HatchGeometry.PatternIndex = new_index hatchobj.CommitChanges() scriptcontext.doc.Views.Redraw() return scriptcontext.doc.HatchPatterns[old_index].Name
def AddBlock(object_ids, base_point, name=None, delete_input=False): """Adds a new block definition to the document Parameters: object_ids = objects that will be included in the block base_point = 3D base point for the block definition name(opt) = name of the block definition. If omitted a name will be automatically generated delete_input(opt) = if True, the object_ids will be deleted Returns: name of new block definition on success """ base_point = rhutil.coerce3dpoint(base_point, True) if not name: name = scriptcontext.doc.InstanceDefinitions.GetUnusedInstanceDefinitionName( ) found = scriptcontext.doc.InstanceDefinitions.Find(name, True) objects = [] for id in object_ids: obj = rhutil.coercerhinoobject(id, True) if obj.IsReference: return ot = obj.ObjectType if ot == Rhino.DocObjects.ObjectType.Light: return if ot == Rhino.DocObjects.ObjectType.Grip: return if ot == Rhino.DocObjects.ObjectType.Phantom: return if ot == Rhino.DocObjects.ObjectType.InstanceReference and found: uses, nesting = obj.UsesDefinition(found.Index) if uses: return objects.append(obj) if objects: geometry = [obj.Geometry for obj in objects] attrs = [obj.Attributes for obj in objects] rc = scriptcontext.doc.InstanceDefinitions.Add(name, "", base_point, geometry, attrs) if rc >= 0: if delete_input: for obj in objects: scriptcontext.doc.Objects.Delete(obj, True) scriptcontext.doc.Views.Redraw() return name
def PointCloudHidePoints(object_id, hidden=[]): """Returns or modifies the hidden points of a point cloud object Parameters: object_id: the point cloud object's identifier hidden: list of hidden values if you want to hide certain points Returns: List of point cloud hidden states """ rhobj = rhutil.coercerhinoobject(object_id) if rhobj: pc = rhobj.Geometry else: pc = rhutil.coercegeometry(object_id, True) if isinstance(pc, Rhino.Geometry.PointCloud): rc = None if pc.ContainsHiddenFlags: rc = [item.Hidden for item in pc] if hidden is None: pc.ClearHiddenFlags() elif len(hidden)==pc.Count: for i in range(pc.Count): pc[i].Hidden = hidden[i] if rhobj: rhobj.CommitChanges() scriptcontext.doc.Views.Redraw() return rc
def RemoveObjectsFromGroup(object_ids, group_name): """Removes one or more objects from an existing group Parameters: object_ids = a list of object identifiers group_name = the name of an existing group Returns: The number of objects removed from the group is successful None on error """ if not isinstance(group_name, str): group_name = str(group_name) index = scriptcontext.doc.Groups.Find(group_name, True) if index<0: return scriptcontext.errorhandler() id = rhutil.coerceguid(objects_ids, False) if id: object_ids = [id] objects_removed = 0 for id in object_ids: rhinoobject = rhutil.coercerhinoobject(id, True, True) attrs = rhinoobject.Attributes attrs.RemoveFromGroup(index) if scriptcontext.doc.Objects.ModifyAttributes(rhinoobject, attrs, True): objects_removed+=1 return objects_removed
def IsObjectInGroup(object_id, group_name=None): """Verifies that an object is a member of a group Parameters: object_id: The identifier of an object group_name[opt]: The name of a group. If omitted, the function verifies that the object is a member of any group Returns: True if the object is a member of the specified group. If a group_name was not specified, the object is a member of some group. False if the object is not a member of the specified group. If a group_name was not specified, the object is not a member of any group """ rhobj = rhutil.coercerhinoobject(object_id, True, True) count = rhobj.GroupCount if count < 1: return False if not group_name: return True index = scriptcontext.doc.Groups.Find(group_name, True) if index < 0: raise ValueError("%s group does not exist" % group_name) group_ids = rhobj.GetGroupList() for id in group_ids: if id == index: return True return False
def MatchObjectAttributes(target_ids, source_id=None): """Matches, or copies the attributes of a source object to a target object Parameters: target_ids = identifiers of objects to copy attributes to source_id[opt] = identifier of object to copy attributes from. If None, then the default attributes are copied to the target_ids Returns: number of objects modified """ id = rhutil.coerceguid(target_ids, False) if id: target_ids = [id] source_attr = Rhino.DocObjects.ObjectAttributes() if source_id: source = rhutil.coercerhinoobject(source_id, True, True) source_attr = source.Attributes rc = 0 for id in target_ids: id = rhutil.coerceguid(id, True) if scriptcontext.doc.Objects.ModifyAttributes(id, source_attr, True): rc += 1 if rc: scriptcontext.doc.Views.Redraw() return rc
def ObjectGripLocations(object_id, points=None): """Returns or modifies the location of all grips owned by an object. The locations of the grips are returned in a list of Point3d with each position in the list corresponding to that grip's index. To modify the locations of the grips, you must provide a list of points that contain the same number of points at grips Parameters: object_id (guid): identifier of the object points ([point, ...], optional) list of 3D points identifying the new grip locations Returns: list(point, ...): if points is not specified, the current location of all grips list(point, ...): if points is specified, the previous location of all grips None: if not successful Example: import rhinoscriptsyntax as rs obj = rs.GetObject("Select curve", rs.filter.curve) if obj: rs.EnableObjectGrips( obj ) points = rs.ObjectGripLocations(obj) for point in points: print point See Also: EnableObjectGrips ObjectGripCount ObjectGripLocation """ rhobj = rhutil.coercerhinoobject(object_id, True, True) if not rhobj.GripsOn: return scriptcontext.errorhandler() grips = rhobj.GetGrips() if grips is None: return scriptcontext.errorhandler() rc = [grip.CurrentLocation for grip in grips] if points and len(points) == len(grips): points = rhutil.coerce3dpointlist(points, True) for i, grip in enumerate(grips): point = points[i] grip.CurrentLocation = point scriptcontext.doc.Objects.GripUpdate(rhobj, True) scriptcontext.doc.Views.Redraw() return rc
def ObjectGripLocation(object_id, index, point=None): """Returns or modifies the location of an object's grip Parameters: object_id = identifier of the object index = index of the grip to either query or modify point [opt] = 3D point defining new location of the grip Returns: if point is not specified, the current location of the grip referenced by index if point is specified, the previous location of the grip referenced by index None on error """ rhobj = rhutil.coercerhinoobject(object_id, True, True) if not rhobj.GripsOn: return scriptcontext.errorhandler() grips = rhobj.GetGrips() if not grips or index < 0 or index >= grips.Length: return scriptcontext.errorhandler() grip = grips[index] rc = grip.CurrentLocation if point: grip.CurrentLocation = rhutil.coerce3dpoint(point, True) scriptcontext.doc.Objects.GripUpdate(rhobj, True) scriptcontext.doc.Views.Redraw() return rc
def ObjectGripCount(object_id): """Returns number of grips owned by an object Parameters: object_id (guid): identifier of the object Returns: number: number of grips if successful None: on error Example: import rhinoscriptsyntax as rs obj = rs.GetObject("Select object") if rs.ObjectGripsOn(obj): print "Grip count =", rs.ObjectGripCount(obj) See Also: EnableObjectGrips ObjectGripsOn ObjectGripsSelected SelectObjectGrips UnselectObjectGrips """ rhobj = rhutil.coercerhinoobject(object_id, True, True) grips = rhobj.GetGrips() if not grips: return scriptcontext.errorhandler() return grips.Length
def RemoveObjectFromAllGroups(object_id): """Removes a single object from any and all groups that it is a member. Neither the object nor the group can be reference objects Parameters: object_id (guid): the object identifier Returns: bool: True or False indicating success or failure Example: import rhinoscriptsyntax as rs object = rs.GetObject("Select object") if object: rs.RemoveObjectFromAllGroups(object) See Also: IsGroupEmpty ObjectGroups ObjectsByGroup RemoveObjectFromGroup RemoveObjectsFromGroup """ rhinoobject = rhutil.coercerhinoobject(object_id, True, True) if rhinoobject.GroupCount < 1: return False attrs = rhinoobject.Attributes attrs.RemoveFromAllGroups() return scriptcontext.doc.Objects.ModifyAttributes(rhinoobject, attrs, True)
def NextObject(object_id, select=False, include_lights=False, include_grips=False): """Returns the identifier of the next object in the document Parameters: object_id = the identifier of the object from which to get the next object select[opt] = select the object include_lights[opt] = include lights in the potential set include_grips[opt] = include grips in the potential set Returns: identifier of the object on success """ current_obj = rhutil.coercerhinoobject(object_id, True) settings = Rhino.DocObjects.ObjectEnumeratorSettings() settings.IncludeLights = include_lights settings.IncludeGrips = include_grips settings.DeletedObjects = False rhobjs = scriptcontext.doc.Objects.GetObjectList(settings) found = False for obj in rhobjs: if found and obj: return obj.Id if obj.Id == current_obj.Id: found = True
def ObjectGripLocation(object_id, index, point=None): """Returns or modifies the location of an object's grip Parameters: object_id (guid) identifier of the object index (number): index of the grip to either query or modify point (point, optional): 3D point defining new location of the grip Returns: point: if point is not specified, the current location of the grip referenced by index point: if point is specified, the previous location of the grip referenced by index None: on error Example: import rhinoscriptsyntax as rs obj = rs.GetObject("Select curve", rs.filter.curve) if obj: rs.EnableObjectGrips(obj) point = rs.ObjectGripLocation(obj, 0) point[0] = point[0] + 1.0 point[1] = point[1] + 1.0 point[2] = point[2] + 1.0 rs.ObjectGripLocation(obj, 0, point) rs.EnableObjectGrips(obj, False) See Also: EnableObjectGrips ObjectGripLocations """ rhobj = rhutil.coercerhinoobject(object_id, True, True) if not rhobj.GripsOn: return scriptcontext.errorhandler() grips = rhobj.GetGrips() if not grips or index < 0 or index >= grips.Length: return scriptcontext.errorhandler() grip = grips[index] rc = grip.CurrentLocation if point: grip.CurrentLocation = rhutil.coerce3dpoint(point, True) scriptcontext.doc.Objects.GripUpdate(rhobj, True) scriptcontext.doc.Views.Redraw() return rc
def ObjectLayout(object_id, layout=None, return_name=True): """Returns or changes the layout or model space of an object Parameters: object_id = identifier of the object layout[opt] = to change, or move, an object from model space to page layout space, or from one page layout to another, then specify the title or identifier of an existing page layout view. To move an object from page layout space to model space, just specify None return_name[opt] = If True, the name, or title, of the page layout view is returned. If False, the identifier of the page layout view is returned Returns: if layout is not specified, the object's current page layout view if layout is specfied, the object's previous page layout view None if not successful """ rhobj = rhutil.coercerhinoobject(object_id, True, True) rc = None if rhobj.Attributes.Space == Rhino.DocObjects.ActiveSpace.PageSpace: page_id = rhobj.Attributes.ViewportId pageview = scriptcontext.doc.Views.Find(page_id) if return_name: rc = pageview.MainViewport.Name else: rc = pageview.MainViewport.Id if layout is None: #move to model space rhobj.Attributes.Space = Rhino.DocObjects.ActiveSpace.ModelSpace rhobj.Attributes.ViewportId = System.Guid.Empty rhobj.CommitChanges() scriptcontext.doc.Views.Redraw() else: if layout: layout = scriptcontext.doc.Views.Find(layout, False) if layout is not None and isinstance(layout, Rhino.Display.RhinoPageView): rhobj.Attributes.ViewportId = layout.MainViewport.Id rhobj.Attributes.Space = Rhino.DocObjects.ActiveSpace.PageSpace rhobj.CommitChanges() scriptcontext.doc.Views.Redraw() return rc
def EnableObjectGrips(object_id, enable=True): """Enables or disables an object's grips. For curves and surfaces, these are also called control points. Parameters: object_id (guid): identifier of the object enable (bool, optional): if True, the specified object's grips will be turned on. Otherwise, they will be turned off Returns: bool: True on success, False on failure Example: import rhinoscriptsyntax as rs objects = rs.GetObjects("Select objects") if objects: [rs.EnableObjectGrips(obj) for obj in objs] See Also: ObjectGripCount ObjectGripsOn ObjectGripsSelected SelectObjectGrips UnselectObjectGrips """ rhobj = rhutil.coercerhinoobject(object_id, True, True) if enable != rhobj.GripsOn: rhobj.GripsOn = enable scriptcontext.doc.Views.Redraw()
def HatchPattern(hatch_id, hatch_pattern=None): """Returns or changes a hatch object's hatch pattern Parameters: hatch_id (guid): identifier of a hatch object hatch_pattern (str, optional): name of an existing hatch pattern to replace the current hatch pattern Returns: str: if hatch_pattern is not specified, the current hatch pattern str: if hatch_pattern is specified, the previous hatch pattern None: on error Example: import rhinoscriptsyntax as rs objects = rs.AllObjects() if objects is not None: for obj in objects: if rs.IsHatch(obj) and rs.HatchPattern(obj)=="Solid": rs.SelectObject(obj) See Also: AddHatch AddHatches HatchRotation HatchScale IsHatch """ hatchobj = rhutil.coercerhinoobject(hatch_id, True, True) if not isinstance(hatchobj, Rhino.DocObjects.HatchObject): return scriptcontext.errorhandler() old_index = hatchobj.HatchGeometry.PatternIndex if hatch_pattern: __initHatchPatterns() new_patt = scriptcontext.doc.HatchPatterns.FindName(hatch_pattern) if new_patt is None: return scriptcontext.errorhandler() hatchobj.HatchGeometry.PatternIndex = new_patt.Index hatchobj.CommitChanges() scriptcontext.doc.Views.Redraw() return scriptcontext.doc.HatchPatterns[old_index].Name
def ExplodeText(text_id, delete=False): """Creates outline curves for a given text entity Parameters: text_id (guid): identifier of Text object to explode delete (bool, optional): delete the text object after the curves have been created Returns: list(guid): of outline curves Example: import rhinoscriptsyntax as rs text = rs.AddText("abcd", rs.WorldXYPlane()) rs.ExplodeText(text, True) See Also: IsHatch HatchPattern HatchRotation HatchScale """ rhobj = rhutil.coercerhinoobject(text_id, True, True) curves = rhobj.Geometry.Explode() attr = rhobj.Attributes rc = [scriptcontext.doc.Objects.AddCurve(curve, attr) for curve in curves] if delete: scriptcontext.doc.Objects.Delete(rhobj, True) scriptcontext.doc.Views.Redraw() return rc
def IsVisibleInView(object_id, view=None): """Verifies an object is visible in a view""" rhobj = rhutil.coercerhinoobject(object_id, True, True) viewport = __viewhelper(view).MainViewport bbox = rhobj.Geometry.GetBoundingBox(True) return rhobj.Visible and viewport.IsVisible(bbox)
def __coerceannotation(object_id): annotation_object = rhutil.coercerhinoobject(object_id, True) if not isinstance(annotation_object, Rhino.DocObjects.AnnotationObjectBase): raise ValueError("object_id does not refer to an Annotation") return annotation_object
def __InstanceObjectFromId(id, raise_if_missing): rhobj = rhutil.coercerhinoobject(id, True, raise_if_missing) if isinstance(rhobj, Rhino.DocObjects.InstanceObject): return rhobj if raise_if_missing: raise ValueError("unable to find InstanceObject")