Highlighting objects on a layer

This approach doesn’t work. Can anyone explain why?

                            doc.Objects.FindByLayer(doc.Layers[LayerId]);
                            doc.Views.Redraw();
                            MessageBox.Show("That layer already exists.  Parts on it have been hilighted,");

What are you trying to do? Or, what do you think this code should do?

It should select everything on the layer doc.layers[LayerId] and highlight them.

A little more work is involved, as FindByLayer returns a list of objects. But you still need to iterate the list and select them.

Here is some code you can use as an example.

https://github.com/dalefugier/SampleCsCommands/blob/master/SampleCsSelectLayerObjects.cs