Problem with AddBox in RhinoScript

Hi there,

for some reason when I add a box to a Rhino document using Rhino.AddBox() and then retrieve the box using Rhino.BoxPoints(), the resulting box has reordered points. I have never noticed this before, is this new behaviour? It seems to mess up some of my older code - if there was no change, I guess I’ll have to keep searching for other reasons.

Here’s some example code:

ReDim arrBox(7)
arrBox(0) = Array(0, 0, 0)
arrBox(1) = Array(0, 1, 0)
arrBox(2) = Array(0, 1, 1)
arrBox(3) = Array(0, 0, 1)
arrBox(4) = Array(1, 0, 0)
arrBox(5) = Array(1, 1, 0)
arrBox(6) = Array(1, 1, 1)
arrBox(7) = Array(1, 0, 1)

Dim objBox : objBox = Rhino.AddBox(arrBox)

Dim arrTestBox : arrTestBox = Rhino.BoxPoints(objBox)

Dim i, j, strPoint
For i = 0 To 7
	strPoint = ""
	For j = 0 To 2
		strPoint = strPoint & arrTestBox(i)(j) & " "
	Next
	Rhino.Print strPoint
Next

The output is

0 0 1 
0 1 1 
1 1 1 
1 0 1 
0 0 0 
0 1 0 
1 1 0 
1 0 0 

The image shows the box in my original orientation, which should be valid, right?

Best,
Mathias

Hey,

just found out that this has probably always been the case - one of my colleagues had already written a workaround which I forgot to use in my current application. But is there a particular reason for this?

Best,
Mathias

This does look buggy to me:

BoxPoints
Returns the corner points of a polysurface box. Points are returned in counter-clockwise order starting with the bottom rectangle of the box.

@Dale That does not look to be the case.

–Mitch

Rhino.BoxPoints does return points in the correct order, per the documentation in the RhinoScript help file. You can verify this by doing the following:

For i = 0 To UBound(arrPts)
  Call Rhino.AddTextDot(CStr(i), arrPts(i))
Next

Once the object is determined to be a box, Rhino.BoxPoints assumes the bottom of the box is the Brep’s first face. The order in which points are returned is based on this face. In Mathias’ case, bottom of the box was determined to be the top-most face. Thus, the points are returned upside down.

In Mathias’ case, the function could do better by finding the face that was parallel with the world x-y plane. But if you rotate the box, determining what the user deems is the bottom of the box is more difficult. So, rather than get it wrong, the function leaves transforming the points to whatever is deem the base plane up to the scripter.

Orienting the box points to your correct plane quite easy:

ReDim arrBox(7)
arrBox(0) = Array(0, 0, 0)
arrBox(1) = Array(0, 1, 0)
arrBox(2) = Array(0, 1, 1)
arrBox(3) = Array(0, 0, 1)
arrBox(4) = Array(1, 0, 0)
arrBox(5) = Array(1, 1, 0)
arrBox(6) = Array(1, 1, 1)
arrBox(7) = Array(1, 0, 1)

Dim objBox : objBox = Rhino.AddBox(arrBox)
Dim arrPts : arrPts = Rhino.BoxPoints(objBox)

''''''''''
Dim arrSrc : arrSrc = Rhino.PlaneFromPoints(arrPts(0), arrPts(1), arrPts(3))
Dim arrDst : arrDst = Rhino.PlaneFromPoints(arrBox(0), arrBox(1), arrBox(3))
Dim arrX : arrX = Rhino.XformRotation(arrSrc, arrDst)
arrPts = Rhino.PointArrayTransform(arrPts, arrX)
''''''''''

Dim i, j, strPoint
For i = 0 To 7
	strPoint = ""
	For j = 0 To 2
		strPoint = strPoint & arrPts(i)(j) & " "
	Next
	Rhino.Print strPoint
Next

Hope this helps.

Hi Dale,

I always thought boxes should be ordered CCW from the lower left corner (as per the help), in your example they are ordered CW… Is this inversion because the bottom face faces downward? In any case it doesn’t seem that clear/straightforward to me…

Cheers,
–Mitch