Layer name property empty, but object exists on layer

I’m trying to delete sublayers and move objects to their own parent layers, but even if object seems to be on renamed layer, properties shows empty on selected object layer name. How to solve this problem so that layer name appears also in properties?

Here’s my code:

import rhinoscriptsyntax as rs
import Rhino

def Layers2Top(layer):
    
    children = rs.LayerChildren(layer)
    if children:
        for child in children:
            objs=rs.ObjectsByLayer(child)
            if objs:
                newName = child.replace("::",":")
                print rs.AddLayer(newName)
                rs.ObjectLayer(objs,newName)
                rs.DeleteLayer(child)
                
if( __name__ == "__main__" ):
    layers = rs.LayerNames()
    if layers:
        for layer in layers:
            if rs.IsLayer(layer):
                #print layer
                Layers2Top(layer)

layers = rs.LayerNames()
for layer in layers:

    if layer in rs.LayerNames():
        if (layer):
            if rs.IsLayerEmpty(layer):
                rs.DeleteLayer(layer)

Hello- that seems to be working as I think you expect, here -

Not sure what to suggest - does it do this with any file?

-Pascal

Now I can’t even reproduce the problem myself… But it helped me to iterate problem further. That PythonScript is called from a RhinoScript and I found some problems there. Mainly about running order of commands. So I think this “problem” is solved :slight_smile: