Grasshopper

algorithmic modeling for Rhino

Hi

Stupid question: how can I get the data type of an input parameter?

ghenv.Component.Params.Input[0]... IsString? IsList? Is DataTree?

I try a couple of things but I didn't get it

Thanks

Paolo

Views: 450

Replies to This Discussion

Check this snippet of code: https://github.com/mostaphaRoudsari/dyfpy/blob/master/dyfpy/grassho...

TypeHint.TypeName will give you the type and Access will return item / list /datatree.

Ok Thanks

But this give me the TypeHint that I have choose?

And if I need the type of data that is entering?

I want to understand if I can change the behaviour of the script following the type of enetering data

if(string):

    do this

else if (number):

    do that

and so on...

Let's call your input `value`. Then you can try something like this:

try:

    # assume it's a number

    x = float(v) * 10

except ValueError:

    # it is None or string

     if v is not None:

         print v

Anyway very useful

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service