i am trying to re-write a script from ironpython for python3:
obj = rs.GetObject()
if rs.IsPolyline(obj):
points = rs.PolylineVertices(obj)
if points:
for k, point in enumerate(points, start=0):
x = str(point[0])
y = str(point[1])
z = str(point[2])
When i run the script i get this error:
In ironpython this script will just work fine. Looks to me that something is going wrong with the Curve.TryGetPolyline method (rhino3d.com) or the rhinoscriptsyntax, or do i miss something?
Does anyone have an idea how i can work around this?
i am trying to re-write a script from ironpython for python3:
If it ain’t broke…
Does anyone have an idea how i can work around this?
If there is a good reason to risk introducing new bugs into what you’ve already got, and to overcomplicate your workflow, e.g. a speed up or a cPython only library etc. is required, then I would use Grasshopper and restructure the code into two different components that both do what they’re good at, and e.g. pass a simple list of the x, y and zs between them, so that only whatever you need the co-ordinate list for happens in a Python 3 component (which could even be less efficient, if it has to deal with Rhino .Net objects), and a good old Iron Python component, that can still do what it’s great at, and is tried and tested for - working with .Net and the Rhino and Grasshopper APIs.
Even if you simply want to retire your Iron Python code, there’s even bound to be a native Grasshopper component that extracts the numerical co-ordinates from a polyline.
You can still run IronPython 2.7 files in V8 by putting #! python 2 at the top of the script. You can force Python 3 by putting #! python 3 at the top.
I have a lot of existing Py2 scripts called by aliases/toolbar buttons that do not have #! python 2 at the top, and they run, so I have a feeling Py2 is run by default.
However, he is using a rhinoscriptsyntax method, not RhinoCommon directly, and it is failing because of this. Is this going to be a general problem? Most RhinoCommon methods are overloaded, if this happens frequently then it will invalidate a lot of rhinoscriptsyntax methods…
I expected the rhinoscriptsyntax to be updated and compatible with pypthon3. From what i have gasped, python3 is supposed to be the future in Rhino since it offers a lot of benefits and maintained external libraries.
@James_Parrott - Just to make clear, the code is just a sample so that anyone can run the script on his own. My original script is much larger then this. I am not just copying the script from 2.7 to 3, but also modify some of the script. The main reason for choosing python3 is that i want to use the pip installer and bridge the new editor with VisualStudioCode.
For now I will try to circumnavigate the problem by using RhinoCommon directly in my script. I hope the suggested Strongbox from @eirannejad will work. Still, I feel this kind of problem should be adressed.
You can still run IronPython 2.7 files in V8 by putting #! python 2 at the top of the script. You can force Python 3 by putting #! python 3 at the top.
I have tried to run the script with #! pyton 2 at the top, but this raises the some error as well
Please post them or send them directly to @eirannejad . There may still be some unresolved bugs concerning getting code to run specifically in Py2 or Py3.
I agree. IronPython behaved differently and automatically chooses the overload with least number of out parameters. I modified Python 3 method resolver to do the same.
The fix should be in Rhino 8.5 next week. The ticket below has more info documented on this issue:
RH-80838 rs.PolylineVertices needs StrongBox | Pythonnet to use overloads with least out params