示例#1
0
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
示例#2
0
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
示例#3
0
def AddMaterialToLayer(layer):
    """Add material to a layer and returns the new material's index. If the
    layer already has a material, then the layer's current material index is
    returned
    Parameters:
      layer (str): name of an existing layer.
    Returns:
      number: Material index of the layer if successful
      None: if not successful or on error
    Example:
      import rhinoscriptsyntax as rs
      layer = rs.CurrentLayer()
      index = rs.LayerMaterialIndex(layer)
      if index==-1: index = rs.AddMaterialToLayer(layer)
    See Also:
      LayerMaterialIndex
      IsMaterialDefault
    """
    layer = __getlayer(layer, True)
    if layer.RenderMaterialIndex > -1: return layer.RenderMaterialIndex
    material_index = scriptcontext.doc.Materials.Add()
    layer.RenderMaterialIndex = material_index
    if scriptcontext.doc.Layers.Modify(layer, layer.LayerIndex, True):
        scriptcontext.doc.Views.Redraw()
        return material_index
    return scriptcontext.errorhandler()
示例#4
0
def AddMaterialToLayer(layer):
    """Add material to a layer and returns the new material's index. If the
    layer already has a material, then the layer's current material index is
    returned
    Parameters:
      layer = name of an existing layer.
    Returns:
      Material index of the layer if successful
      None if not successful or on error
    Example:
      import rhinoscriptsyntax as rs
      layer = rs.CurrentLayer()
      index = rs.LayerMaterialIndex(layer)
    See Also:
      LayerMaterialIndex
      IsMaterialDefault
    """
    layer = __getlayer(layer, True)
    if layer.RenderMaterialIndex>-1: return layer.RenderMaterialIndex
    material_index = scriptcontext.doc.Materials.Add()
    layer.RenderMaterialIndex = material_index
    if scriptcontext.doc.Layers.Modify( layer, layer.LayerIndex, True):
        scriptcontext.doc.Views.Redraw()
        return material_index
    return scriptcontext.errorhandler()
示例#5
0
def ObjectsByLayer(layer_name, select=False):
    """Returns identifiers of all objects based on the objects' layer name
    Parameters:
      layer_name = name of the layer
      select [opt] = select the objects
    Returns:
      list of identifiers
    """
    layer = __getlayer(layer_name, True)
    rhino_objects = scriptcontext.doc.Objects.FindByLayer(layer)
    if not rhino_objects: return []
    if select:
        for rhobj in rhino_objects: rhobj.Select(True)
        scriptcontext.doc.Views.Redraw()
    return [rhobj.Id for rhobj in rhino_objects]
示例#6
0
def ObjectsByLayer(layer_name, select=False):
    """Returns identifiers of all objects based on the objects' layer name
    Parameters:
      layer_name = name of the layer
      select [opt] = select the objects
    Returns:
      list of identifiers
    """
    layer = __getlayer(layer_name, True)
    rhino_objects = scriptcontext.doc.Objects.FindByLayer(layer)
    if not rhino_objects: return []
    if select:
        for rhobj in rhino_objects: rhobj.Select(True)
        scriptcontext.doc.Views.Redraw()
    return [rhobj.Id for rhobj in rhino_objects]
示例#7
0
def AddMaterialToLayer(layer):
    """Add material to a layer and returns the new material's index. If the
    layer already has a material, then the layer's current material index is
    returned
    Parameters:
      layer = name of an existing layer.
    Returns:
      Material index of the layer if successful
      None if not successful or on error
    """
    layer = __getlayer(layer, True)
    if layer.RenderMaterialIndex > -1: return layer.RenderMaterialIndex
    material_index = scriptcontext.doc.Materials.Add()
    layer.RenderMaterialIndex = material_index
    if scriptcontext.doc.Layers.Modify(layer, layer.LayerIndex, True):
        scriptcontext.doc.Views.Redraw()
        return material_index
    return scriptcontext.errorhandler()
示例#8
0
def AddMaterialToLayer(layer):
    """Add material to a layer and returns the new material's index. If the
    layer already has a material, then the layer's current material index is
    returned
    Parameters:
      layer = name of an existing layer.
    Returns:
      Material index of the layer if successful
      None if not successful or on error
    """
    layer = __getlayer(layer, True)
    if layer.RenderMaterialIndex>-1: return layer.RenderMaterialIndex
    material_index = scriptcontext.doc.Materials.AddMaterial()
    layer.RenderMaterialIndex = material_index
    if scriptcontext.doc.Layers.Modify( layer, layer.LayerIndex, True):
        scriptcontext.doc.Views.Redraw()
        return material_index
    return scriptcontext.errorhandler()
示例#9
0
def ObjectsByLayer(layer_name, select=False):
    """Returns identifiers of all objects based on the objects' layer name
    Parameters:
      layer_name = name of the layer
      select [opt] = select the objects
    Returns:
      list of identifiers
    Example:
      import rhinoscriptsyntax as rs
      obj = rs.GetObject("Pick any object")
      if obj:
      layer = rs.ObjectLayer(obj)
      rs.ObjectsByLayer(layer, True)
    See Also:
      
    """
    layer = __getlayer(layer_name, True)
    rhino_objects = scriptcontext.doc.Objects.FindByLayer(layer)
    if not rhino_objects: return []
    if select:
        for rhobj in rhino_objects: rhobj.Select(True)
        scriptcontext.doc.Views.Redraw()
    return [rhobj.Id for rhobj in rhino_objects]