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 MeshVertexColors(mesh_id, colors=0): """Returns of modifies vertex colors of a mesh Parameters: mesh_id = identifier of a mesh object colors[opt] = A list of color values. Note, for each vertex, there must be a corresponding vertex color. If the value is None, then any existing vertex colors will be removed from the mesh Returns: if colors is not specified, the current vertex colors if colors is specified, the previous vertex colors """ mesh = rhutil.coercemesh(mesh_id, True) rc = [mesh.VertexColors[i] for i in range(mesh.VertexColors.Count)] if colors == 0: return rc if colors is None: mesh.VertexColors.Clear() else: color_count = len(colors) if color_count != mesh.Vertices.Count: raise ValueError("length of colors must match vertex count") colors = [rhutil.coercecolor(c) for c in colors] mesh.VertexColors.Clear() for c in colors: mesh.VertexColors.Add(c) id = rhutil.coerceguid(mesh_id, True) scriptcontext.doc.Objects.Replace(id, mesh) scriptcontext.doc.Views.Redraw() return rc
def RenderColor(item, color=None): """Returns or sets the render ambient light or background color Parameters: item = 0=ambient light color, 1=background color color[opt] = the new color value. If omitted, the curren item color is returned Returns: if color is not specified, the current item color if color is specified, the previous item color """ if item != 0 and item != 1: raise ValueError("item must be 0 or 1") if item == 0: rc = scriptcontext.doc.RenderSettings.AmbientLight else: rc = scriptcontext.doc.RenderSettings.BackgroundColorTop if color is not None: color = rhutil.coercecolor(color, True) settings = scriptcontext.doc.RenderSettings if item == 0: settings.AmbientLight = color else: settings.BackgroundColorTop = color scriptcontext.doc.RenderSettings = settings scriptcontext.doc.Views.Redraw() return rc
def RenderColor(item, color=None): """Returns or sets the render ambient light or background color Parameters: item = 0=ambient light color, 1=background color color[opt] = the new color value. If omitted, the curren item color is returned Returns: if color is not specified, the current item color if color is specified, the previous item color Example: import rhinoscriptsyntax as rs render_background_color = 1 rs.RenderColor( render_background_color, (0,0,255) ) See Also: RenderAntialias RenderResolution RenderSettings """ if item!=0 and item!=1: raise ValueError("item must be 0 or 1") if item==0: rc = scriptcontext.doc.RenderSettings.AmbientLight else: rc = scriptcontext.doc.RenderSettings.BackgroundColorTop if color is not None: color = rhutil.coercecolor(color, True) settings = scriptcontext.doc.RenderSettings if item==0: settings.AmbientLight = color else: settings.BackgroundColorTop = color scriptcontext.doc.RenderSettings = settings scriptcontext.doc.Views.Redraw() return rc
def AddLayer(name=None, color=None, visible=True, locked=False, parent=None): """Add a new layer to the document Parameters: name[opt]: The name of the new layer. If omitted, Rhino automatically generates the layer name. color[opt]: A Red-Green-Blue color value or System.Drawing.Color. If omitted, the color Black is assigned. visible[opt]: layer's visibility locked[opt]: layer's locked state parent[opt]: name of the new layer's parent layer. If omitted, the new layer will not have a parent layer. Returns: The name of the new layer if successful. """ layer = Rhino.DocObjects.Layer.GetDefaultLayerProperties() if name: if not isinstance(name, str): name = str(name) layer.Name = name color = rhutil.coercecolor(color) if color: layer.Color = color layer.IsVisible = visible layer.IsLocked = locked if parent: parent = __getlayer(parent, True) layer.ParentLayerId = parent.Id index = scriptcontext.doc.Layers.Add(layer) return scriptcontext.doc.Layers[index].Name
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 AddPointCloud(points, colors=None): """Adds point cloud object to the document Parameters: points = list of values where every multiple of three represents a point colors[opt] = list of colors to apply to each point Returns: identifier of point cloud on success Example: import rhinoscriptsyntax as rs points = (0,0,0), (1,1,1), (2,2,2), (3,3,3) rs.AddPointCloud(points) See Also: IsPointCloud PointCloudCount PointCloudPoints """ points = rhutil.coerce3dpointlist(points, True) if colors and len(colors)==len(points): pc = Rhino.Geometry.PointCloud() for i in range(len(points)): color = rhutil.coercecolor(colors[i],True) pc.Add(points[i],color) points = pc rc = scriptcontext.doc.Objects.AddPointCloud(points) if rc==System.Guid.Empty: raise Exception("unable to add point cloud to document") scriptcontext.doc.Views.Redraw() return rc
def AddPointCloud(points, colors=None): """Adds point cloud object to the document Parameters: points ([point, ....]): list of values where every multiple of three represents a point colors ([color, ...]): list of colors to apply to each point Returns: guid: identifier of point cloud on success Example: import rhinoscriptsyntax as rs points = (0,0,0), (1,1,1), (2,2,2), (3,3,3) rs.AddPointCloud(points) See Also: IsPointCloud PointCloudCount PointCloudPoints """ points = rhutil.coerce3dpointlist(points, True) if colors and len(colors) == len(points): pc = Rhino.Geometry.PointCloud() for i in range(len(points)): color = rhutil.coercecolor(colors[i], True) pc.Add(points[i], color) points = pc rc = scriptcontext.doc.Objects.AddPointCloud(points) if rc == System.Guid.Empty: raise Exception("unable to add point cloud to document") scriptcontext.doc.Views.Redraw() return rc
def MaterialReflectiveColor(material_index, color=None): """Returns or modifies a material's reflective color. Parameters: material_index = zero based material index color[opt] = the new color value Returns: if color is not specified, the current material reflective color if color is specified, the previous material reflective color None on error Example: import rhinoscriptsyntax as rs obj = rs.GetObject("Select object") if obj: index = rs.ObjectMaterialIndex(obj) if index>-1: rs.MaterialReflectiveColor( index, (191, 191, 255) ) See Also: MaterialBump MaterialColor MaterialName MaterialShine MaterialTexture MaterialTransparency """ mat = scriptcontext.doc.Materials[material_index] if mat is None: return scriptcontext.errorhandler() rc = mat.ReflectionColor color = rhutil.coercecolor(color) if color: mat.ReflectionColor = color mat.CommitChanges() scriptcontext.doc.Views.Redraw() return rc
def LayerPrintColor(layer, color=None): """Returns or changes the print color of a layer. Layer print colors are represented as RGB colors. Parameters: layer = name of existing layer color[opt] = new print color Returns: if color is not specified, the current layer print color if color is specified, the previous layer print color None on error Example: import rhinoscriptsyntax as rs layers = rs.LayerNames() if layers: for layer in layers: black = rs.coercecolor((0,0,0)) if rs.LayerPrintColor(layer)!=black: rs.LayerPrintColor(layer, black) See Also: LayerLinetype LayerPrintWidth """ layer = __getlayer(layer, True) rc = layer.PlotColor if color: color = rhutil.coercecolor(color) layer.PlotColor = color scriptcontext.doc.Views.Redraw() return rc
def MeshVertexColors(mesh_id, colors=0): """Returns of modifies the vertex colors of a mesh object Parameters: mesh_id = identifier of a mesh object colors[opt] = A list of color values. Note, for each vertex, there must be a corresponding vertex color. If the value is None, then any existing vertex colors will be removed from the mesh Returns: if colors is not specified, the current vertex colors if colors is specified, the previous vertex colors """ mesh = rhutil.coercemesh(mesh_id, True) rc = [mesh.VertexColors[i] for i in range(mesh.VertexColors.Count)] if colors==0: return rc if colors is None: mesh.VertexColors.Clear() else: color_count = len(colors) if color_count!=mesh.Vertices.Count: raise ValueError("length of colors must match vertex count") colors = [rhutil.coercecolor(c) for c in colors] mesh.VertexColors.Clear() for c in colors: mesh.VertexColors.Add(c) id = rhutil.coerceguid(mesh_id, True) scriptcontext.doc.Objects.Replace(id, mesh) scriptcontext.doc.Views.Redraw() return rc
def ObjectsByColor(color, select=False, include_lights=False): """Returns identifiers of all objects based on color Parameters: color (color): color to get objects by select (bool, optional): select the objects include_lights (bool, optional): include lights in the set Returns: list(guid, ...): identifiers of objects of the selected color. Example: import rhinoscriptsyntax as rs obj = rs.GetObject("Pick any object") if obj: color = rs.ObjectColor(obj) rs.ObjectsByColor(color, True) See Also: """ color = rhutil.coercecolor(color, True) rhino_objects = scriptcontext.doc.Objects.FindByDrawColor( color, include_lights) if select: for obj in rhino_objects: obj.Select(True) scriptcontext.doc.Views.Redraw() return [obj.Id for obj in rhino_objects]
def AddLayer(name=None, color=None, visible=True, locked=False, parent=None): """Add a new layer to the document Parameters: name[opt]: The name of the new layer. If omitted, Rhino automatically generates the layer name. color[opt]: A Red-Green-Blue color value or System.Drawing.Color. If omitted, the color Black is assigned. visible[opt]: layer's visibility locked[opt]: layer's locked state parent[opt]: name of the new layer's parent layer. If omitted, the new layer will not have a parent layer. Returns: The full name of the new layer if successful. """ layer = Rhino.DocObjects.Layer.GetDefaultLayerProperties() if name: if not isinstance(name, str): name = str(name) layer.Name = name color = rhutil.coercecolor(color) if color: layer.Color = color layer.IsVisible = visible layer.IsLocked = locked if parent: parent = __getlayer(parent, True) layer.ParentLayerId = parent.Id index = scriptcontext.doc.Layers.Add(layer) return scriptcontext.doc.Layers[index].FullPath
def AddLayer(name=None, color=None, visible=True, locked=False, parent=None): """Add a new layer to the document Parameters: name[opt]: The name of the new layer. If omitted, Rhino automatically generates the layer name. color[opt]: A Red-Green-Blue color value or System.Drawing.Color. If omitted, the color Black is assigned. visible[opt]: layer's visibility locked[opt]: layer's locked state parent[opt]: name of the new layer's parent layer. If omitted, the new layer will not have a parent layer. Returns: The full name of the new layer if successful. Example: import rhinoscriptsyntax as rs from System.Drawing import Color print "New layer:", rs.AddLayer() print "New layer:", rs.AddLayer("MyLayer1") print "New layer:", rs.AddLayer("MyLayer2", Color.DarkSeaGreen) print "New layer:", rs.AddLayer("MyLayer3", Color.Cornsilk) print "New layer:", rs.AddLayer("MyLayer4",parent="MyLayer3") See Also: CurrentLayer DeleteLayer RenameLayer """ names = [''] if name: if not isinstance(name, str): name = str(name) names = [n for n in name.split("::") if name] last_parent_index = -1 last_parent = None for idx, name in enumerate(names): layer = Rhino.DocObjects.Layer.GetDefaultLayerProperties() if idx is 0: if parent: last_parent = __getlayer(parent, True) else: if last_parent_index <> -1: last_parent = scriptcontext.doc.Layers[last_parent_index] if last_parent: layer.ParentLayerId = last_parent.Id if name: layer.Name = name color = rhutil.coercecolor(color) if color: layer.Color = color layer.IsVisible = visible layer.IsLocked = locked last_parent_index = scriptcontext.doc.Layers.Add(layer) if last_parent_index == -1: full_path = layer.Name if last_parent: full_path = last_parent.FullPath + "::" + full_path last_parent_index = scriptcontext.doc.Layers.FindByFullPath(full_path, True) return scriptcontext.doc.Layers[last_parent_index].FullPath
def LayerColor(layer, color=None): """Returns or changes the color of a layer. Parameters: layer = name or id of an existing layer color [opt] = the new color value. If omitted, the current layer color is returned. Returns: If a color value is not specified, the current color value on success If a color value is specified, the previous color value on success Example: import rhinoscriptsyntax as rs import random from System.Drawing import Color def randomcolor(): red = int(255*random.random()) green = int(255*random.random()) blue = int(255*random.random()) return Color.FromArgb(red,green,blue) layerNames = rs.LayerNames() if layerNames: for name in layerNames: rs.LayerColor(name, randomcolor()) See Also: """ layer = __getlayer(layer, True) rc = layer.Color if color: color = rhutil.coercecolor(color) layer.Color = color if scriptcontext.doc.Layers.Modify(layer, layer.LayerIndex, False): scriptcontext.doc.Views.Redraw() return rc
def MaterialReflectiveColor(material_index, color=None): """Returns or modifies a material's reflective color. Parameters: material_index (number): zero based material index color (color, optional): the new color value Returns: color: if color is not specified, the current material reflective color color: if color is specified, the previous material reflective color None: on error Example: import rhinoscriptsyntax as rs obj = rs.GetObject("Select object") if obj: index = rs.ObjectMaterialIndex(obj) if index>-1: rs.MaterialReflectiveColor( index, (191, 191, 255) ) See Also: MaterialBump MaterialColor MaterialName MaterialShine MaterialTexture MaterialTransparency """ mat = scriptcontext.doc.Materials[material_index] if mat is None: return scriptcontext.errorhandler() rc = mat.ReflectionColor color = rhutil.coercecolor(color) if color: mat.ReflectionColor = color mat.CommitChanges() scriptcontext.doc.Views.Redraw() return rc
def LightColor(object_id, color=None): """Returns or changes the color of a light Parameters: object_id (guid): the light object's identifier color (color, optional): the light's new color Returns: color: if color is not specified, the current color color: if color is specified, the previous color Example: import rhinoscriptsyntax as rs id = rs.GetObject("Select a light", rs.filter.light) if id: rs.LightColor( id, (0,255,255) ) See Also: EnableLight IsLight IsLightEnabled LightCount LightName LightObjects """ light = __coercelight(object_id, True) rc = light.Diffuse if color: color = rhutil.coercecolor(color, True) if color!=rc: light.Diffuse = color id = rhutil.coerceguid(object_id, True) if not scriptcontext.doc.Lights.Modify(id, light): return scriptcontext.errorhandler() scriptcontext.doc.Views.Redraw() return rc
def LightColor(object_id, color=None): """Returns or changes the color of a light Parameters: object_id = the light object's identifier color[opt] = the light's new color Returns: if color is not specified, the current color if color is specified, the previous color Example: import rhinoscriptsyntax as rs id = rs.GetObject("Select a light", rs.filter.light) if id: rs.LightColor( id, (0,255,255) ) See Also: EnableLight IsLight IsLightEnabled LightCount LightName LightObjects """ light = __coercelight(object_id, True) rc = light.Diffuse if color: color = rhutil.coercecolor(color, True) if color!=rc: light.Diffuse = color id = rhutil.coerceguid(object_id, True) if not scriptcontext.doc.Lights.Modify(id, light): return scriptcontext.errorhandler() scriptcontext.doc.Views.Redraw() return rc
def AddLayer(name=None, color=None, visible=True, locked=False, parent=None): """Add a new layer to the document Parameters: name (str, optional): The name of the new layer. If omitted, Rhino automatically generates the layer name. color (color): A Red-Green-Blue color value. If omitted, the color Black is assigned. visible (bool optional): layer's visibility locked (bool, optional): layer's locked state parent (str, optional): name of the new layer's parent layer. If omitted, the new layer will not have a parent layer. Returns: str: The full name of the new layer if successful. Example: import rhinoscriptsyntax as rs from System.Drawing import Color print "New layer:", rs.AddLayer() print "New layer:", rs.AddLayer("MyLayer1") print "New layer:", rs.AddLayer("MyLayer2", Color.DarkSeaGreen) print "New layer:", rs.AddLayer("MyLayer3", Color.Cornsilk) print "New layer:", rs.AddLayer("MyLayer4",parent="MyLayer3") See Also: CurrentLayer DeleteLayer RenameLayer """ names = [''] if name: if not isinstance(name, str): name = str(name) names = [n for n in name.split("::") if name] last_parent_index = -1 last_parent = None for idx, name in enumerate(names): layer = Rhino.DocObjects.Layer.GetDefaultLayerProperties() if idx is 0: if parent: last_parent = __getlayer(parent, True) else: if last_parent_index <> -1: last_parent = scriptcontext.doc.Layers[last_parent_index] if last_parent: layer.ParentLayerId = last_parent.Id if name: layer.Name = name color = rhutil.coercecolor(color) if color: layer.Color = color layer.IsVisible = visible layer.IsLocked = locked last_parent_index = scriptcontext.doc.Layers.Add(layer) if last_parent_index == -1: full_path = layer.Name if last_parent: full_path = last_parent.FullPath + "::" + full_path last_parent_index = scriptcontext.doc.Layers.FindByFullPath(full_path, UnsetIntIndex) return scriptcontext.doc.Layers[last_parent_index].FullPath
def AddMesh(vertices, face_vertices, vertex_normals=None, texture_coordinates=None, vertex_colors=None): """Add a mesh object to the document Parameters: vertices = list of 3D points defining the vertices of the mesh face_vertices = list containing lists of 3 or 4 numbers that define the vertex indices for each face of the mesh. If the third a fourth vertex indices of a face are identical, a triangular face will be created. vertex_normals[opt] = list of 3D vectors defining the vertex normals of the mesh. Note, for every vertex, there must be a corresponding vertex normal texture_coordinates[opt] = list of 2D texture coordinates. For every vertex, there must be a corresponding texture coordinate vertex_colors[opt] = a list of color values. For every vertex, there must be a corresponding vertex color Returns: Identifier of the new object if successful None on error """ mesh = Rhino.Geometry.Mesh() for a, b, c in vertices: mesh.Vertices.Add(a, b, c) for face in face_vertices: if len(face) < 4: mesh.Faces.AddFace(face[0], face[1], face[2]) else: mesh.Faces.AddFace(face[0], face[1], face[2], face[3]) if vertex_normals: count = len(vertex_normals) normals = System.Array.CreateInstance(Rhino.Geometry.Vector3f, count) for i, normal in enumerate(vertex_normals): normals[i] = Rhino.Geometry.Vector3f(normal[0], normal[1], normal[2]) mesh.Normals.SetNormals(normals) if texture_coordinates: count = len(texture_coordinates) tcs = System.Array.CreateInstance(Rhino.Geometry.Point2f, count) for i, tc in enumerate(texture_coordinates): tcs[i] = Rhino.Geometry.Point2f(tc[0], tc[1]) mesh.TextureCoordinates.SetTextureCoordinates(tcs) if vertex_colors: count = len(vertex_colors) colors = System.Array.CreateInstance(System.Drawing.Color, count) for i, color in enumerate(vertex_colors): colors[i] = rhutil.coercecolor(color) mesh.VertexColors.SetColors(colors) rc = scriptcontext.doc.Objects.AddMesh(mesh) if rc == System.Guid.Empty: raise Exception("unable to add mesh to document") scriptcontext.doc.Views.Redraw() return rc
def GetColor(color=[0, 0, 0]): """Displays the Rhino color picker dialog allowing the user to select an RGB color Parameters: color [opt] = a default RGB value. If omitted, the default color is black Returns: RGB tuple of three numbers on success None on error """ color = rhutil.coercecolor(color) if color is None: color = System.Drawing.Color.Black rc, color = Rhino.Input.RhinoGet.GetColor("Select color", True, color) if rc == Rhino.Commands.Result.Success: return color.R, color.G, color.B return scriptcontext.errorhandler()
def EdgeAnalysisColor(color=None): """Returns or modifies edge analysis color displayed by the ShowEdges command Parameters: color [opt] = the new color Returns: if color is not specified, the current edge analysis color if color is specified, the previous edge analysis color """ rc = Rhino.ApplicationSettings.EdgeAnalysisSettings.ShowEdgeColor if color: color = rhutil.coercecolor(color, True) Rhino.ApplicationSettings.EdgeAnalysisSettings.ShowEdgeColor = color return rc
def GetColor(color=[0,0,0]): """Displays the Rhino color picker dialog allowing the user to select an RGB color Parameters: color [opt] = a default RGB value. If omitted, the default color is black Returns: RGB tuple of three numbers on success None on error """ color = rhutil.coercecolor(color) if color is None: color = System.Drawing.Color.Black rc, color = Rhino.UI.Dialogs.ShowColorDialog(color) if rc: return color.R, color.G, color.B return scriptcontext.errorhandler()
def EdgeAnalysisColor( color=None ): """Returns or modifies edge analysis color displayed by the ShowEdges command Parameters: color [opt] = the new color Returns: if color is not specified, the current edge analysis color if color is specified, the previous edge analysis color """ rc = Rhino.ApplicationSettings.EdgeAnalysisSettings.ShowEdgeColor if color: color = rhutil.coercecolor(color, True) Rhino.ApplicationSettings.EdgeAnalysisSettings.ShowEdgeColor = color return rc
def GetColor(color=[0, 0, 0]): """Display the Rhino color picker dialog allowing the user to select an RGB color Parameters: color [opt] = default RGB value. If omitted, the default color is black Returns: RGB tuple of three numbers on success None on error """ color = rhutil.coercecolor(color) if color is None: color = System.Drawing.Color.Black rc, color = Rhino.UI.Dialogs.ShowColorDialog(color) if rc: return color.R, color.G, color.B return scriptcontext.errorhandler()
def AddLayer(name=None, color=None, visible=True, locked=False, parent=None): """Add a new layer to the document Parameters: name[opt]: The name of the new layer. If omitted, Rhino automatically generates the layer name. color[opt]: A Red-Green-Blue color value or System.Drawing.Color. If omitted, the color Black is assigned. visible[opt]: layer's visibility locked[opt]: layer's locked state parent[opt]: name of the new layer's parent layer. If omitted, the new layer will not have a parent layer. Returns: The full name of the new layer if successful. """ names = [''] if name: if not isinstance(name, str): name = str(name) names = [n for n in name.split("::") if name] last_parent_index = -1 last_parent = None for idx, name in enumerate(names): layer = Rhino.DocObjects.Layer.GetDefaultLayerProperties() if idx is 0: if parent: last_parent = __getlayer(parent, True) else: if last_parent_index <> -1: last_parent = scriptcontext.doc.Layers[last_parent_index] if last_parent: layer.ParentLayerId = last_parent.Id if name: layer.Name = name color = rhutil.coercecolor(color) if color: layer.Color = color layer.IsVisible = visible layer.IsLocked = locked last_parent_index = scriptcontext.doc.Layers.Add(layer) if last_parent_index == -1: full_path = layer.Name if last_parent: full_path = last_parent.FullPath + "::" + full_path last_parent_index = scriptcontext.doc.Layers.FindByFullPath( full_path, True) return scriptcontext.doc.Layers[last_parent_index].FullPath
def ObjectsByColor(color, select=False, include_lights=False): """Returns identifiers of all objects based on color Parameters: color = color to get objects by select[opt] = select the objects include_lights[opt] = include lights in the set Returns: list of identifiers """ color = rhutil.coercecolor(color, True) rhino_objects = scriptcontext.doc.Objects.FindByDrawColor(color, include_lights) if select: for obj in rhino_objects: obj.Select(True) scriptcontext.doc.Views.Redraw() return [obj.Id for obj in rhino_objects]
def AddMesh(vertices, face_vertices, vertex_normals=None, texture_coordinates=None, vertex_colors=None): """Adds a mesh object to the document Parameters: vertices = list of 3D points defining the vertices of the mesh face_vertices = list containing lists of 3 or 4 numbers that define the vertex indices for each face of the mesh. If the third a fourth vertex indices of a face are identical, a triangular face will be created. vertex_normals[opt] = list of 3D vectors defining the vertex normals of the mesh. Note, for every vertex, there must be a corresponding vertex normal texture_coordinates[opt] = list of 2D texture coordinates. Note, for every vertex, there must be a corresponding texture coordinate vertex_colors[opt] = a list of color values. Note, for every vertex, there must be a corresponding vertex color Returns: Identifier of the new object if successful None on error """ mesh = Rhino.Geometry.Mesh() for a, b, c in vertices: mesh.Vertices.Add(a, b, c) for face in face_vertices: if len(face)<4: mesh.Faces.AddFace(face[0], face[1], face[2]) else: mesh.Faces.AddFace(face[0], face[1], face[2], face[3]) if vertex_normals: count = len(vertex_normals) normals = System.Array.CreateInstance(Rhino.Geometry.Vector3f, count) for i, normal in enumerate(vertex_normals): normals[i] = Rhino.Geometry.Vector3f(normal[0], normal[1], normal[2]) mesh.Normals.SetNormals(normals) if texture_coordinates: count = len(texture_coordinates) tcs = System.Array.CreateInstance(Rhino.Geometry.Point2f, count) for i, tc in enumerate(texture_coordinates): tcs[i] = Rhino.Geometry.Point2f(tc[0], tc[1], tc[2]) mesh.TextureCoordinates.SetTextureCoordinates(tcs) if vertex_colors: count = len(vertex_colors) colors = System.Array.CreateInstance(System.Drawing.Color, count) for i, color in enumerate(vertex_colors): colors[i] = rhutil.coercecolor(color) mesh.VertexColors.SetColors(colors) rc = scriptcontext.doc.Objects.AddMesh(mesh) if rc==System.Guid.Empty: raise Exception("unable to add mesh to document") scriptcontext.doc.Views.Redraw() return rc
def ObjectColor(object_ids, color=None): """Returns of modifies the color of an object. Object colors are represented as RGB colors. An RGB color specifies the relative intensity of red, green, and blue to cause a specific color to be displayed Parameters: object_ids = id or ids of object(s) color[opt] = the new color value. If omitted, then current object color is returned. If object_ids is a list, color is required Returns: If color value is not specified, the current color value If color value is specified, the previous color value If object_ids is a list, then the number of objects modified """ id = rhutil.coerceguid(object_ids, 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_ids ] if len(rhino_objects) == 1: rhino_object = rhino_objects[0] rhino_objects = None if color is None: #get the color if rhino_objects: raise ValueError( "color must be specified when a list of rhino objects is provided" ) return rhino_object.Attributes.DrawColor(scriptcontext.doc) color = rhutil.coercecolor(color, True) if rhino_objects is not None: for rh_obj in rhino_objects: attr = rh_obj.Attributes attr.ObjectColor = color attr.ColorSource = Rhino.DocObjects.ObjectColorSource.ColorFromObject scriptcontext.doc.Objects.ModifyAttributes(rh_obj, attr, True) return len(rhino_objects) rc = rhino_object.Attributes.DrawColor(scriptcontext.doc) attr = rhino_object.Attributes attr.ObjectColor = color attr.ColorSource = Rhino.DocObjects.ObjectColorSource.ColorFromObject scriptcontext.doc.Objects.ModifyAttributes(rhino_object, attr, True) scriptcontext.doc.Views.Redraw() return rc
def MeshVertexColors(mesh_id, colors=0): """Returns of modifies vertex colors of a mesh Parameters: mesh_id (guid): identifier of a mesh object colors 9{color, ...], optional) A list of color values. Note, for each vertex, there must be a corresponding vertex color. If the value is None, then any existing vertex colors will be removed from the mesh Returns: color: if colors is not specified, the current vertex colors color: if colors is specified, the previous vertex colors Example: import rhinoscriptsyntax as rs import random def randomcolor(): r = random.randint(0,255) g = random.randint(0,255) b = random.randint(0,255) return r,g,b obj = rs.GetObject("Select mesh", rs.filter.mesh) if obj: colors = [] for i in range(rs.MeshVertexCount(obj)): colors.append( randomcolor() ) rs.MeshVertexColors( obj, colors ) See Also: MeshHasVertexColors MeshVertexCount MeshVertices """ mesh = rhutil.coercemesh(mesh_id, True) rc = [mesh.VertexColors[i] for i in range(mesh.VertexColors.Count)] if colors == 0: return rc if colors is None: mesh.VertexColors.Clear() else: color_count = len(colors) if color_count != mesh.Vertices.Count: raise ValueError("length of colors must match vertex count") colors = [rhutil.coercecolor(c) for c in colors] mesh.VertexColors.Clear() for c in colors: mesh.VertexColors.Add(c) id = rhutil.coerceguid(mesh_id, True) scriptcontext.doc.Objects.Replace(id, mesh) scriptcontext.doc.Views.Redraw() return rc
def LayerColor(layer, color=None): """Returns or changes the color of a layer. Parameters: layer = name or id of an existing layer color [opt] = the new color value. If omitted, the current layer color is returned. Returns: If a color value is not specified, the current color value on success If a color value is specified, the previous color value on success """ layer = __getlayer(layer, True) rc = layer.Color if color: color = rhutil.coercecolor(color) layer.Color = color if scriptcontext.doc.Layers.Modify(layer, layer.LayerIndex, False): scriptcontext.doc.Views.Redraw() return rc
def MeshVertexColors(mesh_id, colors=0): """Returns of modifies vertex colors of a mesh Parameters: mesh_id = identifier of a mesh object colors[opt] = A list of color values. Note, for each vertex, there must be a corresponding vertex color. If the value is None, then any existing vertex colors will be removed from the mesh Returns: if colors is not specified, the current vertex colors if colors is specified, the previous vertex colors Example: import rhinoscriptsyntax as rs import random def randomcolor(): r = random.randint(0,255) g = random.randint(0,255) b = random.randint(0,255) return r,g,b obj = rs.GetObject("Select mesh", rs.filter.mesh) if obj: colors = [] for i in range(rs.MeshVertexCount(obj)):colors.append( randomcolor() ) rs.MeshVertexColors( obj, colors ) See Also: MeshHasVertexColors MeshVertexCount MeshVertices """ mesh = rhutil.coercemesh(mesh_id, True) rc = [mesh.VertexColors[i] for i in range(mesh.VertexColors.Count)] if colors==0: return rc if colors is None: mesh.VertexColors.Clear() else: color_count = len(colors) if color_count!=mesh.Vertices.Count: raise ValueError("length of colors must match vertex count") colors = [rhutil.coercecolor(c) for c in colors] mesh.VertexColors.Clear() for c in colors: mesh.VertexColors.Add(c) id = rhutil.coerceguid(mesh_id, True) scriptcontext.doc.Objects.Replace(id, mesh) scriptcontext.doc.Views.Redraw() return rc
def LayerPrintColor(layer, color=None): """Returns or changes the print color of a layer. Layer print colors are represented as RGB colors. Parameters: layer = name of existing layer color[opt] = new print color Returns: if color is not specified, the current layer print color if color is specified, the previous layer print color None on error """ layer = __getlayer(layer, True) rc = layer.PlotColor if color: color = rhutil.coercecolor(color) layer.PlotColor = color scriptcontext.doc.Views.Redraw() return rc
def AddPointCloud(points, colors=None): """Adds point cloud object to the document Parameters: points = list of values where every multiple of three represents a point colors[opt] = list of colors to apply to each point Returns: identifier of point cloud on success """ points = rhutil.coerce3dpointlist(points, True) if colors and len(colors)==len(points): pc = Rhino.Geometry.PointCloud() for i in range(len(points)): color = rhutil.coercecolor(colors[i],True) pc.Add(points[i],color) points = pc rc = scriptcontext.doc.Objects.AddPointCloud(points) if rc==System.Guid.Empty: raise Exception("unable to add point cloud to document") scriptcontext.doc.Views.Redraw() return rc
def MaterialReflectiveColor(material_index, color=None): """Returns or modifies a material's reflective color. Parameters: material_index = zero based material index color[opt] = the new color value Returns: if color is not specified, the current material reflective color if color is specified, the previous material reflective color None on error """ mat = scriptcontext.doc.Materials[material_index] if mat is None: return scriptcontext.errorhandler() rc = mat.ReflectionColor color = rhutil.coercecolor(color) if color: mat.ReflectionColor = color mat.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 (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 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 ObjectColor(object_ids, color=None): """Returns of modifies the color of an object. Object colors are represented as RGB colors. An RGB color specifies the relative intensity of red, green, and blue to cause a specific color to be displayed Parameters: object_ids = id or ids of object(s) color[opt] = the new color value. If omitted, then current object color is returned. If object_ids is a list, color is required Returns: If color value is not specified, the current color value If color value is specified, the previous color value If object_ids is a list, then the number of objects modified """ id = rhutil.coerceguid(object_ids, 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_ids] if len(rhino_objects)==1: rhino_object = rhino_objects[0] rhino_objects = None if color is None: #get the color if rhino_objects: raise ValueError("color must be specified when a list of rhino objects is provided") return rhino_object.Attributes.DrawColor(scriptcontext.doc) color = rhutil.coercecolor(color, True) if rhino_objects is not None: for rh_obj in rhino_objects: attr = rh_obj.Attributes attr.ObjectColor = color attr.ColorSource = Rhino.DocObjects.ObjectColorSource.ColorFromObject scriptcontext.doc.Objects.ModifyAttributes( rh_obj, attr, True) return len(rhino_objects) rc = rhino_object.Attributes.DrawColor(scriptcontext.doc) attr = rhino_object.Attributes attr.ObjectColor = color attr.ColorSource = Rhino.DocObjects.ObjectColorSource.ColorFromObject scriptcontext.doc.Objects.ModifyAttributes( rhino_object, attr, True ) scriptcontext.doc.Views.Redraw() return rc
def GetColor(color=[0,0,0]): """Display the Rhino color picker dialog allowing the user to select an RGB color Parameters: color [opt] = default RGB value. If omitted, the default color is black Returns: RGB tuple of three numbers on success None on error Example: import rhinoscriptsyntax as rs color = rs.LayerColor("Default") rgb = rs.GetColor(color) if rgb: rs.LayerColor("Default", rgb) See Also: """ color = rhutil.coercecolor(color) if color is None: color = System.Drawing.Color.Black rc, color = Rhino.UI.Dialogs.ShowColorDialog(color) if rc: return color.R, color.G, color.B return scriptcontext.errorhandler()
def LightColor(object_id, color=None): """Returns or changes the color of a light Parameters: object_id = the light object's identifier color[opt] = the light's new color Returns: if color is not specified, the current color if color is specified, the previous color """ light = __coercelight(object_id, True) rc = light.Diffuse if color: color = rhutil.coercecolor(color, True) if color != rc: light.Diffuse = color id = rhutil.coerceguid(object_id, True) if not scriptcontext.doc.Lights.Modify(id, light): return scriptcontext.errorhandler() scriptcontext.doc.Views.Redraw() return rc
def GetColor(color=[0,0,0]): """Display the Rhino color picker dialog allowing the user to select an RGB color Parameters: color (color, optional): default RGB value. If omitted, the default color is black Returns: color: RGB tuple of three numbers on success None: on error Example: import rhinoscriptsyntax as rs color = rs.LayerColor("Default") rgb = rs.GetColor(color) if rgb: rs.LayerColor("Default", rgb) See Also: """ color = rhutil.coercecolor(color) if color is None: color = System.Drawing.Color.Black rc, color = Rhino.UI.Dialogs.ShowColorDialog(color) if rc: return color.R, color.G, color.B return scriptcontext.errorhandler()
def LightColor(object_id, color=None): """Returns or changes the color of a light Parameters: object_id = the light object's identifier color[opt] = the light's new color Returns: if color is not specified, the current color if color is specified, the previous color """ light = __coercelight(object_id, True) rc = light.Diffuse if color: color = rhutil.coercecolor(color, True) if color!=rc: light.Diffuse = color id = rhutil.coerceguid(object_id, True) if not scriptcontext.doc.Lights.Modify(id, light): return scriptcontext.errorhandler() scriptcontext.doc.Views.Redraw() return rc
def EdgeAnalysisColor(color=None): """Returns or modifies edge analysis color displayed by the ShowEdges command Parameters: color (tuple (r255,g255,b255), optional): The new color for the analysis. Returns: tuple (r255,g255,b255): if color is not specified, the current edge analysis color tuple (r255,g255,b255): if color is specified, the previous edge analysis color Example: import rhinoscriptsyntax as rs oldcolor = rs.EdgeAnalysisColor() newcolor = rs.GetColor(oldcolor) if newcolor is not None: rs.EdgeAnalysisColor(newcolor) See Also: EdgeAnalysisMode """ rc = Rhino.ApplicationSettings.EdgeAnalysisSettings.ShowEdgeColor if color: color = rhutil.coercecolor(color, True) Rhino.ApplicationSettings.EdgeAnalysisSettings.ShowEdgeColor = color return rc
def EdgeAnalysisColor(color=None): """Returns or modifies edge analysis color displayed by the ShowEdges command Parameters: color [opt] = the new color Returns: if color is not specified, the current edge analysis color if color is specified, the previous edge analysis color Example: import rhinoscriptsyntax as rs oldcolor = rs.EdgeAnalysisColor() newcolor = rs.GetColor(oldcolor) if newcolor is not None: rs.EdgeAnalysisColor(newcolor) See Also: EdgeAnalysisMode """ rc = Rhino.ApplicationSettings.EdgeAnalysisSettings.ShowEdgeColor if color: color = rhutil.coercecolor(color, True) Rhino.ApplicationSettings.EdgeAnalysisSettings.ShowEdgeColor = color 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 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 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 ObjectsByColor(color, select=False, include_lights=False): """Returns identifiers of all objects based on color Parameters: color = color to get objects by select[opt] = select the objects include_lights[opt] = include lights in the set Returns: list of identifiers Example: import rhinoscriptsyntax as rs obj = rs.GetObject("Pick any object") if obj: color = rs.ObjectColor(obj) rs.ObjectsByColor(color, True) See Also: """ color = rhutil.coercecolor(color, True) rhino_objects = scriptcontext.doc.Objects.FindByDrawColor(color, include_lights) if select: for obj in rhino_objects: obj.Select(True) scriptcontext.doc.Views.Redraw() return [obj.Id for obj in rhino_objects]
def AppearanceColor(item, color=None): """Returns or modifies an application interface item's color. Parameters: item (number): Item number to either query or modify 0 = View background 1 = Major grid line 2 = Minor grid line 3 = X-Axis line 4 = Y-Axis line 5 = Selected Objects 6 = Locked Objects 7 = New layers 8 = Feedback 9 = Tracking 10 = Crosshair 11 = Text 12 = Text Background 13 = Text hover color ([r255,g255,b255], optional): The new color value in (r255,g255,b255). If omitted, the current item color is returned. Returns: tuple (r255,g255,b255): if color is not specified, the current item color. tuple (r255,g255,b255): if color is specified, the previous item color. Example: import rhinoscriptsyntax as rs oldColor = rs.AppearanceColor(0) newColor = rs.GetColor(oldColor) if newColor is not None: rs.AppearanceColor(0, newColor) rs.Redraw() See Also: GetColor """ rc = None color = rhutil.coercecolor(color) appearance = Rhino.ApplicationSettings.AppearanceSettings if item == 0: rc = appearance.ViewportBackgroundColor if color: appearance.ViewportBackgroundColor = color elif item == 1: rc = appearance.GridThickLineColor if color: appearance.GridThickLineColor = color elif item == 2: rc = appearance.GridThinLineColor if color: appearance.GridThinLineColor = color elif item == 3: rc = appearance.GridXAxisLineColor if color: appearance.GridXAxisLineColor = color elif item == 4: rc = appearance.GridYAxisLineColor if color: appearance.GridYAxisLineColor = color elif item == 5: rc = appearance.SelectedObjectColor if color: appearance.SelectedObjectColor = color elif item == 6: rc = appearance.LockedObjectColor if color: appearance.LockedObjectColor = color elif item == 7: rc = appearance.DefaultLayerColor if color: appearance.DefaultLayerColor = color elif item == 8: rc = appearance.FeedbackColor if color: appearance.FeedbackColor = color elif item == 9: rc = appearance.TrackingColor if color: appearance.TrackingColor = color elif item == 10: rc = appearance.CrosshairColor if color: appearance.CrosshairColor = color elif item == 11: rc = appearance.CommandPromptTextColor if color: appearance.CommandPromptTextColor = color elif item == 12: rc = appearance.CommandPromptBackgroundColor if color: appearance.CommandPromptBackgroundColor = color elif item == 13: rc = appearance.CommandPromptHypertextColor if color: appearance.CommandPromptHypertextColor = color if rc is None: raise ValueError("item is out of range") scriptcontext.doc.Views.Redraw() return rc
def AppearanceColor( item, color=None ): """Returns or modifies an application interface item's color. Parameters: item = Item number to either query or modify 0 = View background 1 = Major grid line 2 = Minor grid line 3 = X-Axis line 4 = Y-Axis line 5 = Selected Objects 6 = Locked Objects 7 = New layers 8 = Feedback 9 = Tracking 10 = Crosshair 11 = Text 12 = Text Background 13 = Text hover color[opt] = The new color value Returns: if color is not specified, the current item color if color is specified, the previous item color """ rc = None color = rhutil.coercecolor(color) appearance = Rhino.ApplicationSettings.AppearanceSettings grid = Rhino.ApplicationSettings.GridSettings if item==0: rc = appearance.ViewportBackgroundColor if color: appearance.ViewportBackgroundColor = color elif item==1: rc = grid.ThickLineColor if color: grid.ThickLineColor = color elif item==2: rc = grid.ThinLineColor if color: grid.ThinLineColor = color elif item==3: rc = grid.XAxisLineColor if color: grid.XAxisLineColor = color elif item==4: rc = grid.YAxisLineColor if color: grid.YAxisLineColor = color elif item==5: rc = appearance.SelectedObjectColor if color: appearance.SelectedObjectColor = color elif item==6: rc = appearance.LockedObjectColor if color: appearance.LockedObjectColor = color elif item==7: rc = appearance.DefaultLayerColor if color: appearance.DefaultLayerColor = color elif item==8: rc = appearance.FeedbackColor if color: appearance.FeedbackColor = color elif item==9: rc = appearance.TrackingColor if color: appearance.TrackingColor = color elif item==10: rc = appearance.CrosshairColor if color: appearance.CrosshairColor = color elif item==11: rc = appearance.CommandPromptTextColor if color: appearance.CommandPromptTextColor = color elif item==12: rc = appearance.CommandPromptBackgroundColor if color: appearance.CommandPromptBackgroundColor = color elif item==13: rc = appearance.CommandPromptHypertextColor if color: appearance.CommandPromptHypertextColor = color if rc is None: raise ValueError("item is out of range") return rc