本文整理汇总了Python中utility.coercecolor函数的典型用法代码示例。如果您正苦于以下问题:Python coercecolor函数的具体用法?Python coercecolor怎么用?Python coercecolor使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了coercecolor函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ObjectPrintColor
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)
示例2: MeshVertexColors
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
示例3: PointCloudPointColors
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
示例4: LayerPrintColor
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
示例5: LayerColor
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
示例6: AddLayer
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
示例7: MaterialReflectiveColor
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
示例8: RenderColor
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
示例9: LightColor
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
示例10: RenderColor
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
示例11: AddLayer
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
示例12: AddPointCloud
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
示例13: EdgeAnalysisColor
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
示例14: GetColor
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()
示例15: ObjectsByColor
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]