Is there a Python version of Pt2Str?

In Rhinoscript I was able to display a point in a textdot, rounded to a specific number of decimal places. Like this:

Call Rhino.AddTextDot(Rhino.Pt2Str(arrPoint, 3), arrPoint)

In Python, I see that this method is gone. I tried the following, but the displayed points are surrounded with parenthesis, which I don’t want. Here is my code:

import rhinoscriptsyntax as rs
def AnnotatePoint():
arrPoint = rs.GetPoint(‘Select a point to identify’)
if arrPoint is None: return
strPoint = round(arrPoint[0],3), round(arrPoint[1],3), round(arrPoint[2],3)

if name == ‘main’:

What is the preferred method for rounding values in a list? Am I on the right track? What should I be doing as an alternative to the Rhinoscript Pt2Str method?



HI DanBayn,

strPoint = str(round(arrPoint[0],3)) + “,” + str(round(arrPoint[1],3)) + “,” + str(round(arrPoint[2],3))

Perfect, thanks Miguel.


python string formatting also supports rounding. You could do something like:

strPoint = "{0[0]:.3f}, {0[1]:.3f}, {0[2]:.3f}".format(arrPoint)

If you don’t care about rounding, you can just do

strPoint = str(arrPoint)

Wow! I would never have figured that out on my own. Steve, do you have a reference book that you could recommend that would help with questions like this? I’ve been reading as much as I can online, but I don’t recall ever seeing this string formatting.



Not really; if you want a book I would just get the highest recommended one on Amazon for basic python.