Getting Nurbs Surface from user selection (RhinoCommon)

I’m using RhinoCommon. I’m trying to get nurbs surface geometry from an object a user selects with the below code. I’m adding the nurbs surface back to the document to test that it works. The nurbs surface does not get added, any idea why?

Dim go As New Rhino.Input.Custom.GetObject()
go.EnablePreSelect(False, True)
go.DeselectAllBeforePostSelect = False
go.SetCommandPrompt(“Pick Surface”)
go.SubObjectSelect = False
go.GroupSelect = True
go.GeometryFilter = Rhino.DocObjects.ObjectType.Surface
Dim NurbsSurface = TryCast(go.Object(0).Object.Geometry, Rhino.Geometry.NurbsSurface)

Also, is there a simpler way to do this?

A second question, somewhat related:
I’m creating a nurbs surface with the following function:
The input is a one dimensional list of control points, but control points occur in both the U and V directions on the surface. Whats going on here?


As for your first question - if you need all the pre-select, group-select and subobject-select configuration then you need to use GetObject().
If you just want to pick one surface, try this:

ObjRef sRef;
Result r = RhinoGet.GetOneObject("Pick Surface", false, ObjectType.Surface, out sRef);
if (r != Result.Success) return r;
Surface s = sRef.Surface();
NurbsSurface ns = s.ToNurbsSurface();

When using GetObject you could also get the nurbs surface like this (there is no need to get the NurbsSurface, usually the Surface super-class suffices).

Dim NurbsSurface = go.Object(0).Surface().ToNurbsSurface();

As for your second question, the list is one-dimensional, but is interpreted in two dimensions. You must supply a list with (uCount * vCount) control points and the first uCount control points have v = 0, then the next uCount control points have v = 1, etc. etc.

I realized the mistake I was making. Surface objects in rhino are actually Breps! I had forgotten that!
I like the GetOneObject way of doing it.
I see what you mean about the list being interpreted in two dimensions.

Thanks for your help!

I was just noticing something odd. When I use the get one object twice in a row, the second one is skipped:

Rhino.Input.RhinoGet.GetOneObject(“Select Start Surface”, True, Rhino.DocObjects.ObjectType.Surface, rhObject)
Rhino.Input.RhinoGet.GetOneObject(“Select End Surface”, True, Rhino.DocObjects.ObjectType.Surface, rhObject)

I realize I could use get multiple objects instead, but then I can’t change the string message.

Is this a bug?


It is not a bug but a feature! When you select the first surface, it stays selected and will be used immediately as the input for the second GetOneObject() call.
If you give


prior to the second call to GetOneObject() you will be able to select the second surface.

Shucks,It’s never a bug, it’s always me :frowning:

Thanks for setting me straight,

It gets me every time too. First time I test a command that has multiple selections, it always goes straight on after the first selection. Then there’s the D’OH moment, and I think, how many times have I had this now?

Let me tell you, it’s like I have the Simpson’s playing in the background over here :open_mouth:

I have another question for what I’m trying to do here, but it seems to be getting off track from this posts topic, so I’m putting it up as a new post.