Obscure V6 Rhinoscript bug

I have been noticing this for awhile now, but didn’t have time to investigate. Finally I was able to make an repeatable example, so I though I’d report it anyway.

The problem - I had an old Rhinoscript that I used to select all objects of the same color - why it’s still in my workspace, I don’t know, as SelColor works fine to replace it - but that is actually how I discovered the bug…

In the V6 file below, there are 3 layers, each with the same set of colored squares. Two of the layers are off. There is no history relation or grouping between the objects. You can turn on the two layers to verify that they are indeed the same as the first, then turn them off again.

SelColorBug.3dm (406.3 KB)

Now, select one or two of the colored squares and then run the following Rhinoscript:

	Option Explicit
Call SelSameColor()
Sub SelSameColor()
	Dim arrObjs,color,i
	arrObjs = Rhino.GetObjects("Pick objects with colors to select",,, True)
	If Not IsArray(arrObjs) Then Exit Sub
	ReDim arrColors(Ubound(arrObjs))
	For i=0 To Ubound(arrObjs)
		color = Rhino.ObjectColor(arrObjs(i))
		Call Rhino.ObjectsByColor(color, True)
End Sub

All of the same colored squares as those originally selected will get selected. Now, while they are selected, press the Hide button in Rhino to hide them. They disappear. Now, turn on the two layers that are off. You will note that, although those layers were off when the Hide button was pressed, the squares are also hidden on those layers! So Rhino’s native Hide ended up working on objects that were not “visibly selected”. That is the bug.

Now, you can try the same thing in the V5 equivalent file below.

SelColorBugV5.3dm (331.4 KB)

It behaves as expected in V5, objects on off layers are not affected. In V6, you can also try with the Python script below which is the equivalent of the first one, that also does not affect objects on off layers. The native Rhino SelColor also behaves correctly.

import rhinoscriptsyntax as rs

def SelSameColor():
    msg="Pick objects with colors to select"
    objs = rs.GetObjects(msg,preselect=True,select=True)
    if not objs: return
    for i in range(len(objs)):
        color = rs.ObjectColor(objs[i])
        rs.ObjectsByColor(color, True)

I’m only reporting this because it indicates that there might be a bug in how Rhinoscript selection is hooked up in this case, which might affect other people’s scripts… FWIW - @dale

1 Like