• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python utility.coercecolor函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中utility.coercecolor函数的典型用法代码示例。如果您正苦于以下问题:Python coercecolor函数的具体用法?Python coercecolor怎么用?Python coercecolor使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了coercecolor函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)
开发者ID:acormier,项目名称:rhinoscriptsyntax,代码行数:28,代码来源:object.py


示例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
开发者ID:nhfoley,项目名称:rhinopython,代码行数:27,代码来源:mesh.py


示例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
开发者ID:howllone,项目名称:rhinopython,代码行数:26,代码来源:geometry.py


示例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
开发者ID:itrowa,项目名称:rhinoscriptsyntax,代码行数:29,代码来源:layer.py


示例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
开发者ID:itrowa,项目名称:rhinoscriptsyntax,代码行数:33,代码来源:layer.py


示例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
开发者ID:itrowa,项目名称:rhinoscriptsyntax,代码行数:60,代码来源:layer.py


示例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
开发者ID:itrowa,项目名称:rhinoscriptsyntax,代码行数:33,代码来源:material.py


示例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
开发者ID:itrowa,项目名称:rhinoscriptsyntax,代码行数:28,代码来源:document.py


示例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
开发者ID:itrowa,项目名称:rhinoscriptsyntax,代码行数:31,代码来源:light.py


示例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
开发者ID:hstehling,项目名称:rhinopython,代码行数:25,代码来源:document.py


示例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
开发者ID:jehc,项目名称:rhinopython,代码行数:27,代码来源:layer.py


示例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
开发者ID:itrowa,项目名称:rhinoscriptsyntax,代码行数:27,代码来源:geometry.py


示例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
开发者ID:Agnestan,项目名称:rhinopython,代码行数:13,代码来源:application.py


示例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()
开发者ID:nhfoley,项目名称:rhinopython,代码行数:13,代码来源:userinterface.py


示例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]
开发者ID:MartinMGermany,项目名称:rhinopython,代码行数:15,代码来源:selection.py


示例16: AddMesh

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
开发者ID:nhfoley,项目名称:rhinopython,代码行数:47,代码来源:mesh.py


示例17: MeshVertexColors

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
开发者ID:itrowa,项目名称:rhinoscriptsyntax,代码行数:46,代码来源:mesh.py


示例18: 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
    """
    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
开发者ID:jehc,项目名称:rhinopython,代码行数:17,代码来源:layer.py


示例19: 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
    """
    layer = __getlayer(layer, True)
    rc = layer.PlotColor
    if color:
        color = rhutil.coercecolor(color)
        layer.PlotColor = color
        scriptcontext.doc.Views.Redraw()
    return rc
开发者ID:acormier,项目名称:rhinoscriptsyntax,代码行数:18,代码来源:layer.py


示例20: 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
    """
    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
开发者ID:Agnestan,项目名称:rhinopython,代码行数:19,代码来源:material.py



注:本文中的utility.coercecolor函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python utility.coercegeometry函数代码示例发布时间:2022-05-26
下一篇:
Python utility.coerce3dvector函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap