algorithmic modeling for Rhino
String
Ow, but it would work for formulas (like x+y+z)?
There is no expression type, so you get a string then you create an expression from that string.
private void RunScript(string f, double x, double y, double z, ref object A)
{
Grasshopper.Kernel.Expressions.GH_ExpressionParser parser =
new Grasshopper.Kernel.Expressions.GH_ExpressionParser();
parser.AddVariable("x", x);
parser.AddVariable("y", y);
parser.AddVariable("z", z);
parser.CacheSymbols(f);
Grasshopper.Kernel.Expressions.GH_Variant result = parser.Evaluate();
A = result.ToGoo();
}
You can also use the Evaluate() overload which takes a string, caching symbols only makes sense if you intend to run the expression more than once.
I am trying to integrate this into my program, but when I try to convert the final result to a double, it gives me the following error:
'' error: Unable to cast object of type 'Grasshopper.Kernel.Types.GH_Number' to type 'System.IConvertible'. (line: 0)''
Do you know where that might be coming from?
Thank you
ToGoo() returns a type of IGH_Goo, which (if the result of the expression is a double) will be GH_Number. There's no build in conversion from GH_Number to double, but you can just get the double out of the GH_Variant directly. There's no need to create an expensive GH_Number if you're not going to use it.
Ok ok, I seen, but it still cannot convert from variant to double:
"0. error: Unable to cast object of type 'Grasshopper.Kernel.Expressions.GH_Variant' to type 'System.IConvertible'. (line: 0)"
Well ... here's a very clumsy way to cast some stuff (this def is just a demo related with another case). Null breps ... well ... GH failed to memorize them (as usual).
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