示例#1
0
def XformWorldToScreen(point, view=None, screen_coordinates=False):
    """Transforms a point from world coordinates to either client-area coordinates of
    the specified view or screen coordinates. The resulting coordinates are represented
    as a 2D point
    Parameters:
      point = 3D point in world coordinates
      view[opt] = title or identifier of a view. If omitted, the active view is used
      screen_coordinates[opt] = if False, the function returns the results as
        client-area coordinates. If True, the result is in screen-area coordinates
    Returns:
      2D point on success
      None on error
    """
    point = rhutil.coerce3dpoint(point, True)
    view = rhview.__viewhelper(view)
    viewport = view.MainViewport
    xform = viewport.GetTransform(Rhino.DocObjects.CoordinateSystem.World,
                                  Rhino.DocObjects.CoordinateSystem.Screen)
    point = xform * point
    point = Rhino.Geometry.Point2d(point.X, point.Y)
    if screen_coordinates:
        screen = view.ScreenRectangle
        point.X = point.X + screen.Left
        point.Y = point.Y + screen.Top
    return point
示例#2
0
def PopupMenu(items, modes=None, point=None, view=None):
    """Display a context-style popup menu. The popup menu can appear almost
    anywhere, and can be dismissed by clicking the left or right mouse buttons
    Parameters:
      items = list of strings representing the menu items. An empty string or None
        will create a separator
      modes[opt] = List of numbers identifying the display modes. If omitted, all
        modes are enabled.
          0 = menu item is enabled
          1 = menu item is disabled
          2 = menu item is checked
          3 = menu item is disabled and checked
      point[opt] = a 3D point where the menu item will appear. If omitted, the menu
        will appear at the current cursor position
      view[opt] = if point is specified, the view in which the point is computed.
        If omitted, the active view is used
    Returns:
      index of the menu item picked or -1 if no menu item was picked
    """
    screen_point = System.Windows.Forms.Cursor.Position
    if point:
        point = rhutil.coerce3dpoint(point)
        view = __viewhelper(view)
        viewport = view.ActiveViewport
        point2d = viewport.WorldToClient(point)
        screen_point = viewport.ClientToScreen(point2d)
    return Rhino.UI.Dialogs.ShowContextMenu(items, screen_point, modes)
示例#3
0
def VisibleObjects(view=None, select=False, include_lights=False, include_grips=False):
    """Returns the identifiers of all objects that are visible in a specified view
    Parameters:
      view [opt] = the view to use. If omitted, the current active view is used
      select [opt] = Select the objects
      include_lights [opt] = include light objects
      include_grips [opt] = include grip objects
    Returns:
      list of Guids identifying the objects
    """
    it = Rhino.DocObjects.ObjectEnumeratorSettings()
    it.DeletedObjects = False
    it.ActiveObjects = True
    it.ReferenceObjects = True
    it.IncludeLights = include_lights
    it.IncludeGrips = include_grips
    it.VisibleFilter = True
    it.ViewportFilter = __viewhelper(view).MainViewport

    object_ids = []
    e = scriptcontext.doc.Objects.GetObjectList(it)
    for object in e:
        if select: object.Select(True)
        object_ids.append(object.Id)

    if object_ids and select: scriptcontext.doc.Views.Redraw()
    return object_ids
def XformWorldToScreen(point, view=None, screen_coordinates=False):
    """Transforms a point from world coordinates to either client-area coordinates of
    the specified view or screen coordinates. The resulting coordinates are represented
    as a 2D point
    Parameters:
      point (point): 3D point in world coordinates
      view (str, optional): title or identifier of a view. If omitted, the active view is used
      screen_coordinates (bool, optional): if False, the function returns the results as
        client-area coordinates. If True, the result is in screen-area coordinates
    Returns:
      (point): 2D point on success
      None: on error
    Example:
      import rhinoscriptsyntax as rs
      point = (0.0, 0.0, 0.0)
      view = rs.CurrentView()
      point2d = rs.XformWorldToScreen(point, view)
      print point2d
    See Also:
      XformScreenToWorld
    """
    point = rhutil.coerce3dpoint(point, True)
    view = rhview.__viewhelper(view)
    viewport = view.MainViewport
    xform = viewport.GetTransform(Rhino.DocObjects.CoordinateSystem.World,
                                  Rhino.DocObjects.CoordinateSystem.Screen)
    point = xform * point
    point = Rhino.Geometry.Point2d(point.X, point.Y)
    if screen_coordinates:
        screen = view.ScreenRectangle
        point.X = point.X + screen.Left
        point.Y = point.Y + screen.Top
    return point
示例#5
0
def WindowPick(corner1, corner2, view=None, select=False, in_window=True):
    """Picks objects using either a window or crossing selection
    Parameters:
      corner1, corner2 = corners of selection window
      view[opt] = view to perform the selection in
      select[opt] = select picked objects
      in_window[opt] = if False, then a crossing window selection is performed
    Returns:
      list of object ids on success
    Example:
      import rhinoscriptsyntax as  rs
      rs.WindowPick((0,0,0), (0,0,0),  None, True)
    See Also:
      
    """
    viewport = __viewhelper(view).MainViewport
    screen1 = Rhino.Geometry.Point2d(rhutil.coerce3dpoint(corner1, True))
    screen2 = Rhino.Geometry.Point2d(rhutil.coerce3dpoint(corner2, True))
    xf = viewport.GetTransform(Rhino.DocObjects.CoordinateSystem.World, Rhino.DocObjects.CoordinateSystem.Screen)
    screen1.Transform(xf)
    screen2.Transform(xf)
    objects = None
    filter = Rhino.DocObjects.ObjectType.AnyObject
    if in_window:
        objects = scriptcontext.doc.Objects.FindByWindowRegion(viewport, screen1, screen2, True, filter)
    else:
        objects = scriptcontext.doc.Objects.FindByCrossingWindowRegion(viewport, screen1, screen2, True, filter)
    if objects:
        rc = []
        for rhobj in objects:
            rc.append(rhobj.Id)
            if select: rhobj.Select(True)
        if select: scriptcontext.doc.Views.Redraw()
        return rc
def XformScreenToWorld(point, view=None, screen_coordinates=False):
    """Transforms a point from either client-area coordinates of the specified view
    or screen coordinates to world coordinates. The resulting coordinates are represented
    as a 3-D point
    Parameters:
      point (point): 2D point
      view (str, optional): title or identifier of a view. If omitted, the active view is used
      screen_coordinates (bool, optional): if False, point is in client-area coordinates. If True,
      point is in screen-area coordinates
    Returns:
      point: on success
      None: on error
    Example:
      import rhinoscriptsyntax as rs
      point2d = 200,100
      view = rs.CurrentView()
      point = rs.XformScreenToWorld(point2d, view)
      print point
    See Also:
      XformWorldToScreen
    """
    point = rhutil.coerce2dpoint(point, True)
    view = rhview.__viewhelper(view)
    viewport = view.MainViewport
    xform = viewport.GetTransform(Rhino.DocObjects.CoordinateSystem.Screen,
                                  Rhino.DocObjects.CoordinateSystem.World)
    point3d = Rhino.Geometry.Point3d(point.X, point.Y, 0)
    if screen_coordinates:
        screen = view.ScreenRectangle
        point3d.X = point.X - screen.Left
        point3d.Y = point.Y - screen.Top
    point3d = xform * point3d
    return point3d
示例#7
0
def WindowPick(corner1, corner2, view=None, select=False, in_window=True):
    """Picks objects using either a window or crossing selection
    Parameters:
      corner1, corner2 = corners of selection window
      view[opt] = view to perform the selection in
      select[opt] = select picked objects
      in_window[opt] = if False, then a crossing window selection is performed
    Returns:
      list of object ids on success
    """
    viewport = __viewhelper(view).MainViewport
    screen1 = Rhino.Geometry.Point2d(rhutil.coerce3dpoint(corner1, True))
    screen2 = Rhino.Geometry.Point2d(rhutil.coerce3dpoint(corner2, True))
    xf = viewport.GetTransform(Rhino.DocObjects.CoordinateSystem.World,
                               Rhino.DocObjects.CoordinateSystem.Screen)
    screen1.Transform(xf)
    screen2.Transform(xf)
    objects = None
    filter = Rhino.DocObjects.ObjectType.AnyObject
    if in_window:
        objects = scriptcontext.doc.Objects.FindByWindowRegion(
            viewport, screen1, screen2, True, filter)
    else:
        objects = scriptcontext.doc.Objects.FindByCrossingWindowRegion(
            viewport, screen1, screen2, True, filter)
    if objects:
        rc = []
        for rhobj in objects:
            rc.append(rhobj.Id)
            if select: rhobj.Select(True)
        if select: scriptcontext.doc.Views.Redraw()
        return rc
def WindowPick(corner1, corner2, view=None, select=False, in_window=True):
    """Picks objects using either a window or crossing selection
    Parameters:
      corner1, corner2 (point): corners of selection window
      view (bool, optional): view to perform the selection in
      select (bool, optional): select picked objects
      in_window (bool, optional): if False, then a crossing window selection is performed
    Returns:
      list(guid, ...): identifiers of selected objects on success
    Example:
      import rhinoscriptsyntax as  rs
      rs.WindowPick((0,0,0), (0,0,0),  None, True)
    See Also:
      
    """
    viewport = __viewhelper(view).MainViewport
    screen1 = Rhino.Geometry.Point2d(rhutil.coerce3dpoint(corner1, True))
    screen2 = Rhino.Geometry.Point2d(rhutil.coerce3dpoint(corner2, True))
    xf = viewport.GetTransform(Rhino.DocObjects.CoordinateSystem.World, Rhino.DocObjects.CoordinateSystem.Screen)
    screen1.Transform(xf)
    screen2.Transform(xf)
    objects = None
    filter = Rhino.DocObjects.ObjectType.AnyObject
    if in_window:
        objects = scriptcontext.doc.Objects.FindByWindowRegion(viewport, screen1, screen2, True, filter)
    else:
        objects = scriptcontext.doc.Objects.FindByCrossingWindowRegion(viewport, screen1, screen2, True, filter)
    if objects:
        rc = []
        for rhobj in objects:
            rc.append(rhobj.Id)
            if select: rhobj.Select(True)
        if select: scriptcontext.doc.Views.Redraw()
        return rc
示例#9
0
def VisibleObjects(view=None,
                   select=False,
                   include_lights=False,
                   include_grips=False):
    """Return identifiers of all objects that are visible in a specified view
    Parameters:
      view [opt] = the view to use. If omitted, the current active view is used
      select [opt] = Select the objects
      include_lights [opt] = include light objects
      include_grips [opt] = include grip objects
    Returns:
      list of Guids identifying the objects
    """
    it = Rhino.DocObjects.ObjectEnumeratorSettings()
    it.DeletedObjects = False
    it.ActiveObjects = True
    it.ReferenceObjects = True
    it.IncludeLights = include_lights
    it.IncludeGrips = include_grips
    it.VisibleFilter = True
    viewport = __viewhelper(view).MainViewport
    it.ViewportFilter = viewport

    object_ids = []
    e = scriptcontext.doc.Objects.GetObjectList(it)
    for object in e:
        bbox = object.Geometry.GetBoundingBox(True)
        if viewport.IsVisible(bbox):
            if select: object.Select(True)
            object_ids.append(object.Id)

    if object_ids and select: scriptcontext.doc.Views.Redraw()
    return object_ids
示例#10
0
def XformScreenToWorld(point, view=None, screen_coordinates=False):
    """Transforms a point from either client-area coordinates of the specified view
    or screen coordinates to world coordinates. The resulting coordinates are represented
    as a 3-D point
    Parameters:
      point = 2D point
      view[opt] = title or identifier of a view. If omitted, the active view is used
      screen_coordinates[opt] = if False, point is in client-area coordinates. If True,
      point is in screen-area coordinates
    Returns:
      3D point on success
      None on error
    """
    point = rhutil.coerce2dpoint(point, True)
    view = rhview.__viewhelper(view)
    viewport = view.MainViewport
    xform = viewport.GetTransform(Rhino.DocObjects.CoordinateSystem.Screen,
                                  Rhino.DocObjects.CoordinateSystem.World)
    point3d = Rhino.Geometry.Point3d(point.X, point.Y, 0)
    if screen_coordinates:
        screen = view.ScreenRectangle
        point3d.X = point.X - screen.Left
        point3d.Y = point.Y - screen.Top
    point3d = xform * point3d
    return point3d
示例#11
0
def MeshOutline(object_ids, view=None):
    """Creates polyline curve outlines of mesh objects
    Parameters:
      objects_ids ([guid, ...]): identifiers of meshes to outline
      view (str, optional): view to use for outline direction
    Returns:
      list(guid, ...): polyline curve identifiers on success
    Example:
      import rhinoscriptsyntax as rs
      objs = rs.GetObjects("Select mesh objects to outline", rs.filter.mesh)
      if objs: rs.MeshOutline(objs)
    See Also:
      IsMesh
    """
    viewport = __viewhelper(view).MainViewport
    meshes = []
    mesh = rhutil.coercemesh(object_ids, False)
    if mesh: meshes.append(mesh)
    else: meshes = [rhutil.coercemesh(id,True) for id in object_ids]
    rc = []
    for mesh in meshes:
        polylines = mesh.GetOutlines(viewport)
        if not polylines: continue
        for polyline in polylines:
            id = scriptcontext.doc.Objects.AddPolyline(polyline)
            rc.append(id)
    scriptcontext.doc.Views.Redraw()
    return rc
示例#12
0
def MeshOutline(object_ids, view=None):
    """Creates polyline curve outlines of mesh objects
    Parameters:
      objects_ids = identifiers of meshes to outline
      view(opt) = view to use for outline direction
    Returns:
      list of polyline curve id on success
    Example:
      import rhinoscriptsyntax as rs
      objs = rs.GetObjects("Select mesh objects to outline", rs.filter.mesh)
      if objs: rs.MeshOutline(objs)
    See Also:
      IsMesh
    """
    viewport = __viewhelper(view).MainViewport
    meshes = []
    mesh = rhutil.coercemesh(object_ids, False)
    if mesh: meshes.append(mesh)
    else: meshes = [rhutil.coercemesh(id,True) for id in object_ids]
    rc = []
    for mesh in meshes:
        polylines = mesh.GetOutlines(viewport)
        if not polylines: continue
        for polyline in polylines:
            id = scriptcontext.doc.Objects.AddPolyline(polyline)
            rc.append(id)
    scriptcontext.doc.Views.Redraw()
    return rc
示例#13
0
def XformWorldToScreen(point, view=None, screen_coordinates=False):
    """Transforms a point from world coordinates to either client-area coordinates of
    the specified view or screen coordinates. The resulting coordinates are represented
    as a 2D point
    Parameters:
      point = 3D point in world coordinates
      view[opt] = title or identifier of a view. If omitted, the active view is used
      screen_coordinates[opt] = if False, the function returns the results as
        client-area coordinates. If True, the result is in screen-area coordinates
    Returns:
      2D point on success
      None on error
    Example:
      import rhinoscriptsyntax as rs
      point = (0.0, 0.0, 0.0)
      view = rs.CurrentView()
      point2d = rs.XformWorldToScreen(point, view)
      print point2d
    See Also:
      XformScreenToWorld
    """
    point = rhutil.coerce3dpoint(point, True)
    view = rhview.__viewhelper(view)
    viewport = view.MainViewport
    xform = viewport.GetTransform(Rhino.DocObjects.CoordinateSystem.World, Rhino.DocObjects.CoordinateSystem.Screen)
    point = xform * point
    point = Rhino.Geometry.Point2d(point.X, point.Y)
    if screen_coordinates:
        screen = view.ScreenRectangle
        point.X = point.X + screen.Left
        point.Y = point.Y + screen.Top
    return point
示例#14
0
def XformScreenToWorld(point, view=None, screen_coordinates=False):
    """Transforms a point from either client-area coordinates of the specified view
    or screen coordinates to world coordinates. The resulting coordinates are represented
    as a 3-D point
    Parameters:
      point = 2D point
      view[opt] = title or identifier of a view. If omitted, the active view is used
      screen_coordinates[opt] = if False, point is in client-area coordinates. If True,
      point is in screen-area coordinates
    Returns:
      3D point on success
      None on error
    Example:
      import rhinoscriptsyntax as rs
      point2d = 200,100
      view = rs.CurrentView()
      point = rs.XformScreenToWorld(point2d, view)
      print point
    See Also:
      XformWorldToScreen
    """
    point = rhutil.coerce2dpoint(point, True)
    view = rhview.__viewhelper(view)
    viewport = view.MainViewport
    xform = viewport.GetTransform(Rhino.DocObjects.CoordinateSystem.Screen, Rhino.DocObjects.CoordinateSystem.World)
    point3d = Rhino.Geometry.Point3d(point.X, point.Y, 0)
    if screen_coordinates:
        screen = view.ScreenRectangle
        point3d.X = point.X - screen.Left
        point3d.Y = point.Y - screen.Top
    point3d = xform * point3d
    return point3d
示例#15
0
def PopupMenu(items, modes=None, point=None, view=None):
    """Displays a user defined, context-style popup menu. The popup menu can appear
    almost anywhere, and it can be dismissed by either clicking the left or right
    mouse buttons
    Parameters:
      items = list of strings representing the menu items. An empty string or None
        will create a separator
      modes[opt] = List of numbers identifying the display modes. If omitted, all
        modes are enabled.
          0 = menu item is enabled
          1 = menu item is disabled
          2 = menu item is checked
          3 = menu item is disabled and checked
      point[opt] = a 3D point where the menu item will appear. If omitted, the menu
        will appear at the current cursor position
      view[opt] = if point is specified, the view in which the point is computed.
        If omitted, the active view is used
    Returns:
      index of the menu item picked or -1 if no menu item was picked
    """
    screen_point = System.Windows.Forms.Cursor.Position
    if point:
        point = rhutil.coerce3dpoint(point)
        view = __viewhelper(view)
        viewport = view.ActiveViewport
        point2d = viewport.WorldToClient(point)
        screen_point = viewport.ClientToScreen(point2d)
    return Rhino.UI.Dialogs.ShowContextMenu(items, screen_point, modes);
示例#16
0
def AddLeader(points, view_or_plane=None, text=None):
    """Adds a leader to the document. Leader objects are planar.
    The 3D points passed to this function should be co-planar
    Parameters:
      points = list of (at least 2) 3D points
      view_or_plane [opt] = If a view is specified, points will be constrained
        to the view's construction plane. If a view is not specified, points
        will be constrained to a plane fit through the list of points
      text [opt] = leader's text string
    Returns:
      identifier of the new leader on success
      None on error
    Example:
      import rhinoscriptsyntax as rs
      points = rs.GetPoints(True, False, "Select leader points")
      if points: rs.AddLeader( points )
    See Also:
      IsLeader
      LeaderText
    """
    points = rhutil.coerce3dpointlist(points)
    if points is None or len(points) < 2:
        raise ValueError("points must have at least two items")
    rc = System.Guid.Empty
    view = None
    if text and not isinstance(text, str):
        text = str(text)

    if not view_or_plane:
        if len(points) == 2:
            plane = scriptcontext.doc.Views.ActiveView.ActiveViewport.ConstructionPlane(
            )
            rc = scriptcontext.doc.Objects.AddLeader(
                text, plane,
                [Rhino.Geometry.Point2d(p.X, p.Y) for p in points])
        else:
            rc = scriptcontext.doc.Objects.AddLeader(text, points)
    else:
        plane = rhutil.coerceplane(view_or_plane)
        if not plane:
            view = __viewhelper(view_or_plane)
            plane = view.ActiveViewport.ConstructionPlane()
        points2d = []
        for point in points:
            cprc, s, t = plane.ClosestParameter(point)
            if not cprc: return scriptcontext.errorhandler()
            points2d.append(Rhino.Geometry.Point2d(s, t))
        if text is None:
            rc = scriptcontext.doc.Objects.AddLeader(plane, points2d)
        else:
            if not isinstance(text, str): text = str(text)
            rc = scriptcontext.doc.Objects.AddLeader(text, plane, points2d)
    if rc == System.Guid.Empty: return scriptcontext.errorhandler()
    scriptcontext.doc.Views.Redraw()
    return rc
示例#17
0
def WindowPick(corner1, corner2, view=None, select=False, in_window=True):
    """Picks objects using either a window or crossing selection
    Parameters:
      corner1, corner2 (point): corners of selection window
      view (bool, optional): view to perform the selection in
      select (bool, optional): select picked objects
      in_window (bool, optional): if False, then a crossing window selection is performed
    Returns:
      list(guid, ...): identifiers of selected objects on success
    Example:
      import rhinoscriptsyntax as  rs
      rs.WindowPick((0,0,0), (0,0,0),  None, True)
    See Also:
      
    """
    view = __viewhelper(view)
    viewport = view.MainViewport

    screen1 = rhutil.coerce3dpoint(corner1, True)
    screen2 = rhutil.coerce3dpoint(corner2, True)
    xf = viewport.GetTransform(Rhino.DocObjects.CoordinateSystem.World,
                               Rhino.DocObjects.CoordinateSystem.Screen)
    screen1.Transform(xf)
    screen2.Transform(xf)

    pc = Rhino.Input.Custom.PickContext()
    pc.View = view
    pc.PickStyle = Rhino.Input.Custom.PickStyle.WindowPick if in_window else Rhino.Input.Custom.PickStyle.CrossingPick
    pc.PickGroupsEnabled = True if in_window else False
    _, frustumLine = viewport.GetFrustumLine((screen1.X + screen2.X) / 2.0,
                                             (screen1.Y + screen2.Y) / 2.0)
    pc.PickLine = frustumLine

    leftX = min(screen1.X, screen2.X)
    topY = min(screen1.Y, screen2.Y)
    w = abs(screen1.X - screen2.X)
    h = abs(screen1.Y - screen2.Y)
    rec = sd.Rectangle(leftX, topY, w, h)

    pc.SetPickTransform(viewport.GetPickTransform(rec))
    pc.UpdateClippingPlanes()

    objects = scriptcontext.doc.Objects.PickObjects(pc)

    if objects:
        rc = []
        for rhobj in objects:
            o = rhobj.Object()
            rc.append(o.Id)
            if select: o.Select(True)
        if select: scriptcontext.doc.Views.Redraw()
        return rc
示例#18
0
def AddLeader(points, view_or_plane=None, text=None):
    """Adds a leader to the document. Leader objects are planar.
    The 3D points passed to this function should be co-planar
    Parameters:
      points = list of (at least 2) 3D points
      view_or_plane [opt] = If a view is specified, points will be constrained
        to the view's construction plane. If a view is not specified, points
        will be constrained to a plane fit through the list of points
      text [opt] = leader's text string
    Returns:
      identifier of the new leader on success
      None on error
    Example:
      import rhinoscriptsyntax as rs
      points = rs.GetPoints(True, False, "Select leader points")
      if points: rs.AddLeader( points )
    See Also:
      IsLeader
      LeaderText
    """
    points = rhutil.coerce3dpointlist(points)
    if points is None or len(points)<2: raise ValueError("points must have at least two items")
    rc = System.Guid.Empty
    view = None
    if text and not isinstance(text, str): 
        text = str(text)

    if not view_or_plane:
        if len(points) == 2:
            plane = scriptcontext.doc.Views.ActiveView.ActiveViewport.ConstructionPlane()
            rc = scriptcontext.doc.Objects.AddLeader(text, plane, [Rhino.Geometry.Point2d(p.X, p.Y) for p in points])
        else:
            rc = scriptcontext.doc.Objects.AddLeader(text, points)
    else:
        plane = rhutil.coerceplane(view_or_plane)
        if not plane:
            view = __viewhelper(view_or_plane)
            plane = view.ActiveViewport.ConstructionPlane()
        points2d = []
        for point in points:
            cprc, s, t = plane.ClosestParameter( point )
            if not cprc: return scriptcontext.errorhandler()
            points2d.append( Rhino.Geometry.Point2d(s,t) )
        if text is None:
            rc = scriptcontext.doc.Objects.AddLeader(plane, points2d)
        else:
            if not isinstance(text, str): text = str(text)
            rc = scriptcontext.doc.Objects.AddLeader(text, plane, points2d)
    if rc==System.Guid.Empty: return scriptcontext.errorhandler()
    scriptcontext.doc.Views.Redraw()
    return rc
示例#19
0
def VisibleObjects(view=None,
                   select=False,
                   include_lights=False,
                   include_grips=False):
    """Return identifiers of all objects that are visible in a specified view
    Parameters:
      view (bool, optional): the view to use. If omitted, the current active view is used
      select (bool, optional): Select the objects
      include_lights (bool, optional): include light objects
      include_grips (bool, optional): include grip objects
    Returns:
      list(guid, ...): identifiers of the visible objects
    Example:
      import rhinoscriptsyntax as rs
      object_ids = rs.VisibleObjects("Top")
      if object_ids:
      for id in object_ids: print "Object identifier:", id
    See Also:
      IsView
      IsVisibleInView
    """
    it = Rhino.DocObjects.ObjectEnumeratorSettings()
    it.DeletedObjects = False
    it.ActiveObjects = True
    it.ReferenceObjects = True
    it.IncludeLights = include_lights
    it.IncludeGrips = include_grips
    it.VisibleFilter = True
    viewport = __viewhelper(view).MainViewport
    it.ViewportFilter = viewport

    object_ids = []
    e = scriptcontext.doc.Objects.GetObjectList(it)
    for object in e:
        bbox = object.Geometry.GetBoundingBox(True)
        if viewport.IsVisible(bbox):
            if select: object.Select(True)
            object_ids.append(object.Id)

    if object_ids and select: scriptcontext.doc.Views.Redraw()
    return object_ids
示例#20
0
def MeshOutline(object_ids, view=None):
    """Creates polyline curve outlines of mesh objects
    Parameters:
      objects_ids = identifiers of meshes to outline
      view(opt) = view to use for outline direction
    Returns:
      list of polyline curve id on success
    """
    viewport = __viewhelper(view).MainViewport
    meshes = []
    mesh = rhutil.coercemesh(object_ids, False)
    if mesh: meshes.append(mesh)
    else: meshes = [rhutil.coercemesh(id,True) for id in object_ids]
    rc = []
    for mesh in meshes:
        polylines = mesh.GetOutlines(viewport)
        for polyline in polylines:
            id = scriptcontext.doc.Objects.AddPolyline(polyline)
            rc.append(id)
    scriptcontext.doc.Views.Redraw()
    return rc
示例#21
0
def MeshOutline(object_ids, view=None):
    """Creates polyline curve outlines of mesh objects
    Parameters:
      objects_ids = identifiers of meshes to outline
      view(opt) = view to use for outline direction
    Returns:
      list of polyline curve id on success
    """
    viewport = __viewhelper(view).MainViewport
    meshes = []
    mesh = rhutil.coercemesh(object_ids, False)
    if mesh: meshes.append(mesh)
    else: meshes = [rhutil.coercemesh(id, True) for id in object_ids]
    rc = []
    for mesh in meshes:
        polylines = mesh.GetOutlines(viewport)
        for polyline in polylines:
            id = scriptcontext.doc.Objects.AddPolyline(polyline)
            rc.append(id)
    scriptcontext.doc.Views.Redraw()
    return rc
示例#22
0
def VisibleObjects(view=None, select=False, include_lights=False, include_grips=False):
    """Return identifiers of all objects that are visible in a specified view
    Parameters:
      view [opt] = the view to use. If omitted, the current active view is used
      select [opt] = Select the objects
      include_lights [opt] = include light objects
      include_grips [opt] = include grip objects
    Returns:
      list of Guids identifying the objects
    Example:
      import rhinoscriptsyntax as rs
      object_ids = rs.VisibleObjects("Top")
      if object_ids:
      for id in object_ids: print "Object identifier:", id
    See Also:
      IsView
      IsVisibleInView
    """
    it = Rhino.DocObjects.ObjectEnumeratorSettings()
    it.DeletedObjects = False
    it.ActiveObjects = True
    it.ReferenceObjects = True
    it.IncludeLights = include_lights
    it.IncludeGrips = include_grips
    it.VisibleFilter = True
    viewport = __viewhelper(view).MainViewport
    it.ViewportFilter = viewport

    object_ids = []
    e = scriptcontext.doc.Objects.GetObjectList(it)
    for object in e:
        bbox = object.Geometry.GetBoundingBox(True)
        if viewport.IsVisible(bbox):
            if select: object.Select(True)
            object_ids.append(object.Id)

    if object_ids and select: scriptcontext.doc.Views.Redraw()
    return object_ids
示例#23
0
def IsVisibleInView(object_id, view=None):
    """Verifies an object is visible in a view"""
    rhobj = rhutil.coercerhinoobject(object_id, True, True)
    return rhobj.IsActiveInViewport(__viewhelper(view).MainViewport)
示例#24
0
def IsVisibleInView(object_id, view=None):
    """Verifies an object is visible in a view"""
    rhobj = rhutil.coercerhinoobject(object_id, True, True)
    viewport = __viewhelper(view).MainViewport
    bbox = rhobj.Geometry.GetBoundingBox(True)
    return rhobj.Visible and viewport.IsVisible(bbox)
示例#25
0
def IsVisibleInView(object_id, view=None):
    """Verifies an object is visible in a view"""
    rhobj = rhutil.coercerhinoobject(object_id, True, True)
    viewport = __viewhelper(view).MainViewport
    bbox = rhobj.Geometry.GetBoundingBox(True)
    return rhobj.Visible and viewport.IsVisible(bbox)