Hi, I struggle with using infinity symbol in python.
I can paste/type it directly into a text object in rhino with out problems, but python seems to struggle with it, does anybody know a workaround?
I explode a curve and checks the parts and then adds text that I later on move into position.
(Right now I use two o’s as infinity)
partradius = rs.CurveRadius(parts[i],midpoint)
# Add text
# If curve segment is straight then CurveRadius return None
if partradius:
text = rs.AddText("R="+str(int(round(partradius,0))), (0,0,0), 2.25, 'Verdana', 0, 2)
else:
text = rs.AddText("R=oo", (0,0,0), 2.25, 'Verdana', 0, 2)
You could also just use inf, which is a pretty normal thing to use at least in the programming world. In Python 2.7 (IronPython) you say for instance float('inf') :
I wonder if this is a locale thing where the default locale is using ascii encoding? Running the command print("∞") in the Rhino 7 python editor throws an ascii error. If you import the locale module and set the locale to use UTF-8 maybe you can get further (I haven’t tested this).
That command runs fine in Rhino 8 with Python 3 by the way.
EDIT: Unfortunately you cannot set the locale to use UTF8 in Iron Python 2.7 - possibly because it predates the availability of that feature in Windows 10 onward. Python 3 works fine.
And using repr() to print the character in 2.7 gives you the unicode string, not the glyph. The unicode is recognised and can be interpreted correctly, just not displayed as the glyph.
Thanks for the help guys, the reason I need it is that we are working on road drawings and there the correct way is to use the infinity symbol and oo works, but isn’t correct.
FWIW, the IronPython component in R8 grasshopper (using IronPython 2.7.12) seems to handle ∞ just fine. I don’t have access to R7 to test anything there.
Addendum: Here’s an example using RhinoScriptSyntax instead of RhinoCommon - note that the two AddText commands have different syntax. WritingInfinityWithRS.py (164 Bytes)
Yeah, we’ve established that rs.AddText() will write unicode on the canvas. But in your post above you show print() placing the Infinity glyph on the Python Editor Output panel. Nobody else has done that yet (and the R= ouside the u-string makes no difference), so I’m interested in what is different about your setup. One possibility is locale as you are in Switzerland. What does this Python code output: import locale as l print(l.getdefaultlocale())
?
OK, it isn’t the obvious locale setting (en_CH isn’t recognised as a valid locale in my Windows, and isn’t supported in Python 2.7, so I can’t set my locale to that), but I was able to replicate @Helvetosaur’s result in the Output panel by changing a well-hidden windows setting. Although it isn’t necessary for writing Unicode to the Rhino canvas, here for interest is how to do it for the Output panel, in Windows 10.
Go to Language settings and select Administrative language settings
You should now be able to see Unicode in the Output panel. But this is a system-wide setting so there is the possibility you will break something elsewhere…