As of Rhino 8.5 If i call ToList() on the ObjectTable i am seeing as many nulls as i have objects on reference layers. Example script below:
using System;
using Rhino;
using System.Linq;
using Rhino.Geometry;
using Rhino.DocObjects;
var doc = RhinoDoc.ActiveDoc;
// create reference layer
int layerId = doc.Layers.AddReferenceLayer(new Layer { Name = "Ref"});
// add object
var circle = new Circle(50).ToNurbsCurve();
doc.Objects.Add(circle,new ObjectAttributes {LayerIndex = layerId});
// BUG? this list now contains a null?
var obs = doc.Objects.ToList();
Console.WriteLine("NULLS ="+obs.Count(o => o == null));
// yet this does not
Console.WriteLine("NO nulls="+doc.Objects.Count(o => o == null));
foreach (var item in doc.Objects) {
// nor does this fire ?!?
if (item == null) Console.WriteLine("Null found");
}
Has this always been the behaviour? Is it intended? or is it a regression?
System info attached, no plugins are loaded. systeminfo.txt (2.3 KB)
@dale use the attached grasshopper script in a new document. Just opening it will add a layer and circle on that layer. Except on that very first run doc.Objects.ToList() gives a list with just one null entry instead of the actual object.
.ToList returns an empty list. (same as new List<T>() );. This is standard LINQ behavior.
The default ObjectTable enumerator only searches for active objects - object are in the document. In your case, you are adding fake reference objects. So when the ObjectTable is enumerated, nothing is returned, thus the empty list.