Send "enter" to the rhino command line

Hi guys

I’m trying to create a script to automate the texture mapping of a mesh based on a surfaces coordinates, however the rhino command line always gets stuck at picking target objects, how do I send the enter key or spacebar function to the command line so that the rest of the command can be executed? I still need to set the custom mapping object in the command.

if active:

sc.doc = Rhino.RhinoDoc.ActiveDoc

meshes = rs.ObjectsByType(32)
surfaces = rs.ObjectsByType(8)

objcurrent = meshes[0]
print objcurrent
rs.Command("_-ApplyCustomMapping " + "selid " + str(objcurrent))
rs.Command("enter")

Thanks
Daniel

@dchristev, below seems to work. It preselects the mesh (target) before starting the command and it passes the mapping channel instead of _Enter. You can pass " Enter" instead of the map:channel as well, just put it in the same line:

import rhinoscriptsyntax as rs

def ApplyCustomMapping():
    
    mesh_id = rs.GetObject("Select target mesh", 32, True, False)
    if not mesh_id: return 
    
    srf_id = rs.GetObject("Select custom mapping surface", 8, False, False)
    if not srf_id: return 
    
    # preselect the mesh
    rs.SelectObject(mesh_id)
    
    # set the mapping channel
    map_channel = 1
    
    cmd = "_ApplyCustomMapping _SelId " + str(srf_id) + " " + str(map_channel)
    rs.Command(cmd, True)
    
if __name__=="__main__":
    ApplyCustomMapping()

c.