Hi so I’m working on a custom Grasshopper plugin. I’m running into an issue where, when I try to use the “Rhino.NodeInCode” to call the “Mesh Shadow” component, it will return a “ironpython.runtime.list” rather than some usable object type. It won’t let me cast it to a “Curve”.
I’ve tried just using a regular “Object” class to store it but that doesn’t come into Grasshopper nicely. It doesn’t show up as curves but as just a “ironpython.runtime.list”. It does seem to return a curve if I plug similar code into a C# node and run it as a one-off.
Does anyone have a suggestion on how to deal with this properly? Or where to look to learn more about this problem? Thank you.
using Rhino.NodeInCode;
private SunPosition currentSunPosition;
private Mesh originObject;
public readonly Curve ShadowCurve;
private ComponentFunctionInfo ghMeshShadow = Components.FindComponent("MeshShadow");
private Curve CreateShadowCurve()
{
string[] warnings;
Plane planeXY = new Plane(new Point3d(0.0, 0.0, 0.0), new Vector3d(0.0, 0.0, 1.0));
object[] result = ghMeshShadow.Evaluate(new Object[] {
originObject,
currentSunPosition.SunVector,
planeXY }, false, out warnings);
return (Curve) result[0];
}
(Can’t tell if this response was meant to be snarky or not…)
I did get it to work from that link so thank. Using the right Google search query definitely is helpful since when I google’d around, I didn’t find that particular topic.
Also trying to avoid making my own version of Mesh Shadow since GH’s works just fine. (and I’m essentially learning C# while making this plugin)
Anyways, here’s what worked for those curious:
object[] result = ghMeshShadow.Evaluate(new Object[] { originObject, currentSunPosition.SunVector,
planeXY }, false, out warnings);
IList<object> resultList = (IList<object>)result[0];
return (Curve)resultList[0];
This is correct. To improve this, just make sure that your lookup is not out of range. You should probably do this in a couple of lines (check that IList will work, using C# keywords as, is, or some other one, then check if there is an item [0], by checking Count.
As you noticed, there is no need to know that the returned list is Ironpython.Runtime.List. You can expect lists to be IList, or IList<object>.