Slider expressions extract with python?

Hey guys how would one get the sliders expression from the given slider?

I barely understand python so a working example would be nice, I personally haven’t found documentation on how to extract this exact parameter. Thank you for your help in advance!

Regards,

Jonas Blazinskas

import Grasshopper as gh
objs = ghenv.Component.Params.Input[0].Sources
for obj in objs:
    if type(obj) is gh.Kernel.Special.GH_NumberSlider:
        print obj.Expression

sliderExpression.gh (14.4 KB)

1 Like

Thank you very much! Just realised that even tho I now have the expressions, I am not sure of how to do a calculation with a string expression like this. Do you have any ideas on how could I plug my x value in now? Or would I have to write a custom python script for this?

image

You can use Evaluate Component:


Evaluate.gh (14.2 KB)

1 Like

Awesome! Thank you for your help so much!

You can also use eval function in python:

import rhinoscriptsyntax as rs
a = eval(F)

Evaluate.gh (15.3 KB)

1 Like