Пример #1
0
def CurrentDetail(layout, detail=None, return_name=True):
    """Returns or changes the current detail view in a page layout view
    Parameters:
      layout = title or identifier of an existing page layout view
      detail[opt] = title or identifier the the detail view to set
      return_name[opt] = return title if True, else return identifier
    Returns:
      if detail is not specified, the title or id of the current detail view
      if detail is specified, the title or id of the previous detail view
      None on error
    """
    layout_id = rhutil.coerceguid(layout)
    page = None
    if layout_id is None: page = scriptcontext.doc.Views.Find(layout, False)
    else: page = scriptcontext.doc.Views.Find(layout_id)
    if page is None: return scriptcontext.errorhandler()
    rc = None
    active_viewport = page.ActiveViewport
    if return_name: rc = active_viewport.Name
    else: rc = active_viewport.Id
    if detail:
        id = rhutil.coerceguid(detail)
        if( (id and id==page.MainViewport.Id) or (id is None and detail==page.MainViewport.Name) ):
            page.SetPageAsActive()
        else:
            if id: page.SetActiveDetail(id)
            else: page.SetActiveDetail(detail, False)
    scriptcontext.doc.Views.Redraw()
    return rc
Пример #2
0
def MeshBooleanSplit(input0, input1, delete_input=True):
    """Performs a boolean split operation on two sets of input meshes
    Parameters:
      input0, input1 = identifiers of meshes
      delete_input[opt] = delete the input meshes
    Returns:
      list of identifiers of new meshes on success
      None on error
    """
    id = rhutil.coerceguid(input0)
    if id: input0 = [id]
    id = rhutil.coerceguid(input1)
    if id: input1 = [id]
    meshes0 = [rhutil.coercemesh(id, True) for id in input0]
    meshes1 = [rhutil.coercemesh(id, True) for id in input1]
    if not meshes0 or not meshes1: raise ValueError("no meshes to work with")
    newmeshes = Rhino.Geometry.Mesh.CreateBooleanSplit(meshes0, meshes1)
    rc = []
    for mesh in newmeshes:
        id = scriptcontext.doc.Objects.AddMesh(mesh)
        if id!=System.Guid.Empty: rc.append(id)
    if rc and delete_input:
        input = input0 + input1
        for id in input:
            id = rhutil.coerceguid(id, True)
            scriptcontext.doc.Objects.Delete(id, True)
    scriptcontext.doc.Views.Redraw()
    return rc
Пример #3
0
def IsDetail(layout, detail):
    """Verifies that a detail view exists on a page layout view
    Parameters:
      layout: title or identifier of an existing page layout
      detail: title or identifier of an existing detail view
    Returns:
      True if detail is a detail view
      False if detail is not a detail view
      None on error
    """
    layout_id = rhutil.coerceguid(layout)
    views = scriptcontext.doc.Views.GetViewList(False, True)
    found_layout = None
    for view in views:
        if layout_id:
            if view.MainViewport.Id==layout_id:
                found_layout = view
                break
        elif view.MainViewport.Name==layout:
            found_layout = view
            break
    # if we couldn't find a layout, this is an error
    if found_layout is None: return scriptcontext.errorhandler()
    detail_id = rhutil.coerceguid(detail)
    details = view.GetDetailViews()
    if not details: return False
    for detail_view in details:
        if detail_id:
            if detail_view.Id==detail_id: return True
        else:
            if detail_view.Name==detail: return True
    return False
Пример #4
0
def MatchMaterial(source, destination):
    """Copies the material definition from one material to one or more objects
    Parameters:
      source = source material index -or- identifier of the source object.
        The object must have a material assigned
      destination = indentifier(s) of the destination object(s)
    Returns:
      number of objects that were modified if successful
      None if not successful or on error
    """
    source_id = rhutil.coerceguid(source)
    source_mat = None
    if source_id:
        rhobj = rhutil.coercerhinoobject(source_id, True, True)
        source = rhobj.Attributes.MaterialIndex
    mat = scriptcontext.doc.Materials[source]
    if not mat: return scriptcontext.errorhandler()
    destination_id = rhutil.coerceguid(destination)
    if destination_id: destination = [destination]
    ids = [rhutil.coerceguid(d) for d in destination]
    rc = 0
    for id in ids:
        rhobj = scriptcontext.doc.Objects.Find(id)
        if rhobj:
            rhobj.Attributes.MaterialIndex = source
            rhobj.Attributes.MaterialSource = Rhino.DocObjects.ObjectMaterialSource.MaterialFromObject
            rhobj.CommitChanges()
            rc += 1
    if rc>0: scriptcontext.doc.Views.Redraw()
    return rc
Пример #5
0
def HideObjects(object_ids):
    """Hides one or more objects
    Parameters:
      object_ids: identifiers of objects to hide
    Returns:
      Number of objects hidden
    """
    id = rhutil.coerceguid(object_ids, False)
    if id: object_ids = [id]
    rc = 0
    for id in object_ids:
        id = rhutil.coerceguid(id, True)
        if scriptcontext.doc.Objects.Hide(id, False): rc += 1
    if rc: scriptcontext.doc.Views.Redraw()
    return rc
Пример #6
0
def DeleteObjects(object_ids):
    """Deletes one or more objects from the document
    Parameters:
      object_ids: identifiers of objects to delete
    Returns:
      Number of objects deleted
    """
    rc = 0
    id = rhutil.coerceguid(object_ids, False)
    if id: object_ids = [id]
    for id in object_ids:
        id = rhutil.coerceguid(id, True)
        if scriptcontext.doc.Objects.Delete(id, True): rc+=1
    if rc: scriptcontext.doc.Views.Redraw()
    return rc
Пример #7
0
def MeshArea(object_ids):
    """Returns the approximate area of one or more mesh objects
    Parameters:
      object_ids = identifiers of one or more mesh objects
    Returns:
      a list containing 3 numbers if successful where
        element[0] = number of meshes used in calculation
        element[1] = total area of all meshes
        element[2] = the error estimate
      None if not successful
    """
    id = rhutil.coerceguid(object_ids)
    if id: object_ids = [object_ids]
    meshes_used = 0
    total_area = 0.0
    error_estimate = 0.0
    for id in object_ids:
        mesh = rhutil.coercemesh(id, True)
        if mesh:
            mp = Rhino.Geometry.AreaMassProperties.Compute(mesh)
            if mp:
                meshes_used += 1
                total_area += mp.Area
                error_estimate += mp.AreaError
    if meshes_used==0: return scriptcontext.errorhandler()
    return meshes_used, total_area, error_estimate
Пример #8
0
def ExplodeMeshes(mesh_ids, delete=False):
    """Explodes a mesh object, or mesh objects int submeshes. A submesh is a
    collection of mesh faces that are contained within a closed loop of
    unwelded mesh edges. Unwelded mesh edges are where the mesh faces that
    share the edge have unique mesh vertices (not mesh topology vertices)
    at both ends of the edge
    Parameters:
      mesh_ids = list of mesh identifiers
      delete[opt] = delete the input meshes
    Returns:
      List of identifiers
    """
    id = rhutil.coerceguid(mesh_ids)
    if id: mesh_ids = [mesh_ids]
    rc = []
    for mesh_id in mesh_ids:
        mesh = rhutil.coercemesh(mesh_id, True)
        if mesh:
            submeshes = mesh.ExplodeAtUnweldedEdges()
            if submeshes:
                for submesh in submeshes:
                    id = scriptcontext.doc.Objects.AddMesh(submesh)
                    if id!=System.Guid.Empty: rc.append(id)
    if rc: scriptcontext.doc.Views.Redraw()
    return rc
Пример #9
0
def AddHatches(curve_ids, hatch_pattern=None, scale=1.0, rotation=0.0):
    """Creates one or more new hatch objects a list of closed planar curves
    Parameters:
      curve_ids = identifiers of the closed planar curves that defines the
          boundary of the hatch objects
      hatch_pattern[opt] = name of the hatch pattern to be used by the hatch
          object. If omitted, the current hatch pattern will be used
      scale[opt] = hatch pattern scale factor
      rotation[opt] = hatch pattern rotation angle in degrees.
    Returns:
      identifiers of the newly created hatch on success
      None on error
    """
    id = rhutil.coerceguid(curve_ids, False)
    if id: curve_ids = [id]
    index = scriptcontext.doc.HatchPatterns.CurrentHatchPatternIndex
    if hatch_pattern and hatch_pattern!=index:
        if isinstance(hatch_pattern, int):
            index = hatch_pattern
        else:
            index = scriptcontext.doc.HatchPatterns.Find(hatch_pattern, True)
        if index<0: return scriptcontext.errorhandler()
    curves = [rhutil.coercecurve(id, -1, True) for id in curve_ids]
    rotation = Rhino.RhinoMath.ToRadians(rotation)
    hatches = Rhino.Geometry.Hatch.Create(curves, index, rotation, scale)
    if not hatches: return scriptcontext.errorhandler()
    ids = []
    for hatch in hatches:
        id = scriptcontext.doc.Objects.AddHatch(hatch)
        if id==System.Guid.Empty: continue
        ids.append(id)
    if not ids: return scriptcontext.errorhandler()
    scriptcontext.doc.Views.Redraw()
    return ids
Пример #10
0
def MeshBooleanUnion(mesh_ids, delete_input=True):
    """Performs boolean union operation on a set of input meshes
    Parameters:
      mesh_ids = identifiers of meshes
      delete_input[opt] = delete the input meshes
    Returns:
      list of identifiers of new meshes
    Example:
      import rhinoscriptsyntax as rs
      input = rs.GetObjects("Select meshes to union", rs.filter.mesh)
      if input: rs.MeshBooleanUnion(input)
    See Also:
      MeshBooleanDifference
      MeshBooleanIntersection
      MeshBooleanSplit
    """
    if len(mesh_ids)<2: raise ValueError("mesh_ids must contain at least 2 meshes")
    meshes = [rhutil.coercemesh(id, True) for id in mesh_ids]
    newmeshes = Rhino.Geometry.Mesh.CreateBooleanUnion(meshes)
    rc = []
    for mesh in newmeshes:
        id = scriptcontext.doc.Objects.AddMesh(mesh)
        if id!=System.Guid.Empty: rc.append(id)
    if rc and delete_input:
        for id in mesh_ids:
            id = rhutil.coerceguid(id, True)
            scriptcontext.doc.Objects.Delete(id, True)
    scriptcontext.doc.Views.Redraw()
    return rc
Пример #11
0
def TextObjectStyle(object_id, style=None):
    """Returns or modifies the font style of a text object
    Parameters:
      object_id = the identifier of a text object
      style [opt] = the font style. Can be any of the following flags
         0 = Normal
         1 = Bold
         2 = Italic
    Returns:
      if style is not specified, the current font style
      if style is specified, the previous font style
      None if not successful, or on Error
    """
    annotation = rhutil.coercegeometry(object_id, True)
    if not isinstance(annotation, Rhino.Geometry.TextEntity):
        return scriptcontext.errorhandler()
    fontdata = scriptcontext.doc.Fonts[annotation.FontIndex]
    if fontdata is None: return scriptcontext.errorhandler()
    rc = 0
    if fontdata.Bold: rc += 1
    if fontdata.Italic: rc += 2
    if style is not None and style!=rc:
        index = scriptcontext.doc.Fonts.FindOrCreate( fontdata.FaceName, (style&1)==1, (style&2)==2 )
        annotation.FontIndex = index
        id = rhutil.coerceguid(object_id, True)
        scriptcontext.doc.Objects.Replace(id, annotation)
        scriptcontext.doc.Views.Redraw()
    return rc
Пример #12
0
def MeshVolume(object_ids):
    """Returns the approximate volume of one or more closed meshes
    Parameters:
      object_ids = identifiers of one or more mesh objects
    Returns:
      tuple containing 3 numbers if successful where
        element[0] = number of meshes used in volume calculation
        element[1] = total volume of all meshes
        element[2] = the error estimate
      None if not successful
    Example:
      import rhinoscriptsyntax as rs
      obj = rs.GetObject("Select mesh", rs.filter.mesh )
      if obj and rs.IsMeshClosed(obj):
      volume = rs.MeshVolume(obj)
      if volume: print "Mesh volume:", volume[1]
    See Also:
      IsMeshClosed
      MeshArea
    """
    id = rhutil.coerceguid(object_ids)
    if id: object_ids = [id]
    meshes_used = 0
    total_volume = 0.0
    error_estimate = 0.0
    for id in object_ids:
        mesh = rhutil.coercemesh(id, True)
        mp = Rhino.Geometry.VolumeMassProperties.Compute(mesh)
        if mp:
            meshes_used += 1
            total_volume += mp.Volume
            error_estimate += mp.VolumeError
    if meshes_used==0: return scriptcontext.errorhandler()
    return meshes_used, total_volume, error_estimate
Пример #13
0
def RenameView(old_title, new_title):
    """Changes the title of the specified view
    Parameters:
      old_title: the title or identifier of the view to rename
      new_title: the new title of the view
    Returns:
      the view's previous title if successful
      None on error
    """
    if not old_title or not new_title: return scriptcontext.errorhandler()
    old_id = rhutil.coerceguid(old_title)
    foundview = None
    allviews = scriptcontext.doc.Views.GetViewList(True, True)
    for view in allviews:
        if old_id:
            if view.MainViewport.Id==old_id:
                foundview = view
                break
        elif view.MainViewport.Name==old_title:
            foundview = view
            break
    if foundview is None: return scriptcontext.errorhandler()
    old_title = foundview.MainViewport.Name
    foundview.MainViewport.Name = new_title
    return old_title
Пример #14
0
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
Пример #15
0
def JoinMeshes(object_ids, delete_input=False):
    """Joins two or or more mesh objects together
    Parameters:
      object_ids = identifiers of two or more mesh objects
      delete_input[opt] = delete input after joining
    Returns:
      identifier of newly created mesh on success
    Example:
      import rhinoscriptsyntax as rs
      objs = rs.GetObjects("Select meshes to join", rs.filter.mesh)
      if objs and len(objs)>1: rs.JoinMeshes(objs, True)
    See Also:
      JoinCurves
      JoinSurfaces
    """
    meshes = [rhutil.coercemesh(id,True) for id in object_ids]
    joined_mesh = Rhino.Geometry.Mesh()
    for mesh in meshes: joined_mesh.Append(mesh)
    rc = scriptcontext.doc.Objects.AddMesh(joined_mesh)
    if delete_input:
        for id in object_ids:
            guid = rhutil.coerceguid(id)
            scriptcontext.doc.Objects.Delete(guid,True)
    scriptcontext.doc.Views.Redraw()
    return rc
Пример #16
0
def MeshVolume(object_ids):
    """
    Returns the approximate volume of one or more closed mesh objects
    Parameters:
      object_ids = identifiers of one or more mesh objects
    Returns:
      a tuple containing 3 numbers if successful where
        element[0] = number of meshes used in volume calculation
        element[1] = total volume of all meshes
        element[2] = the error estimate
      None if not successful
    """
    id = rhutil.coerceguid(object_ids)
    if id: object_ids = [id]
    meshes_used = 0
    total_volume = 0.0
    error_estimate = 0.0
    for id in object_ids:
        mesh = rhutil.coercemesh(id, True)
        mp = Rhino.Geometry.VolumeMassProperties.Compute(mesh)
        if mp:
            meshes_used += 1
            total_volume += mp.Volume
            error_estimate += mp.VolumeError
    if meshes_used==0: return scriptcontext.errorhandler()
    return meshes_used, total_volume, error_estimate
Пример #17
0
def MeshArea(object_ids):
    """Returns approximate area of one or more mesh objects
    Parameters:
      object_ids = identifiers of one or more mesh objects
    Returns:
      list containing 3 numbers if successful where
        element[0] = number of meshes used in calculation
        element[1] = total area of all meshes
        element[2] = the error estimate
      None if not successful
    Example:
      import rhinoscriptsyntax as rs
      obj = rs.GetObject("Select mesh", rs.filter.mesh )
      if obj:
      area_rc = rs.MeshArea(obj)
      if area_rc: print "Mesh area:", area_rc[1]
    See Also:
      MeshVolume
    """
    id = rhutil.coerceguid(object_ids)
    if id: object_ids = [object_ids]
    meshes_used = 0
    total_area = 0.0
    error_estimate = 0.0
    for id in object_ids:
        mesh = rhutil.coercemesh(id, True)
        if mesh:
            mp = Rhino.Geometry.AreaMassProperties.Compute(mesh)
            if mp:
                meshes_used += 1
                total_area += mp.Area
                error_estimate += mp.AreaError
    if meshes_used==0: return scriptcontext.errorhandler()
    return meshes_used, total_area, error_estimate
Пример #18
0
def ObjectLinetypeSource(object_ids, source=None):
    """Returns of modifies the linetype source of an object
    Parameters:
      object_ids = identifiers of object(s)
      source[opt] = new linetype source. If omitted, the current source is returned.
        If object_ids is a list of identifiers, this parameter is required
          0 = By Layer
          1 = By Object
          3 = By Parent
    Returns:
      If a source is not specified, the object's current linetype source
      If source is specified, the object's previous linetype source
      If object_ids is a list, the number of objects modified
    """
    id = rhutil.coerceguid(object_ids, False)
    if id:
        rhino_object = rhutil.coercerhinoobject(id, True, True)
        oldsource = rhino_object.Attributes.LinetypeSource
        if source is not None:
            source = System.Enum.ToObject(Rhino.DocObjects.ObjectLinetypeSource, source)
            rhino_object.Attributes.LinetypeSource = source
            rhino_object.CommitChanges()
            scriptcontext.doc.Views.Redraw()
        return int(oldsource)
    source = System.Enum.ToObject(Rhino.DocObjects.ObjectLinetypeSource, source)
    for id in object_ids:
        rhino_object = rhutil.coercerhinoobject(id, True, True)
        rhino_object.Attributes.LinetypeSource = source
        rhino_object.CommitChanges()
    scriptcontext.doc.Views.Redraw()
    return len(object_ids)
Пример #19
0
def AddDetail(layout_id, corner1, corner2, title=None, projection=1):
    """Add new detail view to an existing layout view
    Parameters:
      layout_id = identifier of an existing layout
      corner1, corner2 = 2d corners of the detail in the layout's unit system
      title[opt] = title of the new detail
      projection[opt] = type of initial view projection for the detail
          1 = parallel top view
          2 = parallel bottom view
          3 = parallel left view
          4 = parallel right view
          5 = parallel front view
          6 = parallel back view
          7 = perspective view
    Returns:
      identifier of the newly created detial on success
      None on error
    """
    layout_id = rhutil.coerceguid(layout_id, True)
    corner1 = rhutil.coerce2dpoint(corner1, True)
    corner2 = rhutil.coerce2dpoint(corner2, True)
    if projection<1 or projection>7: raise ValueError("projection must be a value between 1-7")
    layout = scriptcontext.doc.Views.Find(layout_id)
    if not layout: raise ValueError("no layout found for given layout_id")
    projection = System.Enum.ToObject(Rhino.Display.DefinedViewportProjection, projection)
    detail = layout.AddDetailView(title, corner1, corner2, projection)
    if not detail: return scriptcontext.errorhandler()
    scriptcontext.doc.Views.Redraw()
    return detail.Id
Пример #20
0
def ObjectLinetype(object_ids, linetype=None):
    """Returns of modifies the linetype of an object
    Parameters:
      object_ids = identifiers of object(s)
      linetype[opt] = name of an existing linetype. If omitted, the current
        linetype is returned. If object_ids is a list of identifiers, this parameter
        is required
    Returns:
      If a linetype is not specified, the object's current linetype
      If linetype is specified, the object's previous linetype
      If object_ids is a list, the number of objects modified
    """
    id = rhutil.coerceguid(object_ids, False)
    if id:
        rhino_object = rhutil.coercerhinoobject(id, True, True)
        oldindex = scriptcontext.doc.Linetypes.LinetypeIndexForObject(rhino_object)
        if linetype:
            newindex = scriptcontext.doc.Linetypes.Find(linetype, True)
            rhino_object.Attributes.LinetypeSource = Rhino.DocObjects.ObjectLinetypeSource.LinetypeFromObject
            rhino_object.Attributes.LinetypeIndex = newindex
            rhino_object.CommitChanges()
            scriptcontext.doc.Views.Redraw()
        return scriptcontext.doc.Linetypes[oldindex].Name

    newindex = scriptcontext.doc.Linetypes.Find(linetype, True)
    if newindex<0: raise Exception("%s does not exist in LineTypes table"%linetype)
    for id in object_ids:
        rhino_object = rhutil.coercerhinoobject(id, True, True)
        rhino_object.Attributes.LinetypeSource = Rhino.DocObjects.ObjectLinetypeSource.LinetypeFromObject
        rhino_object.Attributes.LinetypeIndex = newindex
        rhino_object.CommitChanges()
    scriptcontext.doc.Views.Redraw()
    return len(object_ids)
Пример #21
0
def __getlayer(name_or_id, raise_if_missing):
    if not name_or_id: raise TypeError("Parameter must be a string or Guid")
    id = rhutil.coerceguid(name_or_id)
    if id: name_or_id = id
    layer = scriptcontext.doc.Layers.Find(name_or_id, True)
    if layer>=0: return scriptcontext.doc.Layers[layer]
    if raise_if_missing: raise ValueError("%s does not exist in LayerTable" % name_or_id)
Пример #22
0
def ObjectColorSource(object_ids, source=None):
    """Returns of modifies the color source of an object.
    Paramters:
      object_ids = single identifier of list of identifiers
      source[opt] = new color source
          0 = color from layer
          1 = color from object
          2 = color from material
          3 = color from parent
    Returns:
      if color source is not specified, the current color source
      is color source is specified, the previous color source
      if color_ids is a list, then the number of objects modifief
    """
    id = rhutil.coerceguid(object_ids, False)
    if id:
        rhobj = rhutil.coercerhinoobject(id, True, True)
        rc = int(rhobj.Attributes.ColorSource)
        if source is not None:
            rhobj.Attributes.ColorSource = System.Enum.ToObject(Rhino.DocObjects.ObjectColorSource, source)
            rhobj.CommitChanges()
            scriptcontext.doc.Views.Redraw()
        return rc
    else:
        rc = 0
        source = System.Enum.ToObject(Rhino.DocObjects.ObjectColorSource, source)
        for id in object_ids:
            rhobj = rhutil.coercerhinoobject(id, True, True)
            rhobj.Attributes.ColorSource = source
            rhobj.CommitChanges()
            rc += 1
        if rc: scriptcontext.doc.Views.Redraw()
        return rc
Пример #23
0
def ShowObjects(object_ids):
    """Shows one or more objects. Hidden objects are not visible, cannot be
    snapped to and cannot be selected
    Parameters:
      object_ids: list of Strings or Guids representing ids of objects to show
    Returns:
      Number of objects shown
    """
    id = rhutil.coerceguid(object_ids, False)
    if id: object_ids = [id]
    rc = 0
    for id in object_ids:
        id = rhutil.coerceguid(id, True)
        if scriptcontext.doc.Objects.Show(id, False): rc += 1
    if rc: scriptcontext.doc.Views.Redraw()
    return rc
Пример #24
0
def LockObjects(object_ids):
    """Locks one or more objects. Locked objects are visible, and they can be
    snapped to. But, they cannot be selected.
    Parameters:
      object_ids: list of Strings or Guids. The identifiers of objects
    Returns:
      number of objects locked
    """
    id = rhutil.coerceguid(object_ids, False)
    if id: object_ids = [id]
    rc = 0
    for id in object_ids:
        id = rhutil.coerceguid(id, True)
        if scriptcontext.doc.Objects.Lock(id, False): rc += 1
    if rc: scriptcontext.doc.Views.Redraw()
    return rc
Пример #25
0
def ObjectMaterialSource(object_ids, source=None):
    """Returns or modifies the rendering material source of an object.
    Parameters:
      object_ids = one or more object identifiers
      source [opt] = The new rendering material source. If omitted and a single
        object is provided in object_ids, then the current material source is
        returned. This parameter is required if multiple objects are passed in
        object_ids
        0 = Material from layer
        1 = Material from object
        3 = Material from parent
    Returns:
      If source is not specified, the current rendering material source
      If source is specified, the previous rendering material source
      If object_ids refers to multiple objects, the number of objects modified
    """
    id = rhutil.coerceguid(object_ids, False)
    if id: # working with single object
        rhino_object = rhutil.coercerhinoobject(id, True, True)
        rc = int(rhino_object.Attributes.MaterialSource)
        if source is not None:
            rhino_object.Attributes.MaterialSource = System.Enum.ToObject(Rhino.DocObjects.ObjectMaterialSource, source)
            rhino_object.CommitChanges()
        return rc
    # else working with multiple objects
    if source is None: raise Exception("source is required when object_ids represents multiple objects")
    source = System.Enum.ToObject(Rhino.DocObjects.ObjectMaterialSource, source)
    for id in object_ids:
        rhino_object = rhutil.coercerhinoobject(id, True, True)
        rhino_object.Attributes.MaterialSource = source
        rhino_object.CommitChanges()
    return len(object_ids)
Пример #26
0
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)
Пример #27
0
def ObjectName(object_id, name=None):
    """Returns or modifies the name of an object
    Parameters:
      object_id = id or ids of object(s)
      name[opt] = the new object name. If omitted, the current name is returned
    Returns:
      If name is not specified, the current object name
      If name is specified, the previous object name
      If object_id is a list, the number of objects changed
    """
    id = rhutil.coerceguid(object_id, False)
    rhino_object = None
    rhino_objects = None
    if id:
        rhino_object = rhutil.coercerhinoobject(id, True, True)
    else:
        rhino_objects = [rhutil.coercerhinoobject(id, True, True) for id in object_id]
        if not rhino_objects: return 0
        if len(rhino_objects)==1:
            rhino_object = rhino_objects[0]
            rhino_objects = None
    if name is None: #get the name
        if rhino_objects: raise Exception("name required when object_id represents multiple objects")
        return rhino_object.Name
    if rhino_objects:
        for rh_obj in rhino_objects:
            attr = rh_obj.Attributes
            attr.Name = name
            scriptcontext.doc.Objects.ModifyAttributes(rh_obj, attr, True)
        return len(rhino_objects)
    rc = rhino_object.Name
    if not type(name) is str: name = str(name)
    rhino_object.Attributes.Name = name
    rhino_object.CommitChanges()
    return rc
Пример #28
0
def GetMeshVertices(object_id, message="", min_count=1, max_count=0):
    """Prompts the user to pick one or more mesh vertices
    Parameters:
      object_id = the mesh object's identifier
      message[opt] = a prompt of message
      min_count[opt] = the minimum number of vertices to select
      max_count[opt] = the maximum number of vertices to select. If 0, the user must
        press enter to finish selection. If -1, selection stops as soon as there
        are at least min_count vertices selected.
    Returns:
      list of mesh vertex indices on success
      None on error
    """
    scriptcontext.doc.Objects.UnselectAll()
    scriptcontext.doc.Views.Redraw()
    object_id = rhutil.coerceguid(object_id, True)
    class CustomGetObject(Rhino.Input.Custom.GetObject):
        def CustomGeometryFilter( self, rhino_object, geometry, component_index ):
            return object_id == rhino_object.Id
    go = CustomGetObject()
    if message: go.SetCommandPrompt(message)
    go.GeometryFilter = Rhino.DocObjects.ObjectType.MeshVertex
    go.AcceptNothing(True)
    if go.GetMultiple(min_count,max_count)!=Rhino.Input.GetResult.Object: return None
    objrefs = go.Objects()
    rc = [item.GeometryComponentIndex.Index for item in objrefs]
    go.Dispose()
    return rc
Пример #29
0
def ObjectPrintWidth(object_ids, width=None):
    """Returns or modifies the print width of an object
    Parameters:
      object_ids = identifiers of object(s)
      width[opt] = new print width value in millimeters, where width=0 means use
        the default width, and width<0 means do not print (visible for screen display,
        but does not show on print). If omitted, the current width is returned.
    Returns:
      If width is not specified, the object's current print width
      If width is specified, the object's previous print width
      If object_ids is a list or tuple, the number of objects modified
    """
    id = rhutil.coerceguid(object_ids, False)
    if id:
        rhino_object = rhutil.coercerhinoobject(id, True, True)
        rc = rhino_object.Attributes.PlotWeight
        if width is not None:
            rhino_object.Attributes.PlotWeightSource = Rhino.DocObjects.ObjectPlotWeightSource.PlotWeightFromObject
            rhino_object.Attributes.PlotWeight = width
            rhino_object.CommitChanges()
            scriptcontext.doc.Views.Redraw()
        return rc
    for id in object_ids:
        rhino_object = rhutil.coercerhinoobject(id, True, True)
        rhino_object.Attributes.PlotWeightSource = Rhino.DocObjects.ObjectPlotWeightSource.PlotWeightFromObject
        rhino_object.Attributes.PlotWeight = width
        rhino_object.CommitChanges()
    scriptcontext.doc.Views.Redraw()
    return len(object_ids)
Пример #30
0
def ObjectPrintWidthSource(object_ids, source=None):
    """Returns or modifies the print width source of an object
    Parameters:
      object_ids = identifiers of object(s)
      source[opt] = new print width source
        0 = print width by layer
        1 = print width by object
        3 = print width by parent
    Returns:
      If source is not specified, the object's current print width source
      If source is specified, the object's previous print width source
      If object_ids is a list or tuple, the number of objects modified
    """
    id = rhutil.coerceguid(object_ids, False)
    if id:
        rhino_object = rhutil.coercerhinoobject(id, True, True)
        rc = int(rhino_object.Attributes.PlotWeightSource)
        if source is not None:
            rhino_object.Attributes.PlotWeightSource = System.Enum.ToObject(Rhino.DocObjects.ObjectPlotWeightSource, source)
            rhino_object.CommitChanges()
            scriptcontext.doc.Views.Redraw()
        return rc
    for id in object_ids:
        rhino_object = rhutil.coercerhinoobject(id, True, True)
        rhino_object.Attributes.PlotWeightSource = System.Enum.ToObject(Rhino.DocObjects.ObjectPlotWeightSource, source)
        rhino_object.CommitChanges()
    scriptcontext.doc.Views.Redraw()
    return len(object_ids)
Пример #31
0
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
Пример #32
0
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
Пример #33
0
def TextObjectFont(object_id, font=None):
    """Returns of modifies the font used by a text object
    Parameters:
      object_id (guid): the identifier of a text object
      font (str): the new font face name
    Returns:
      str: if a font is not specified, the current font face name
      str: if a font is specified, the previous font face name
      None: if not successful, or on error
    Example:
      import rhinoscriptsyntax as rs
      obj = rs.GetObject("Select text")
      if rs.IsText(obj): rs.TextObjectFont(obj, "Arial")
    See Also:
      AddText
      IsText
      TextObjectHeight
      TextObjectPlane
      TextObjectPoint
      TextObjectStyle
      TextObjectText
    """
    annotation = rhutil.coercegeometry(object_id, True)
    if not isinstance(annotation, Rhino.Geometry.TextEntity):
        return scriptcontext.errorhandler()
    fontdata = annotation.Font
    rc = fontdata.QuartetName
    if font:

        def q2f(qn, b, i):
            return Rhino.DocObjects.Font.FromQuartetProperties(qn, b, i)

        # normally calls will not go further than q2f(font, False, False)
        # but there are a few rare fonts that don't have a regular font
        f = q2f(font, fontdata.Bold, fontdata.Italic)\
            or q2f(font, False, False)\
            or q2f(font, True, False)\
            or q2f(font, False, True)\
            or q2f(font, True, True)
        if f is None:
            return scriptcontext.errorhandler()
        annotation.Font = f
        id = rhutil.coerceguid(object_id, True)
        scriptcontext.doc.Objects.Replace(id, annotation)
        scriptcontext.doc.Views.Redraw()
    return rc
Пример #34
0
def AddHatches(curve_ids, hatch_pattern=None, scale=1.0, rotation=0.0):
    """Creates one or more new hatch objects a list of closed planar curves
    Parameters:
      curve_ids = identifiers of the closed planar curves that defines the
          boundary of the hatch objects
      hatch_pattern[opt] = name of the hatch pattern to be used by the hatch
          object. If omitted, the current hatch pattern will be used
      scale[opt] = hatch pattern scale factor
      rotation[opt] = hatch pattern rotation angle in degrees.
    Returns:
      identifiers of the newly created hatch on success
      None on error
    Example:
      import rhinoscriptsyntax as rs
      curves = rs.GetObjects("Select closed planar curves", rs.filter.curve)
      if curves:
      if rs.IsHatchPattern("Grid"):
      rs.AddHatches( curves, "Grid" )
      else:
      rs.AddHatches( curves, rs.CurrentHatchPattern() )
    See Also:
      AddHatch
      CurrentHatchPattern
      HatchPatternNames
    """
    id = rhutil.coerceguid(curve_ids, False)
    if id: curve_ids = [id]
    index = scriptcontext.doc.HatchPatterns.CurrentHatchPatternIndex
    if hatch_pattern and hatch_pattern != index:
        if isinstance(hatch_pattern, int):
            index = hatch_pattern
        else:
            index = scriptcontext.doc.HatchPatterns.Find(hatch_pattern, True)
        if index < 0: return scriptcontext.errorhandler()
    curves = [rhutil.coercecurve(id, -1, True) for id in curve_ids]
    rotation = Rhino.RhinoMath.ToRadians(rotation)
    hatches = Rhino.Geometry.Hatch.Create(curves, index, rotation, scale)
    if not hatches: return scriptcontext.errorhandler()
    ids = []
    for hatch in hatches:
        id = scriptcontext.doc.Objects.AddHatch(hatch)
        if id == System.Guid.Empty: continue
        ids.append(id)
    if not ids: return scriptcontext.errorhandler()
    scriptcontext.doc.Views.Redraw()
    return ids
Пример #35
0
def PointCoordinates(object_id, point=None):
    """Returns or modifies the X, Y, and Z coordinates of a point object
    Parameters:
      object_id = The identifier of a point object
      point[opt] = A new 3D point location.
    Returns:
      If point is not specified, the current 3-D point location
      If point is specified, the previous 3-D point location
    """
    point_geometry = rhutil.coercegeometry(object_id, True)
    if isinstance(point_geometry, Rhino.Geometry.Point):
        rc = point_geometry.Location
        if point:
            point = rhutil.coerce3dpoint(point, True)
            id = rhutil.coerceguid(object_id, True)
            scriptcontext.doc.Objects.Replace(id, point)
            scriptcontext.doc.Views.Redraw()
        return rc
Пример #36
0
def LightName(object_id, name=None):
    """Returns or changes the name of a light object
    Parameters:
      object_id = the light object's identifier
      name[opt] = the light's new name
    Returns:
      if name is not specified, the current name
      if name is specified, the previous name
    """
    light = __coercelight(object_id, True)
    rc = light.Name
    if name and name != rc:
        light.Name = name
        id = rhutil.coerceguid(object_id, True)
        if not scriptcontext.doc.Lights.Modify(id, light):
            return scriptcontext.errorhandler()
        scriptcontext.doc.Views.Redraw()
    return rc
Пример #37
0
def JoinMeshes(object_ids, delete_input=False):
    """Joins two or or more mesh objects together
    Parameters:
      object_ids = identifiers of two or more mesh objects
      delete_input[opt] = delete input after joining
    Returns:
      identifier of newly created mesh on success
    """
    meshes = [rhutil.coercemesh(id,True) for id in object_ids]
    joined_mesh = Rhino.Geometry.Mesh()
    for mesh in meshes: joined_mesh.Append(mesh)
    rc = scriptcontext.doc.Objects.AddMesh(joined_mesh)
    if delete_input:
        for id in object_ids:
            guid = rhutil.coerceguid(id)
            scriptcontext.doc.Objects.Delete(guid,True)
    scriptcontext.doc.Views.Redraw()
    return rc
Пример #38
0
def DetailLock(detail_id, lock=None):
    """Returns or modifies the projection locked state of a detail
    Parameters:
      detail_id = identifier of a detail object
      lock[opt] = the new lock state
    Returns:
      if lock==None, the current detail projection locked state
      if lock is True or False, the previous detail projection locked state
      None on error
    """
    detail_id = rhutil.coerceguid(detail_id, True)
    detail = scriptcontext.doc.Objects.Find(detail_id)
    if not detail: return scriptcontext.errohandler()
    rc = detail.DetailGeometry.IsProjectionLocked
    if lock and lock != rc:
        detail.DetailGeometry.IsProjectionLocked = lock
        detail.CommitChanges()
    return rc
Пример #39
0
def ProjectPointToSurface(points, surface_ids, direction):
    """Projects one or more points onto one or more surfaces or polysurfaces
    Parameters:
      points = one or more 3D points
      surface_ids = identifiers of one or more surfaces/polysurfaces
      direction = direction vector to project the points
    Returns:
     list of projected points on success
    """
    pts = rhutil.coerce3dpointlist(points)
    if pts is None:
        pts = [rhutil.coerce3dpoint(points, True)]
    direction = rhutil.coerce3dvector(direction, True)
    id = rhutil.coerceguid(surface_ids, False)
    if id: surface_ids = [id]
    breps = [rhutil.coercebrep(id, True) for id in surface_ids]
    tolerance = scriptcontext.doc.ModelAbsoluteTolerance
    return Rhino.Geometry.Intersect.Intersection.ProjectPointsToBreps(breps, pts, direction, tolerance)
Пример #40
0
def GetMeshVertices(object_id, message="", min_count=1, max_count=0):
    """Prompts the user to pick one or more mesh vertices
    Parameters:
      object_id = the mesh object's identifier
      message[opt] = a prompt of message
      min_count[opt] = the minimum number of vertices to select
      max_count[opt] = the maximum number of vertices to select. If 0, the user must
        press enter to finish selection. If -1, selection stops as soon as there
        are at least min_count vertices selected.
    Returns:
      list of mesh vertex indices on success
      None on error
    Example:
      import rhinoscriptsyntax as rs
      mesh = rs.GetObject("Select mesh", rs.filter.mesh)
      if mesh:
      indices = rs.GetMeshVertices(mesh)
      if indices:
      for index in indices: print index
    See Also:
      GetMeshFaces
      MeshFaces
      MeshFaceVertices
      MeshVertices
    """
    scriptcontext.doc.Objects.UnselectAll()
    scriptcontext.doc.Views.Redraw()
    object_id = rhutil.coerceguid(object_id, True)

    class CustomGetObject(Rhino.Input.Custom.GetObject):
        def CustomGeometryFilter(self, rhino_object, geometry,
                                 component_index):
            return object_id == rhino_object.Id

    go = CustomGetObject()
    if message: go.SetCommandPrompt(message)
    go.GeometryFilter = Rhino.DocObjects.ObjectType.MeshVertex
    go.AcceptNothing(True)
    if go.GetMultiple(min_count, max_count) != Rhino.Input.GetResult.Object:
        return None
    objrefs = go.Objects()
    rc = [item.GeometryComponentIndex.Index for item in objrefs]
    go.Dispose()
    return rc
Пример #41
0
def EnableLight(object_id, enable=None):
    """Enables or disables a light object
    Parameters:
      object_id = the light object's identifier
      enable[opt] = the light's enabled status
    Returns:
      if enable is not specified, the current enabled status 
      if enable is specified, the previous enabled status
      None on error
    """
    light = __coercelight(object_id, True)
    rc = light.IsEnabled
    if enable is not None and enable != rc:
        light.IsEnabled = enable
        id = rhutil.coerceguid(object_id)
        if not scriptcontext.doc.Lights.Modify(id, light):
            return scriptcontext.errorhandler()
        scriptcontext.doc.Views.Redraw()
    return rc
Пример #42
0
def IsPlugIn(plugin):
    """Verifies that a plug-in is registered
    Parameters:
      plugin = id of the plug-in
    Returns:
      True or False
    Example:
      import rhinoscriptsyntax as rs
      plugin = rs.GetString("Plug-in name")
    See Also:
      EnablePlugIn
      PlugInId
      PlugIns
    """
    id = rhutil.coerceguid(plugin)
    if not id: id = Rhino.PlugIns.PlugIn.IdFromName(plugin)
    if id:
        rc, loaded, loadprot = Rhino.PlugIns.PlugIn.PlugInExists(id)
        return rc
Пример #43
0
def TextDotHeight(object_id, height=None):
    """Returns or modified the font height of a text dot
    Parameters:
      object_id = identifier of a text dot object
      height[opt] = new font height
    Returns:
      If height is not specified, the current text dot height
      If height is specified, the previous text dot height
      None on error
    """
    textdot = rhutil.coercegeometry(object_id, True)
    if isinstance(textdot, Rhino.Geometry.TextDot):
        rc = textdot.FontHeight
        if height and height > 0:
            textdot.FontHeight = height
            id = rhutil.coerceguid(object_id, True)
            scriptcontext.doc.Objects.Replace(id, textdot)
            scriptcontext.doc.Views.Redraw()
        return rc
Пример #44
0
def TextDotPoint(object_id, point=None):
    """Returns or modifies the location, or insertion point, on a text dot object
    Parameters:
      object_id = identifier of a text dot object
      point[opt] = A new 3D point location.
    Returns:
      If point is not specified, the current 3-D text dot location
      If point is specified, the previous 3-D text dot location
      None if not successful, or on error
    """
    textdot = rhutil.coercegeometry(object_id, True)
    if isinstance(textdot, Rhino.Geometry.TextDot):
        rc = textdot.Point
        if point:
            textdot.Point = rhutil.coerce3dpoint(point, True)
            id = rhutil.coerceguid(object_id, True)
            scriptcontext.doc.Objects.Replace(id, textdot)
            scriptcontext.doc.Views.Redraw()
        return rc
Пример #45
0
def ProjectPointToMesh(points, mesh_ids, direction):
    """Projects one or more points onto one or more meshes
    Parameters:
      points = one or more 3D points
      mesh_ids = identifiers of one or more meshes
      direction = direction vector to project the points
    Returns:
     list of projected points on success
    """
    pts = rhutil.coerce3dpointlist(points, False)
    if pts is None:
        pts = [rhutil.coerce3dpoint(points, True)]
    direction = rhutil.coerce3dvector(direction, True)
    id = rhutil.coerceguid(mesh_ids, False)
    if id: mesh_ids = [id]
    meshes = [rhutil.coercemesh(id, True) for id in mesh_ids]
    tolerance = scriptcontext.doc.ModelAbsoluteTolerance
    rc = Rhino.Geometry.Intersect.Intersection.ProjectPointsToMeshes(meshes, pts, direction, tolerance)
    return rc
Пример #46
0
def TextObjectStyle(object_id, style=None):
    """Returns or modifies the font style of a text object
    Parameters:
      object_id (guid) the identifier of a text object
      style (number, optional) the font style. Can be any of the following flags
         0 = Normal
         1 = Bold
         2 = Italic
    Returns:
      number: if style is not specified, the current font style
      number: if style is specified, the previous font style
      None: if not successful, or on Error
    Example:
      import rhinoscriptsyntax as rs
      obj = rs.GetObject("Select text")
      if rs.IsText(obj):
          rs.TextObjectStyle( obj, 3 )
    See Also:
      AddText
      IsText
      TextObjectFont
      TextObjectHeight
      TextObjectPlane
      TextObjectPoint
      TextObjectText
    """
    annotation = rhutil.coercegeometry(object_id, True)
    if not isinstance(annotation, Rhino.Geometry.TextEntity):
        return scriptcontext.errorhandler()
    fontdata = annotation.Font
    if fontdata is None: return scriptcontext.errorhandler()
    rc = 0
    if fontdata.Bold: rc += 1
    if fontdata.Italic: rc += 2
    if style is not None and style != rc:
        index = scriptcontext.doc.Fonts.FindOrCreate(fontdata.FaceName,
                                                     (style & 1) == 1,
                                                     (style & 2) == 2)
        annotation.Font = scriptcontext.doc.Fonts[index]
        id = rhutil.coerceguid(object_id, True)
        scriptcontext.doc.Objects.Replace(id, annotation)
        scriptcontext.doc.Views.Redraw()
    return rc
Пример #47
0
def TextDotFont(object_id, fontface=None):
    """Returns or modified the font of a text dot
    Parameters:
      object_id = identifier of a text dot object
      fontface[opt] = new font face name
    Returns:
      If font is not specified, the current text dot font
      If font is specified, the previous text dot font
      None on error
    """
    textdot = rhutil.coercegeometry(object_id, True)
    if isinstance(textdot, Rhino.Geometry.TextDot):
        rc = textdot.FontFace
        if fontface:
            textdot.FontFace = fontface
            id = rhutil.coerceguid(object_id, True)
            scriptcontext.doc.Objects.Replace(id, textdot)
            scriptcontext.doc.Views.Redraw()
        return rc
Пример #48
0
def UnifyMeshNormals(object_id):
    """Fixes inconsistencies in the directions of faces of a mesh
    Parameters:
      object_id (guid): identifier of a mesh object
    Returns:
      number: the number of faces that were modified
    Example:
      import rhinoscriptsyntax as rs
      obj = rs.GetObject("Select mesh", rs.filter.mesh)
      if rs.IsMesh(obj): rs.UnifyMeshNormals(obj)
    See Also:
      IsMesh
    """
    mesh = rhutil.coercemesh(object_id, True)
    rc = mesh.UnifyNormals()
    if rc>0:
        id = rhutil.coerceguid(object_id, True)
        scriptcontext.doc.Objects.Replace(id, mesh)
        scriptcontext.doc.Views.Redraw()
    return rc
Пример #49
0
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
Пример #50
0
def LightDirection(object_id, direction=None):
    """Returns or changes the direction of a light object
    Parameters:
      object_id = the light object's identifier
      direction[opt] = the light's new direction
    Returns:
      if direction is not specified, the current direction
      if direction is specified, the previous direction
    """
    light = __coercelight(object_id, True)
    rc = light.Direction
    if direction:
        direction = rhutil.coerce3dvector(direction, True)
        if direction != rc:
            light.Direction = direction
            id = rhutil.coerceguid(object_id, True)
            if not scriptcontext.doc.Lights.Modify(id, light):
                return scriptcontext.errorhandler()
            scriptcontext.doc.Views.Redraw()
    return rc
Пример #51
0
def TextObjectHeight(object_id, height=None):
    """Returns or modifies the height of a text object
    Parameters:
      object_id = the identifier of a text object
      height[opt] = the new text height.
    Returns:
      if height is not specified, the current text height
      if height is specified, the previous text height
      None if not successful, or on error
    """
    annotation = rhutil.coercegeometry(object_id, True)
    if not isinstance(annotation, Rhino.Geometry.TextEntity):
        return scriptcontext.errorhandler()
    rc = annotation.TextHeight
    if height:
        annotation.TextHeight = height
        id = rhutil.coerceguid(object_id, True)
        scriptcontext.doc.Objects.Replace(id, annotation)
        scriptcontext.doc.Views.Redraw()
    return rc
Пример #52
0
def TextObjectPlane(object_id, plane=None):
    """Returns or modifies the plane used by a text object
    Parameters:
      object_id = the identifier of a text object
      plane[opt] = the new text object plane
    Returns:
      if a plane is not specified, the current plane if successful
      if a plane is specified, the previous plane if successful
      None if not successful, or on Error
    """
    annotation = rhutil.coercegeometry(object_id, True)
    if not isinstance(annotation, Rhino.Geometry.TextEntity):
        return scriptcontext.errorhandler()
    rc = annotation.Plane
    if plane:
        annotation.Plane = rhutil.coerceplane(plane, True)
        id = rhutil.coerceguid(object_id, True)
        scriptcontext.doc.Objects.Replace(id, annotation)
        scriptcontext.doc.Views.Redraw()
    return rc
Пример #53
0
def LightLocation(object_id, location=None):
    """Returns or changes the location of a light object
    Parameters:
      object_id = the light object's identifier
      location[opt] = the light's new location
    Returns:
      if location is not specified, the current location
      if location is specified, the previous location
    """
    light = __coercelight(object_id, True)
    rc = light.Location
    if location:
        location = rhutil.coerce3dpoint(location, True)
        if location != rc:
            light.Location = location
            id = rhutil.coerceguid(object_id, True)
            if not scriptcontext.doc.Lights.Modify(id, light):
                return scriptcontext.errorhandler()
            scriptcontext.doc.Views.Redraw()
    return rc
Пример #54
0
def SpotLightShadowIntensity(object_id, intensity=None):
    """Returns or changes the shadow intensity of a spot light.
    Parameters:
      object_id = the light object's identifier
      intensity[opt] = the light's new intensity
    Returns:
      if intensity is not specified, the current intensity
      if intensity is specified, the previous intensity
    """
    light = __coercelight(object_id, True)
    if light.LightStyle != Rhino.Geometry.LightStyle.WorldSpot:
        return scriptcontext.errorhandler()
    rc = light.SpotLightShadowIntensity
    if intensity and intensity != rc:
        light.SpotLightShadowIntensity = intensity
        id = rhutil.coerceguid(object_id, True)
        if not scriptcontext.doc.Lights.Modify(id, light):
            return scriptcontext.errorhandler()
        scriptcontext.doc.Views.Redraw()
    return rc
Пример #55
0
def TextDotText(object_id, text=None):
    """Returns or modifies the text on a text dot object
    Parameters:
      object_id =tThe identifier of a text dot object
      text [opt] = a new string for the dot
    Returns:
      If text is not specified, the current text dot text
      If text is specified, the previous text dot text
      None if not successful, or on error
    """
    textdot = rhutil.coercegeometry(object_id, True)
    if isinstance(textdot, Rhino.Geometry.TextDot):
        rc = textdot.Text
        if text is not None:
            if not isinstance(text, str): text = str(text)
            textdot.Text = text
            id = rhutil.coerceguid(object_id, True)
            scriptcontext.doc.Objects.Replace(id, textdot)
            scriptcontext.doc.Views.Redraw()
        return rc
Пример #56
0
def IsLayout(layout):
    """Verifies that a view is a page layout view
    Parameters:
      layout: title or identifier of an existing page layout view
    Returns:
      True if layout is a page layout view
      False is layout is a standard, model view
      None on error
    """
    layout_id = rhutil.coerceguid(layout)
    alllayouts = scriptcontext.doc.Views.GetViewList(False, True)
    for layoutview in alllayouts:
        if layout_id:
            if layoutview.MainViewport.Id == layout_id: return True
        elif layoutview.MainViewport.Name == layout: return True
    allmodelviews = scriptcontext.doc.Views.GetViewList(True, False)
    for modelview in allmodelviews:
        if layout_id:
            if modelview.MainViewport.Id == layout_id: return False
        elif modelview.MainViewport.Name == layout: return False
    return scriptcontext.errorhandler()
Пример #57
0
def PullPoints(object_id, points):
    """Pulls an array of points to a surface or mesh object. For more
    information, see the Rhino help file Pull command
    Parameters:
      object_id = the identifier of the surface or mesh object that pulls
      points = list of 3D points
    Returns:
      list of 3D points
    """
    id = rhutil.coerceguid(object_id, True)
    points = rhutil.coerce3dpointlist(points, True)
    mesh = rhutil.coercemesh(id, False)
    if mesh:
        points = mesh.PullPointsToMesh(points)
        return list(points)
    brep = rhutil.coercebrep(id, False)
    if brep and brep.Faces.Count==1:
        tolerance = scriptcontext.doc.ModelAbsoluteTolerance
        points = brep.Faces[0].PullPointsToFace(points, tolerance)
        return list(points)
    return []
def EnablePlugIn(plugin, enable=None):
    """Enables or disables a Rhino plug-in
      Parameters:
        plugin (guid): The unique Guid id of the plugin.
        enable (bool, optional): Load silently if True. If omitted Load silently is False.
      Returns:
        bool: True if set to load silently otherwise False
      Example:
      import rhinoscriptsyntax as rs
      print rs.EnablePlugIn("RhinoCrasher", False)
    See Also:
        IsPlugIn
        PlugInId
        PlugIns
    """
    id = rhutil.coerceguid(plugin)
    if not id: id = Rhino.PlugIns.PlugIn.IdFromName(plugin)
    rc, loadSilent = Rhino.PlugIns.PlugIn.GetLoadProtection(id)
    if enable is not None:
        Rhino.PlugIns.PlugIn.SetLoadProtection(id, enable)
    return loadSilent
Пример #59
0
def TextObjectText(object_id, text=None):
    """Returns or modifies the text string of a text object.
    Parameters:
      object_id = the identifier of a text object
      text [opt] = a new text string
    Returns:
      if text is not specified, the current string value if successful
      if text is specified, the previous string value if successful
      None if not successful, or on error
    """
    annotation = rhutil.coercegeometry(object_id, True)
    if not isinstance(annotation, Rhino.Geometry.TextEntity):
        return scriptcontext.errorhandler()
    rc = annotation.Text
    if text:
        if not isinstance(text, str): text = str(text)
        annotation.Text = text
        id = rhutil.coerceguid(object_id, True)
        scriptcontext.doc.Objects.Replace(id, annotation)
        scriptcontext.doc.Views.Redraw()
    return rc
def IsPlugIn(plugin):
    """Verifies that a plug-in is registered
    Parameters:
      plugin (guid): The unique id of the plug-in
    Returns:
      bool: True if the Guid is registered or False if it is not.
    Example:
      import rhinoscriptsyntax as rs
      plugin = rs.GetString("Plug-in name")
      if rs.IsPlugIn(plugin): print "The  plug-in is registered."
      else: print "The  plug-in is not registered."
    See Also:
      EnablePlugIn
      PlugInId
      PlugIns
    """
    id = rhutil.coerceguid(plugin)
    if not id: id = Rhino.PlugIns.PlugIn.IdFromName(plugin)
    if id:
        rc, loaded, loadprot = Rhino.PlugIns.PlugIn.PlugInExists(id)
        return rc