algorithmic modeling for Rhino
Hi,
I develop a new component library with C# and get a mess with user data mechanism.
My issue is the following :
* a component A generates a list of polylines as output and user data are associated to each segment of the polyline like this:
solveinstance() method of A :
----------------------------
for (int i = ....) // a loop
{
r = new Polyline(...); // polyline initiated
r.SegmentAt(0).ToNurbsCurve().SetUserString("power", 1.0)
outputList.add(r)
}
DA.SetDataList(outputList)
When using this output in my other component B as an input, I hoped retrieving my user data (here "power" set to 1.0). But no !
I am actually doing in the solveInstance() method of B a cast from Curve to Polyline to avoid a "Invalid Cast Curve>>Polyline" issue in Grasshopper :
List<Curve> input = new List<Curve>();
DA.GetDataList<Curve>(0, input);
List<Polyline> output = new List<Polyline>(input.Count);
Polyline ply;
foreach (Curve c in input)
{
c.TryGetPolyline(out ply);
output.Add(ply);
Rhino.RhinoApp.WriteLine(ply.SegmentAt(0).ToNurbsCurve().GetUserString("power"));
}
But the WriteLine should display at Rhino prompt the value "1.0" no ? nothing is displayed, as if it was lost during the conversion.
Anybody could help ? Where am I wrong ?
Tags:
You convert a segment from the polyline to a Nurbs curve, then you assign user data to that Nurbs curve, but the curve is subsequently forgotten. The ToNurbsCurve() method doesn't mean the polyline will now have a nurbs curve in it, rather it creates a nurbs curve that looks just like the original segment.
Polylines and Lines cannot have user data assigned to them. For that you will need to use either NurbsCurves or PolylineCurves or PolyCurves (basically, the class has to inherit from GeometryBase for UserData to work).
Alternatively you can output your user data as a separate Grasshopper parameter instead of trying to combine it with the geometry.
--
David Rutten
david@mcneel.com
Tirol, Austria
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