コード例 #1
0
def GetObjects(message=None, filter=0, group=True, preselect=False, select=False, objects=None, minimum_count=1, maximum_count=0, custom_filter=None):
    """Prompts user to pick or select one or more objects.
    Parameters:
      message[opt] = a prompt or message.
      filter[opt] = The type(s) of geometry (points, curves, surfaces, meshes,...)
          that can be selected. Object types can be added together to filter
          several different kinds of geometry. use the filter class to get values
      group[opt] = Honor object grouping.  If omitted and the user picks a group,
          the entire group will be picked (True). Note, if filter is set to a
          value other than 0 (All objects), then group selection will be disabled.
      preselect[opt] =  Allow for the selection of pre-selected objects.
      select[opt] = Select the picked objects.  If False, the objects that are
          picked are not selected.
      objects[opt] = list of objects that are allowed to be selected
      mimimum_count, maximum_count[out] = limits on number of objects allowed to be selected
    Returns
      list of Guids identifying the picked objects
    """
    if not preselect:
        scriptcontext.doc.Objects.UnselectAll()
        scriptcontext.doc.Views.Redraw()

    objects = rhutil.coerceguidlist(objects)
    class CustomGetObject(Rhino.Input.Custom.GetObject):
        def __init__(self, filter_function):
            self.m_filter_function = filter_function
        def CustomGeometryFilter( self, rhino_object, geometry, component_index ):
            if objects and not rhino_object.Id in objects: return False
            rc = True
            if self.m_filter_function is not None:
                try:
                    rc = self.m_filter_function(rhino_object, geometry, component_index)
                except:
                    rc = True
            return rc
    go = CustomGetObject(custom_filter)
    if message: go.SetCommandPrompt(message)
    geometry_filter = __FilterHelper(filter)
    if filter>0: go.GeometryFilter = geometry_filter
    go.SubObjectSelect = False
    go.GroupSelect = group
    go.AcceptNothing(True)
    if go.GetMultiple(minimum_count,maximum_count)!=Rhino.Input.GetResult.Object: return None
    if not select:
        scriptcontext.doc.Objects.UnselectAll()
        scriptcontext.doc.Views.Redraw()
    rc = []
    count = go.ObjectCount
    for i in xrange(count):
        objref = go.Object(i)
        rc.append(objref.ObjectId)
        obj = objref.Object()
        if select and obj is not None: obj.Select(select)
    go.Dispose()
    return rc
コード例 #2
0
def GetObjects(message=None, filter=0, group=True, preselect=False, select=False, objects=None, minimum_count=1, maximum_count=0, custom_filter=None):
    """Prompts user to pick or select one or more objects.
    Parameters:
      message[opt] = a prompt or message.
      filter[opt] = The type(s) of geometry (points, curves, surfaces, meshes,...)
          that can be selected. Object types can be added together to filter
          several different kinds of geometry. use the filter class to get values
      group[opt] = Honor object grouping.  If omitted and the user picks a group,
          the entire group will be picked (True). Note, if filter is set to a
          value other than 0 (All objects), then group selection will be disabled.
      preselect[opt] =  Allow for the selection of pre-selected objects.
      select[opt] = Select the picked objects.  If False, the objects that are
          picked are not selected.
      objects[opt] = list of objects that are allowed to be selected
      mimimum_count, maximum_count[out] = limits on number of objects allowed to be selected
    Returns
      list of Guids identifying the picked objects
    """
    if not preselect:
        scriptcontext.doc.Objects.UnselectAll()
        scriptcontext.doc.Views.Redraw()

    objects = rhutil.coerceguidlist(objects)
    class CustomGetObject(Rhino.Input.Custom.GetObject):
        def __init__(self, filter_function):
            self.m_filter_function = filter_function
        def CustomGeometryFilter( self, rhino_object, geometry, component_index ):
            if objects and not rhino_object.Id in objects: return False
            rc = True
            if self.m_filter_function is not None:
                try:
                    rc = self.m_filter_function(rhino_object, geometry, component_index)
                except:
                    rc = True
            return rc
    go = CustomGetObject(custom_filter)
    go.SetCommandPrompt(message or "Select Objects")
    geometry_filter = __FilterHelper(filter)
    if filter>0: go.GeometryFilter = geometry_filter
    go.SubObjectSelect = False
    go.GroupSelect = group
    go.AcceptNothing(True)
    if go.GetMultiple(minimum_count,maximum_count)!=Rhino.Input.GetResult.Object: return None
    if not select:
        scriptcontext.doc.Objects.UnselectAll()
        scriptcontext.doc.Views.Redraw()
    rc = []
    count = go.ObjectCount
    for i in xrange(count):
        objref = go.Object(i)
        rc.append(objref.ObjectId)
        obj = objref.Object()
        if select and obj is not None: obj.Select(select)
    go.Dispose()
    return rc
コード例 #3
0
ファイル: pointvector.py プロジェクト: Agnestan/rhinopython
def PointClosestObject(point, object_ids):
    """Finds the object that is closest to a test point
    Parameters:
      point = point to test
      object_id = identifiers of one or more objects
    Returns:
      (closest object_id, point on object) on success
      None on failure
    """
    object_ids = rhutil.coerceguidlist(object_ids)
    point = rhutil.coerce3dpoint(point, True)
    closest = None
    for id in object_ids:
        geom = rhutil.coercegeometry(id, True)
        point_geometry = geom
        if isinstance(point_geometry, Rhino.Geometry.Point):
            distance = point.DistanceTo( point_geometry.Location )
            if closest is None or distance<closest[0]:
                closest = distance, id, point_geometry.Location
            continue
        point_cloud = geom
        if isinstance(point_cloud, Rhino.Geometry.PointCloud):
            index = point_cloud.ClosestPoint(point)
            if index>=0:
                distance = point.DistanceTo( point_cloud[index].Location )
                if closest is None or distance<closest[0]:
                    closest = distance, id, point_cloud[index].Location
            continue
        curve = geom
        if isinstance(curve, Rhino.Geometry.Curve):
            rc, t = curve.ClosestPoint(point)
            if rc:
                distance = point.DistanceTo( curve.PointAt(t) )
                if closest is None or distance<closest[0]:
                    closest = distance, id, curve.PointAt(t)
            continue
        brep = geom
        if isinstance(brep, Rhino.Geometry.Brep):
            brep_closest = brep.ClosestPoint(point)
            distance = point.DistanceTo( brep_closest )
            if closest is None or distance<closest[0]:
                closest = distance, id, brep_closest
            continue
        mesh = geom
        if isinstance(mesh, Rhino.Geometry.Mesh):
            mesh_closest = mesh.ClosestPoint(point)
            distance = point.DistanceTo( mesh_closest )
            if closest is None or distance<closest[0]:
                closest = distance, id, mesh_closest
            continue
    if not closest: return scriptcontext.errorhandler()
    return closest[1], closest[2]
コード例 #4
0
def PointClosestObject(point, object_ids):
    """Finds the object that is closest to a test point
    Parameters:
      point = point to test
      object_id = identifiers of one or more objects
    Returns:
      (closest object_id, point on object) on success
      None on failure
    """
    object_ids = rhutil.coerceguidlist(object_ids)
    point = rhutil.coerce3dpoint(point, True)
    closest = None
    for id in object_ids:
        geom = rhutil.coercegeometry(id, True)
        point_geometry = geom
        if isinstance(point_geometry, Rhino.Geometry.Point):
            distance = point.DistanceTo(point_geometry.Location)
            if closest is None or distance < closest[0]:
                closest = distance, id, point_geometry.Location
            continue
        point_cloud = geom
        if isinstance(point_cloud, Rhino.Geometry.PointCloud):
            index = point_cloud.ClosestPoint(point)
            if index >= 0:
                distance = point.DistanceTo(point_cloud[index].Location)
                if closest is None or distance < closest[0]:
                    closest = distance, id, point_cloud[index].Location
            continue
        curve = geom
        if isinstance(curve, Rhino.Geometry.Curve):
            rc, t = curve.ClosestPoint(point)
            if rc:
                distance = point.DistanceTo(curve.PointAt(t))
                if closest is None or distance < closest[0]:
                    closest = distance, id, curve.PointAt(t)
            continue
        brep = geom
        if isinstance(brep, Rhino.Geometry.Brep):
            brep_closest = brep.ClosestPoint(point)
            distance = point.DistanceTo(brep_closest)
            if closest is None or distance < closest[0]:
                closest = distance, id, brep_closest
            continue
        mesh = geom
        if isinstance(mesh, Rhino.Geometry.Mesh):
            mesh_closest = mesh.ClosestPoint(point)
            distance = point.DistanceTo(mesh_closest)
            if closest is None or distance < closest[0]:
                closest = distance, id, mesh_closest
            continue
    if not closest: return scriptcontext.errorhandler()
    return closest[1], closest[2]
コード例 #5
0
ファイル: group.py プロジェクト: AsherBond/rhinopython
def AddObjectsToGroup(object_ids, group_name):
    """Adds one or more objects to an existing group.
    Parameters:
      object_ids = list of Strings or Guids representing the object identifiers
      group_name = the name of an existing group
    Returns:
      number of objects added to the group
    """
    if not isinstance(group_name, str): group_name = str(group_name)
    index = scriptcontext.doc.Groups.Find(group_name, True)
    object_ids = rhutil.coerceguidlist(object_ids)
    if index<0 or not object_ids: return 0
    if not scriptcontext.doc.Groups.AddToGroup(index, object_ids): return 0
    return len(object_ids)
コード例 #6
0
ファイル: group.py プロジェクト: RafaelMri/gh-decodes
def AddObjectsToGroup(object_ids, group_name):
    """Adds one or more objects to an existing group.
    Parameters:
      object_ids = list of Strings or Guids representing the object identifiers
      group_name = the name of an existing group
    Returns:
      number of objects added to the group
    """
    if not isinstance(group_name, str): group_name = str(group_name)
    index = scriptcontext.doc.Groups.Find(group_name, True)
    object_ids = rhutil.coerceguidlist(object_ids)
    if index<0 or not object_ids: return 0
    if not scriptcontext.doc.Groups.AddToGroup(index, object_ids): return 0
    return len(object_ids)
コード例 #7
0
def AddObjectsToGroup(object_ids, group_name):
    """Adds one or more objects to an existing group.
    Parameters:
      object_ids ([guid, ...]) list of Strings or Guids representing the object identifiers
      group_name (str): the name of an existing group
    Returns:
      number: number of objects added to the group
    Example:
      import rhinoscriptsyntax as rs
      name = "NewGroup"
      object_ids = rs.GetObjects("Select objects to add to group")
      if object_ids: rs.AddObjectsToGroup(object_ids, name)
    See Also:
      AddObjectToGroup
      IsGroupEmpty
      ObjectGroups
      ObjectsByGroup
    """
    if not isinstance(group_name, str): group_name = str(group_name)
    index = scriptcontext.doc.Groups.Find(group_name)
    object_ids = rhutil.coerceguidlist(object_ids)
    if index < 0 or not object_ids: return 0
    if not scriptcontext.doc.Groups.AddToGroup(index, object_ids): return 0
    return len(object_ids)
コード例 #8
0
ファイル: group.py プロジェクト: itrowa/rhinoscriptsyntax
def AddObjectsToGroup(object_ids, group_name):
    """Adds one or more objects to an existing group.
    Parameters:
      object_ids = list of Strings or Guids representing the object identifiers
      group_name = the name of an existing group
    Returns:
      number of objects added to the group
    Example:
      import rhinoscriptsyntax as rs
      name = "NewGroup"
      object_ids = rs.GetObjects("Select objects to add to group")
      if object_ids: rs.AddObjectsToGroup(object_ids, name)
    See Also:
      AddObjectToGroup
      IsGroupEmpty
      ObjectGroups
      ObjectsByGroup
    """
    if not isinstance(group_name, str): group_name = str(group_name)
    index = scriptcontext.doc.Groups.Find(group_name, True)
    object_ids = rhutil.coerceguidlist(object_ids)
    if index<0 or not object_ids: return 0
    if not scriptcontext.doc.Groups.AddToGroup(index, object_ids): return 0
    return len(object_ids)
コード例 #9
0
def PointClosestObject(point, object_ids):
    """Finds the object that is closest to a test point
    Parameters:
      point = point to test
      object_id = identifiers of one or more objects
    Returns:
      (closest object_id, point on object) on success
      None on failure
    Example:
      import rhinoscriptsyntax as rs
      objs = rs.GetObjects("Select target objects for closest point", 63)
      if objs:
      point = rs.GetPoint("Test point")
      if point:
      results = rs.PointClosestObject(point, objs)
      if results:
      print "Object id:", results[0]
      rs.AddPoint( results[1] )
    See Also:
      CurveClosestObject
    """
    object_ids = rhutil.coerceguidlist(object_ids)
    point = rhutil.coerce3dpoint(point, True)
    closest = None
    for id in object_ids:
        geom = rhutil.coercegeometry(id, True)
        point_geometry = geom
        if isinstance(point_geometry, Rhino.Geometry.Point):
            distance = point.DistanceTo(point_geometry.Location)
            if closest is None or distance < closest[0]:
                closest = distance, id, point_geometry.Location
            continue
        point_cloud = geom
        if isinstance(point_cloud, Rhino.Geometry.PointCloud):
            index = point_cloud.ClosestPoint(point)
            if index >= 0:
                distance = point.DistanceTo(point_cloud[index].Location)
                if closest is None or distance < closest[0]:
                    closest = distance, id, point_cloud[index].Location
            continue
        curve = geom
        if isinstance(curve, Rhino.Geometry.Curve):
            rc, t = curve.ClosestPoint(point)
            if rc:
                distance = point.DistanceTo(curve.PointAt(t))
                if closest is None or distance < closest[0]:
                    closest = distance, id, curve.PointAt(t)
            continue
        brep = geom
        if isinstance(brep, Rhino.Geometry.Brep):
            brep_closest = brep.ClosestPoint(point)
            distance = point.DistanceTo(brep_closest)
            if closest is None or distance < closest[0]:
                closest = distance, id, brep_closest
            continue
        mesh = geom
        if isinstance(mesh, Rhino.Geometry.Mesh):
            mesh_closest = mesh.ClosestPoint(point)
            distance = point.DistanceTo(mesh_closest)
            if closest is None or distance < closest[0]:
                closest = distance, id, mesh_closest
            continue
    if closest: return closest[1], closest[2]
コード例 #10
0
def GetObjects(message=None,
               filter=0,
               group=True,
               preselect=False,
               select=False,
               objects=None,
               minimum_count=1,
               maximum_count=0,
               custom_filter=None):
    """Prompts user to pick or select one or more objects.
    Parameters:
      message (str, optional): a prompt or message.
      filter (number, optional): The type(s) of geometry (points, curves, surfaces, meshes,...)
          that can be selected. Object types can be added together to filter
          several different kinds of geometry. use the filter class to get values
      group (bool, optional) Honor object grouping.  If omitted and the user picks a group,
          the entire group will be picked (True). Note, if filter is set to a
          value other than 0 (All objects), then group selection will be disabled.
      preselect (bool, optional):  Allow for the selection of pre-selected objects.
      select (bool, optional): Select the picked objects.  If False, the objects that are
          picked are not selected.
      objects ([guid, ...]): list of objects that are allowed to be selected
      minimum_count, maximum_count(number): limits on number of objects allowed to be selected
      custom_filter (str, optional): Calls a custom function in the script and passes the Rhino Object, Geometry, and component index and returns true or false indicating if the object can be selected
    Returns:
      list(guid, ...): identifiers of the picked objects
    Example:
      import rhinoscriptsyntax as rs
      objectIds = rs.GetObjects("Pick some curves", rs.filter.curve)
      for id in objectIds: print "Object identifier:", id
    See Also:
      GetCurveObject
      GetObject
      GetSurfaceObject
    """
    if not preselect:
        scriptcontext.doc.Objects.UnselectAll()
        scriptcontext.doc.Views.Redraw()

    objects = rhutil.coerceguidlist(objects)

    class CustomGetObject(Rhino.Input.Custom.GetObject):
        def __init__(self, filter_function):
            self.m_filter_function = filter_function

        def CustomGeometryFilter(self, rhino_object, geometry,
                                 component_index):
            if objects and not rhino_object.Id in objects: return False
            rc = True
            if self.m_filter_function is not None:
                try:
                    rc = self.m_filter_function(rhino_object, geometry,
                                                component_index)
                except:
                    rc = True
            return rc

    go = CustomGetObject(custom_filter)
    go.SetCommandPrompt(message or "Select objects")
    geometry_filter = __FilterHelper(filter)
    if filter > 0: go.GeometryFilter = geometry_filter
    go.SubObjectSelect = False
    go.GroupSelect = group
    go.AcceptNothing(True)
    if go.GetMultiple(minimum_count,
                      maximum_count) != Rhino.Input.GetResult.Object:
        return None
    if not select:
        scriptcontext.doc.Objects.UnselectAll()
        scriptcontext.doc.Views.Redraw()
    rc = []
    count = go.ObjectCount
    for i in xrange(count):
        objref = go.Object(i)
        rc.append(objref.ObjectId)
        obj = objref.Object()
        if select and obj is not None: obj.Select(select)
    go.Dispose()
    return rc
コード例 #11
0
def PointClosestObject(point, object_ids):
    """Finds the object that is closest to a test point
    Parameters:
      point = point to test
      object_id = identifiers of one or more objects
    Returns:
      (closest object_id, point on object) on success
      None on failure
    Example:
      import rhinoscriptsyntax as rs
      objs = rs.GetObjects("Select target objects for closest point", 63)
      if objs:
      point = rs.GetPoint("Test point")
      if point:
      results = rs.PointClosestObject(point, objs)
      if results:
      print "Object id:", results[0]
      rs.AddPoint( results[1] )
    See Also:
      CurveClosestObject
    """
    object_ids = rhutil.coerceguidlist(object_ids)
    point = rhutil.coerce3dpoint(point, True)
    closest = None
    for id in object_ids:
        geom = rhutil.coercegeometry(id, True)
        point_geometry = geom
        if isinstance(point_geometry, Rhino.Geometry.Point):
            distance = point.DistanceTo( point_geometry.Location )
            if closest is None or distance<closest[0]:
                closest = distance, id, point_geometry.Location
            continue
        point_cloud = geom
        if isinstance(point_cloud, Rhino.Geometry.PointCloud):
            index = point_cloud.ClosestPoint(point)
            if index>=0:
                distance = point.DistanceTo( point_cloud[index].Location )
                if closest is None or distance<closest[0]:
                    closest = distance, id, point_cloud[index].Location
            continue
        curve = geom
        if isinstance(curve, Rhino.Geometry.Curve):
            rc, t = curve.ClosestPoint(point)
            if rc:
                distance = point.DistanceTo( curve.PointAt(t) )
                if closest is None or distance<closest[0]:
                    closest = distance, id, curve.PointAt(t)
            continue
        brep = geom
        if isinstance(brep, Rhino.Geometry.Brep):
            brep_closest = brep.ClosestPoint(point)
            distance = point.DistanceTo( brep_closest )
            if closest is None or distance<closest[0]:
                closest = distance, id, brep_closest
            continue
        mesh = geom
        if isinstance(mesh, Rhino.Geometry.Mesh):
            mesh_closest = mesh.ClosestPoint(point)
            distance = point.DistanceTo( mesh_closest )
            if closest is None or distance<closest[0]:
                closest = distance, id, mesh_closest
            continue
    if closest: return closest[1], closest[2]