SelChain from API

Trying to implement a plug-in that needs to invoke SelChain from API and then allow selection or could bring up full SelChain dialog first and then selection. But SelChain is not available in the API at all!

Is there any way to call SelChain from API or to call PythonScript to call SelChain?
As this could be for large parts, I do not want to have to do the full n^2 solution of checking every element manually.
Are there selection routines that can find any element within x distance (say 0.005in) of a point?
If so, then I could at least greatly reduce n when trying to do the chain.

Thank you!

This is correct. But you might be able to script the SelChain command. Have you tried?

SelChain is not a command. It is a modifier to GetObject.
I can’t script it to turn on after already in GetObject.
How can I call GetObject with SelChain, G0 options from a plugin?

SelChain is a command, see (about halfway down the page). While running GetObject this can be called using RhinoApp.RunScript, as it is a transparent command.

What you can do from code to emulate this is different whether it is curves or surface edges that are being selected. For curves, you could do the following pseudo code:

GetObject go = new GetObject()
crv = go.Object().Curve()

Point3d start = crv.PointAtStart;
Point3d end = crv.PointAtEnd;

List<Curve> allCurves = GetAllCurvesFromDocument(); // todo: implement this
allCurves.Remove(crv); // you may need to test object id's

List<Curve> adjacent = GetAllAdjacentCurves(allCurves, start, end, doc.ModelAbsoluteTolerance); // todo:  implement this, it should return curves from the all-curves list that have their start or end point at the given 'start' or 'end' point

while(adjacent.Count > 0 && allCurves.Count > 0)
  crv = JoinCurves(crv, adjacent, doc.ModelAbsolutTolerance); // todo: implement this, or call Intersection.JoinCurves directly
  if (null == crv) break; // failed to join
  start = crv.PointAtStart;
  end = crv.PointAtEnd;
  adjacent = GetAllAdjacentCurves(alLCurves, start, end, doc.ModelAbsoluteTolerance);
// crv is now a (possibly) circular poly-curve.
// in principle, for G0 continuity, this last bit is not necessary, but for G1+ continuity it is.

double t0 = crv.Domain.T0;
double t1 = crv.Domain.T1;
double t;
while(crv.GetNextDiscontinuity(Continuity.C0_continuous, t0, t1, out t))
  t0 = t;

Curve c0_continuous = crv.ToNurbsCurve(new Domain(crv.Domain.T0, t0));

This code probably contains some errors; I haven’t tested the code, but the idea should be clear.

For surface edges, you can walk the BRep object model using edges and vertices. See for more information.