Assigning layers in a Worksession environment. Bug?

Hi,

I’ve been using scripts in an Worksession environment. If I try to create a layer name in the active Document, which already exists in an “not active” file, it is not created. Also layer assignment does’t always work correctly.

I didn’t get to the bottom of the problem yet, but there is some issue there. Currently I’m working with Python an VB Scripts in Parallel. (one after the other).

Also I don’t have time to really track it down right now and report the error thoroughly. Just posting it now, so I don’t forget to post it.

Thanks
Martin

Details would be helpful. Do you a simple script that demonstrates your problem

Hi Dale,

please find attached a Zip File with a dummy worksession and a simple script file.

I believe the problem is the “IsLayer” function.

The way I would believe the “IsLayer” function should return “True” if the layer doesn’t exist in the current/active document opposed to existing in the current worksession.

Thanks
Martin

LayerProblem.zip (21.7 KB)

Try this:

import rhinoscriptsyntax as rs

def IsLayerInActiveDocument(layer_name):
    if not rs.IsLayer("myParent"):
        return False
    if rs.IsLayerReference(layer_name):
        return False
    return True

def main():
    
    rs.AddLayer("ScriptLayer1")
    
    parent = "myParent"
    if not IsLayerInActiveDocument("myParent"):
        parent = rs.AddLayer(parent)
        
    child = rs.AddLayer("myChild", None, True, False, parent)
    pt_id = rs.AddPoint([0,0,0])
    rs.ObjectLayer(pt_id, child)