Null layers when reloading a model

I’ve been working around this problem that I have for a while but I thought I’d see if anyone know how to fix it properly today! Simplest scenario listed

If I start Rhino with a particular model and call a RhinoCommand that does this:

Rhino.DocObjects.RhinoObject[] rhobjs = _doc.Objects.FindByLayer(“whatever”);

Then I get a bunch of objects back.

If I maintain the same Rhino session but reload the model. Same layers and same objects, I then get “null” for the same call. It can’t find the layer. What can I do?

It’s not a typo, it’s definitely the same model with the same layers.

Is your _doc variable pointing to the right document, i.e. the re-loaded one?

ah gosh. I bet that’s it. I’m so stupid. Thank you.

Happens to me all the time, don’t feel bad :slightly_smiling_face: