https://github.com/mcneel/Rhino5Samples_CPP/blob/master/SampleCommands/cmdSampleToggleLayer.cpp
Enjoy!
– Dale