BUG: CurveMeshIntersection (GhPython) with multiple arguments

suddenly in the last hours I have came across a Runtime Error on a grasshopper python script that has worked before. (I didn’t do any updates in between)

Somehow, the CurveMeshIntersection function doesn’t seem to work when I give it multiple arguments. The meshs and the curves are both set to “ListAccess” and to the right type. The function works perfectly with just one mesh and one curve. Does anybody has an idea what the problem could be?

“for (each) curve in x” assumes something different than you do! It does: for each item of the given list!
Your item could be a curve, but it could also be None or a PinkSausage… Who knows… It asks you later to provide a GUID or a string being parsable to GUID… But you give them two list instances as argument.

Hi Tom,

Ok that was a careless mistake, I just wrote “curve” so it’s easier to read and should have written rs.CurveMeshIntersection(curve, mesh) :smiley:
But at my script where the error accured, I still get the error. Now it seems to me, that the type of the Curve has somehow changed to Line (before I was a LineLikeCurve, I think). Can you tell me how to change the type of the curve “l” from “Line” to “Curve”? It is part of a list, so I can’t change it with the “Type hint” Option.

Thanks in advance

I found this and it seems to work:

Rhino.Geometry.Line.ToNurbsCurve(l) instead of l.

Still thank you!

You can write for curve in curves:, but then you need to really make sure that you feed in valid curves. In Python, this is a bit of a chicken-egg problem, and usually it excepts somewhere else. So in case you design the script to be used by someone else, I would simply invest some extra time and line-numbers to validate the given input and raise an exception if it’s not a curve (or a list of curves)…
Furthermore, another advice. Choose better variable names! A single letter is hard to read (except an ‘i’ within a loop). It’s especially stupid if you choose a capital I or a lower case l. Rather pick long and descriptive names. But don’t lie. If it’s curve, then call it curve. If it’s an object (of unknown type) then name it ‘object’ or ‘item’ or ‘instance’ or something similar…

Thanks for the useful tips!