algorithmic modeling for Rhino
Hello everybody!
Where could I check which are the geometry classes accepted in RegisterInputParams when creating a component from visual studio?
For instance I am trying to have a Polyline as an input parameter and
pManager.Register_PolylineParam("whatever");
does not work.
Thanks!
Cheers
Tags:
There is no Polyline type in Grasshopper. You'll have to either use the Curve parameter, or create your own type and parameter.
--
David Rutten
david@mcneel.com
Poprad, Slovakia
Ok, David. I was using the Curve parameter (pManager.Register_CurveParam) but, when I feed the input with of the component with a polyline, I get the error: "Invalid cast Curve >> Polyline".
Shouldn´t the component be casting the Polyline as a Curve?
Anyway, could you explain how could I create my own parameter? Is it on the GH SDK help file?
Thank you! :)
Polylines can always be cast to curves, but not all curves can be cast to polylines. Is the casting error from within the SolveInstance() method or from elsewhere?
--
David Rutten
david@mcneel.com
Poprad, Slovakia
It must be from the SolveInstance() I suppose because both the input and output params are set as CurveParam.
You should get a Rhino.Geometry.Curve if the parameter is of type curve. Then convert the curve to a polyline if possible, if not, post a runtime message informing the user that only polylines are accepted.
--
David Rutten
david@mcneel.com
Poprad, Slovakia
Right.
But, in the case of using curves and then converting them to polylines, how could I declare at the beginning a placeholder variable and initialize a curve, as this class is protected?
Rhino.Geometry.Curve crv = new Rhino.Geometry.Curve(); is not valid
You don't have to initialize it, the DA.GetData will do that for you:
Curve curve = null;
if (!DA.GetData(0, ref curve)) { return; }
Polyline polyline;
if (!crv.TryGetPolyline(out polyline))
{
AddRuntimeMessage(GH_RuntimeMessageLevel.Error,
"Only polylines are accepted");
return;
}
--
David Rutten
david@mcneel.com
Poprad, Slovakia
Thanks, David.
Now that works just fine but I have trouble outputting DataTrees with DA.SetData.
The Grasshopper component returns items and lists but the outputs that should be returning DataTrees have nothing.
How could I fix that?
Thank you!
Sorry David, the problem is within SolveInstance(). It´s not about DataTrees.
You cannot use DataTrees, they are just for scripters. You'll need to construct a GH_Structure<IGH_Goo T>, then assign it using DA.SetDataTree().
Creating structures is quite tricky though, are you absolutely sure you have to do it this way?
--
David Rutten
david@mcneel.com
Poprad, Slovakia
So, in order to output a collection of objects, I have to use lists, right?
Actually, I was making a component out of a script I made and I was using DataTrees in this one.
It would be intersting to know how to use them but I would use lists if it´s very tricky though.
The problem with outputting trees is that you have to make sure they have the correct paths. If the SolveInstance() method is called more than once in a solution you have to make sure your trees are merged in an odd way.
But let's start another thread for this as this one has reached its response limit.
If you want to use DA.SetDataList, then you need to supply an IEnumerable instance. A list will do. So will an array, or any other class that implements IEnumerable.
--
David Rutten
david@mcneel.com
Poprad, Slovakia
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
© 2024 Created by Scott Davidson. Powered by