Well, there are a few things there but the main one is that you are requiring the user to select point objects existing in the document to indicate the section line. You can do that, but in that case you will have to extract their coordinates to to send to the command string. Right now str(pt1) makes a string from the objects ID, but the Section command wants a clicked point, i.e. the point’s coordinates, not the point object.
Instead of using GetObject() to select an existing point, use GetPoint(). This will prompt you to click on a point. str(pt) will then give you the point coordinates, which is what the command wants. So to start with something like this might work:
import rhinoscriptsyntax as rs
St = rs.GetObjects("Select 3D objects to section")
p1 = rs.GetPoint("First point for section")
p2 = rs.GetPoint("Second point for section")
rs.UnselectAllObjects()
rs.SelectObjects(St)
rs.Command("Section "+ str(p1) + " " + str(p2) + " _Enter")
The problem with this is that the point coordinates are in world coordinates, so the script will work from the top view or any other that has the world Top CPlane active. But it won’t work from something like the Front or Right views. So you would need to transform the point coordinates into current CPlane coordinates.
import rhinoscriptsyntax as rs
St = rs.GetObjects("Select 3D objects to section")
p1 = rs.GetPoint("First point for section")
p2 = rs.GetPoint("Second point for section")
#get active view's CPlane
plane=rs.ViewCPlane()
#transform p1 and p2 to CPlane coordinates
p1=rs.XformWorldToCPlane(p1,plane)
p2=rs.XformWorldToCPlane(p2,plane)
#now do your section
rs.UnselectAllObjects()
rs.SelectObjects(St)
rs.Command("Section "+ str(p1) + " " + str(p2) + " _Enter")
Finally, you could also do this with native rhinoscriptsyntax methods, with the method ProjectCurveToSurface() but it’s a little more complicated:
import rhinoscriptsyntax as rs
objs=rs.GetObjects("Select 3D objects to section")
pt1,pt2=rs.GetLine(1)
#you need to create an actual line curve for this to work
line_crv=rs.AddLine(pt1,pt2)
#get active view's CPlane
plane=rs.ViewCPlane()
#get active CPlane's Z-Axis (projection direction)
proj_vec=plane.ZAxis
#project line to surfaces in CPlane Z direction
sections=rs.ProjectCurveToSurface(line_crv,objs,proj_vec)
#select the results (if any)
if sections: rs.SelectObjects(sections)
#delete the line curve
rs.DeleteObject(line_crv)