RhinoInside.Revit Baking geometry to layer with Python

Hi there,

I know this has been discussed more than often in the forum, but I am not able to solve this problem.

I want to bake a lot of geometry on different layers in a GH-Pyhon node.
First I create layers in my rhino-document.
Then I get the geometry from grasshopper.
And this I am perfectly able to bake.

But when I want to assign a layer - and it exists in the RhinoDocument - it says:
Runtime error (ValueErrorException): Geschossdecken does not exist in LayerTable

Any help highly appreciated,

import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino
import System.Drawing

sc.doc = Rhino.RhinoDoc.ActiveDoc

for p in layerpool:
    if rs.IsLayer(p) == False:
        clr = layercolors[layerpool.index(p)]
        rs.AddLayer(p, color = clr)

for rawgeo in geos:
    sc.doc = ghdoc
    doc_obj = rs.coercerhinoobject(rawgeo)
    geo = doc_obj.Geometry
    sc.doc = Rhino.RhinoDoc.ActiveDoc
    lyr = layers[geos.index(rawgeo)]
    id = sc.doc.Objects.Add(geo)
    rs.ObjectLayer(id, layer=lyr)

Climate Studio plug-in does this

@Gregor_Ruta thanks for the input.
I also know that some plugins provide this option.

I just would like to understand how to achieve this though.