algorithmic modeling for Rhino
You can use Rhino.Geometry.Matrix in Grasshopper scripting components. Here is how.The only missing bit is the automatic casting made by the 'TypeHint' of the input, but we can do that in scripting directly, too.
Matrix m = null;
if (x is Matrix)
{
m = (Matrix) x; //cast if it is a Matrix
}
else if(x == null)
{
m = new Matrix(3, 3); //what should happen if it is null?
}
else
{
throw new ArgumentException( //some other type: exception
string.Format("Conversion of x failed from {0} to Matrix.",
x.GetType().ToString())
);
}
//do something with m...
m.Invert(0.001); A = m;
Giulio
--
Giulio Piacentino
for Robert McNeel & Associates
giulio@mcneel.com
I opted for is because it's slightly more self-documenting, and as components are compiled in debug mode, I doubt this will make a big difference in speed. Good point though.
Giulio
--
Giulio Piacentino
for Robert McNeel & Associates
giulio@mcneel.com
Thanks for the fast help
I think I'm almost there but now i get this error:
1. Solution exception:Object reference not set to an instance of an object.
I work in VS enviorment
thanks
That exception means you're trying to call properties or methods on a null reference. Before you call any methods or access any fields, you must make sure the instance you're calling it on actually exists.
In Visual Studio, these problems are usually solved best using the Debugger. If you do not know how to use the debugger, that should be research project #1 for you. There is no tool out there which will help you develop better code than a working debugger.
Hi Roey,
in addition to what David suggested, if you use the code above with the is keyword, you will get a special case for null items. You can then treat them in the way you think will work better for you.
Giulio
--
Giulio Piacentino
for Robert McNeel & Associates
giulio@mcneel.com
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