Galapagos Gene List Object Decimals


i’m trying to automate the setting of the values of the Galapagos Genepool component, but my val(see attached image + gh definition) has to be an integer… How can I convert float to decimal so that it is accepted by the GalapagosGeneListObject? Decimal(val) doesn’t work.

Thanks, (5.0 KB)

I posted an example back here:

1 Like

Anders, whenever i’m trying to convert float to decimal using Decimal(value) I am getting this error:

Runtime error (ArgumentTypeException): expected Decimal, got Object_2$2

line 16, in script

does explicity casting it as a float work?

obj[i] = float(val)

Or do what @AndersDeleuran has in his example.

From System import Decimal 
#do stuff
obj[i] = Decimal(val)

this worked I missed that part of @AndersDeleuran code… perfect! thank you!

btw what’s the difference between

  1. from decimal import Decimal
  2. from System import Decimal

in the context of grasshopper and Galapagos Gene List Object?

from decimal import Decimal : won’t work. there is no “decimal” library to import

from System import Decimal: will work. System is an available library to import.

Note: From within the ghpython editor, when you type “import” , the autocomplete will show you the “out of the box” available libraries. There are discussions on the forum that describe ways to import libraries that aren’t listed by the autocomplete.

ok, thanks.
do you maybe know why my value is being automatically rounded (see picture). should I define a context for the conversion from float to decimal?

without seeing the code/component setup/file…I might guess that you should set the “val” input type hint to “No Type Hint”.
Conversely, I would guess that if you set it to “float”, you might not need to have to do any casting in your code, (your original error).

1 Like

thank you so much. “No Type Hint” worked (I forgot I set it to integer to avoid the initial error…)

to clarify, in this case, the reason to set it to “no type hint” is because you are explicitly describing what type of object your val is, (in this case, a decimal/float).
And…in most cases, just setting the type hint makes life a little easier.

1 Like