Picking type of input data [python]

Could someone explain to me how can I specify which data I want to provide if the method accepts a number of types as inputs?

Like this for example:
image

I remember seeing somewhere something like:

Point3d[0](x,y,z)
# or
Point3d[2](somePointObject)

But it doesn’t work like that.

Many thanks in advance.

The constructor is chosen based on what type you pass into it.

There is no such notation in Python for selecting constructors. It is all inferred (dynamic typing, remember).

You specify which data you want to provide by typing the code such that you have the data required by the constructor you want…

1 Like

I cannot find the website I think I saw this syntax.

Anyways, if I don’t typehint by right clicking the input in GHpython, how can I explicitly specify a type?

I know I can assign empty types like

i = 0
f = 0.0
s = ""
l = []
t = ()
d = {}

But how can I explicitly define type for empty Point3d / Surface / Curve, etc. variable?

Obviously by instantiating a Point3d etc.

import Rhino.Geometry as rg
p3d = `rg.Point3d(1,2,3)`
print(p3d)

Just like you would use any of the constructors of other classes you want to instantiate…

edit: And before you ask “Why do I have to use RhinoCommon? It is wrong!” : Point3d is a class defined in RhinoCommon.

:slight_smile: Of course I’m gonna ask that. Why isn’t there Point3d defined in GH.api?

GH builds on RhinoCommon anyway, not the other way around. If you really want to hide Point3d you could create your own wrapper class. But that is more work than necessary.

A lot of the primitive geometry types in RhinoCommon allows you to instantiate an empty eg point, plane, vector etc using Unset. Meaning you haven’t set its components yet, same for an empty mesh:

1 Like

Thanks @AndersDeleuran,

This is wonderful.

1 Like