Multiple Get Objects

Hi,

I have run into an odd issue with my script. I want to get a second edge loop from a subd, but the Rhino document doesn’t prompt me for another selection. I’m guessing that the results of the first ‘get’ are sticking around being reused when i try assigning to another variable (selected_edge_id2)

Any thoughts? Do I need to do something like an unset?


# 
import Rhino
import Rhino.Geometry as rg
import rhinoscriptsyntax as rs
import scriptcontext as sc
import System

def GetSubDEdge():
    
    #select a subd edge, return edge ids of selection
    go = Rhino.Input.Custom.GetObject()
    go.GeometryFilter = Rhino.DocObjects.ObjectType.MeshEdge
    go.SetCommandPrompt('Select subd edge for fairing')
    go.GetMultiple(1,0) # could be optional depending on inputs, add cmd line op?
    
    objrefs = go.Objects()
    subdref = go.Objects() [0].SubD()
    
    edge_ids = [ objref.GeometryComponentIndex.Index for objref in objrefs ]
    
    return edge_ids, subdref

def SubDPointsInfo( subd ):
    # input a subd, return all info of subds points
    verts = subd.Vertices.First
    
    control_net_pts, srf_pts = [ verts.ControlNetPoint ], [ verts.SurfacePoint() ]
    subd_vert_objects = [verts] # temp variable
    subd_vert_ids = [verts.Id]
    
    for vert in range( subd.Vertices.Count  - 1 ):
        current = subd_vert_objects[-1].Next
        subd_vert_objects.append( current )
        subd_vert_ids.append( current.Id) 
        control_net_pts.append( current.ControlNetPoint )
        srf_pts.append(current.SurfacePoint( ) )
        value = [ current.ControlNetPoint, current.SurfacePoint( ) ]
    
    point_loc_tuple =  zip( control_net_pts, srf_pts )
    point_loc = list(map(list, point_loc_tuple))
    
    points_info_dict = dict (zip( subd_vert_ids, point_loc) )
    
    return points_info_dict

def GetSelectedSubDEdgePoints( edges, selected_edge_ids ):
    
    selected_edge_points = [ ]
    for edge in edges:
        if edge.Id in selected_edge_ids:
            
            selected_edge_points.append(edge.VertexFrom.Id)
            selected_edge_points.append(edge.VertexTo.Id)
    
    selected_vertex_ids_set = set ( selected_edge_points )
    srf_pt = [ ]
    for id in selected_vertex_ids_set:
        selected_vertex = verts.Find( id )
        srf_pt.append( selected_vertex.SurfacePoint() )
    
    selected_vertex_ids = [ vert for vert in selected_vertex_ids_set ]
    
    return selected_vertex_ids, srf_pt

#get operation one, no problem
selected_edge_id, subdref = GetSubDEdge() #returns selected edge ids
points_info = SubDPointsInfo( subdref )

#get operation two, rhino document doesn't prompt for another selection?
selected_edge_id2, subdref = GetSubDEdge()

[EnableClearObjectsOnEntry]

By default the picked object list is cleared when GetObject.GetObjects() is called. If you are reusing a GetObject class and do not want the existing object list cleared when you call Input, then call EnableClearObjectsOnEntry(false) before calling GetObjects().

Is this just a minor difference between GetObject and GetObjects?

Preselected objects are accepted by default, so the second call to GetMultiple is just accepting the edges selected during the first call. One way to handle this is to add the following before the second call to GetSubDEdge.

sc.doc.Objects.UnselectAll()
sc.doc.Views.Redraw()

Dear Steve,
Thank you for getting in touch! I finally go tthere, thank you.

In the end I used the DisablePreSelect method on my GetObject object. I’m guessing both this and your method are going to reach the same end result.

I suppose I was confused that, ‘pythonically’, the separated function scopes, when doing two calls, still returned the same thing. But without knowing those preselect methods I could have been scratching my head for weeks!