Getting Nurbs Surface from user selection (RhinoCommon)


#1

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.EnableHighlight(False)
go.SetCommandPrompt(“Pick Surface”)
go.SubObjectSelect = False
go.GroupSelect = True
go.GeometryFilter = Rhino.DocObjects.ObjectType.Surface
go.Get()
Dim NurbsSurface = TryCast(go.Object(0).Object.Geometry, Rhino.Geometry.NurbsSurface)
doc.Objects.AddSurface(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:
Rhino.Geometry.NurbsSurface.CreateFromPoints(…
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?

Thanks,
Sam


(Menno Deij - van Rijswijk) #2

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.


#3

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!
Sam


#4

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?

Thanks,
Sam


(Menno Deij - van Rijswijk) #5

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

doc.Objects.UnselectAll(true);

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


#6

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

Thanks for setting me straight,
Sam


(Menno Deij - van Rijswijk) #7

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?


#8

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.

Thanks,
Sam