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:
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.
nathanletwory
(Nathan 'jesterKing' Letwory)
December 5, 2018, 5:14am
2
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?
nathanletwory
(Nathan 'jesterKing' Letwory)
December 5, 2018, 11:45am
4
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.
Of course I’m gonna ask that. Why isn’t there Point3d defined in GH.api?
nathanletwory
(Nathan 'jesterKing' Letwory)
December 5, 2018, 1:46pm
6
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