C# Script to Export to Colored Layers from Grasshopper without Baking

There is the Rhino.FileIO namespace (rhino3d.com) allowing you to e.g. create a 3dm file in memory and write it to disk.
This should allow you to write geometry to that file with attributes (including layers, color etc.).
There are already a few topics about that, which may give some more input on this:
Write a 3dm file with c# in Grasshopper - Grasshopper Developer - McNeel Forum

Exporting grasshopper geometry to rhino file without baking it - Grasshopper - McNeel Forum

If I understand you correctly, this should also give you what you want, without needing to rely on a Rhino command and likely also avoid the problems/bugs you ran into.

1 Like