Python, GetOneObject - CustomGeometryFilter Exception


import Rhino
import rhinoscriptsyntax
import scriptcontext

#offset_object
#soft_edited_curve

object, objref = Rhino.Input.RhinoGet.GetOneObject ( "Pick Curve to Offset and Soft Edit" , False , Rhino.DocObjects.CurveObject)
# Returns bool

print object
print objref

pick_error

Just a couple of things. First the above error, Cannot create instances of CurveObject because it has no public constructors. This is after picking the curve. What have I done incorrectly?

Then, a question on unpacking. I’m familar with this now, but a little bit thrown by the documentation which states:

public static Result GetOneObject(
string prompt,
bool acceptNothing,
ObjectType filter,

out ObjRef rhObject

What’s the difference between the ‘out’ and usual ‘returned’ value ? I noticed that I can unpack it the two variables nicely, but want to know the distinction between these two terms. Or is it a C# term? At first I thought it was an extra argument.

Thanks!

filter = Rhino.DocObjects.ObjectType.Curve
rc, objref = Rhino.Input.RhinoGet.GetOneObject('Pick Curve', False, filter)

out is a keyword in C# which is used for passing the arguments to methods as a reference type. It is generally used when a method returns multiple values.
https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/out-parameter-modifier

1 Like

Phew… okay that makes for some pretty heavy reading. So what would be the syntax for that in Python terms, to describe this method?

Python does not have syntax for specifying whether a method paramter is passed by-reference since arguments are always passed by-value. in python you can return multiple values by simply return them separated by commas (tuple).

def test():
    return 'abc', 100
a, b = test()
print(a)
# abc

print(b)
# 100

Makes sense. So I should interpret GetOneObject, for Python, as:

GetOneObject ( string, bool, ObjectType )
----- return Result, ObjRef

Is this not a bit misleading? Although I know it’s probably just me. So I notice the same thing in GetNumber - it returns a Result, outs / refs a double.

Thank you for that link! Glad that I asked, and I’ll take the silver lining of being pointed to an intermediate level link :sweat_smile:

Sorry - one other question if you (or anyone) will.

From the Curve.Offset method, I get an array back of type Rhino.Geometry.Curve [ - ] . What’s the best way to approach this kind of object in Python, and where does the Array type come from? I only ask since it’s not a standard Python datatype like a list (forgive my use of datatype).

For now I have assigned the result of Curve.Offset to offset_crv_array, and set offset_crv = offset_crv_array [0]. Covenient in this simple case, but maybe there is a more correct / elegant / accepted way of handling the returned array.

from System import Array

.NET arrays can be indexed and iterated over as if they were Python lists, You can also check for membership using ‘in’ and test their length with ‘len’.

Turning a .NET array into a Python list is trivially easy:

curves = list(rec.Offset(plane, 3, 0.01, rg.CurveOffsetCornerStyle.None))

As far as I know, It’s the most acceptable way to do this.

1 Like

Thanks for this, yeah it’s more the ‘origination’ of the Array which confused me. So it’s a .NET … should I say, storage method? (whatever the right syntax is for this, equivalent to what a list/tuple is in python)