Annoying inconsistencies in rs.Get() methods that return points

…and auxiliary methods that use those points

We have:

rs.GetPoints()     #returns a *list* of points
rs.GetLine()       #returns a *tuple* of two points
rs.GetRectangle()  #returns an *Array[Point3d]*
rs.BoundingBox()   #returns a *list* of 8 points

Why don’t they all just return a list? Let’s see some of the issues right now:

Let’s start with line=rs.GetLine(). So you run it and click two points. it returns the tuple of your two points clicked. Now, lets say you want to re-set the start point to, say, world 0. You try:


You get: ‘tuple’ object does not support item assignment
This would not be a problem if the return was a list. Of course you can actively convert the tuple to a list to make this work, but why should that be necessary?

Next case: rect=GetRectangle()
Run it and draw your rectangle. It returns not a list, not a tuple, but an Array[Point3d]. Now, supposing I want to actually add the rectangle to the document. One can only do that with rs.AddPolyline(), and to get a closed rectangle you need five points, the last point being a duplicate of the first point.

rs.AddPolyline(rect) #works, but you only get three sides.

Of course you can close after, but it’s easier to start closed.

So, let’s try adding the last point back in in the usual way:


You get: ‘Array[Point3d]’ object has no attribute ‘append’

Yes, this works:


#or safer:

But again, why is that necessary? If it returned a list and not an Array[Point3d] it would be fine. Both rs.BoundingBox() and rs.GetPoints() return nice lists of points, why can’t the others? Is there a specific reason for that?

As a corrolary, one of the things that also annoys me is this:

rs.AddLine(line) #doesn't work because it's unable to unpack the two points

You need to do this instead:

rs.AddLine(*line) # "manual" unpack


rs.AddLine(line[0],line[1]) # manually separate the line into two arguments

That kind of stuff should just be made to work…
(end of niggle)

1 Like