algorithmic modeling for Rhino
hi all,
I have written a simple script (in VB) that solves a formula for its zero points. it works ok, but I want to feed the formula into the component like into the "function evaluate"-component.
is there any chance to do this?
perhaps its easier to make this in python, but I don't get the python code working.
Tags:
Hi Laurenz,
You can use the eval function to evaluate the string (that's the equation you have) as if it was regular python expression.
So why don't you create a string input and feed in the expression?
--
David Rutten
david@mcneel.com
Hi Djordje,
thank You very much for introducing me into the magic of eval(). It was exactly what I was looking for! Now it works for my needs.
One drawback: the eval()-function seems to slow down the whole thing significantly (hard-coded the component took 78ms, with eval() it took 3.5s !)
Yes, looks like eval function can be slow.
Still, I tried using the equation string directly (assigning it to a variable inside of ghpython component), not importing it from outside. And it lowered the computation time to 100ms.
You can speed up eval() by using lambdas
f = eval('lambda x: ' + expressionString)
and call the function like
f(5)
thank You both, now it works at reasonable speed. I think what causes the delay was the position of the "eval"-command, so every time the function was called, the "eval" translated the input one more time.
Welcome to
Grasshopper
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
© 2024 Created by Scott Davidson. Powered by