OK, so I made a quick C# component for switching alternative Planes, A or B to the output. I used this component for different types, and therefore I set the input param’s Type Hint to GeometryBase.
if (UseB)
{
R = B;
return;
}
R = A;
But, using GeometryBase as the type hint causes the Planes to flip axes so that X becomes Y.
I understan that a Plane is a Struct and thus not a subclass to GeometryBase (not even a class) but, if the type is still handled by GrassHopper somehow, why manipulating it in the passing… ?
This reckless flippin really puzzled me before I found out where the planes had flipped axes.
Grasshopper will have to convert your Plane into something which does derive from GeometryBase, in this case a PlaneSurface:
This surface is then converted back into a plane when you plug it into a Plane parameter. I suspect it’s this latter conversion which does not respect axis orientation. I can special case the conversion from PlaneSurface to Plane to not rely on the Surface.TryGetPlane() method, but ideally your component wouldn’t convert planes to surfaces at all if it didn’t have to.
How about this:
private void RunScript(System.Object A, System.Object B, bool UseB, ref object R)
{
R = UseB ? B : A;
if (R is Plane)
return;
Plane plane = Plane.Unset;
if (!GH_Convert.ToPlane(R, ref plane, GH_Conversion.Both))
throw new Exception("Input data cannot be converted to a plane");
R = plane;
}
Anyway, thanks, your approach simplifies things a lot (I have use for this kind of switching for many different types, so Object suits me well, silly me should’ve thought of it already.).