RhinoScript function for adding layers

I’ve written a Rhinoscript function that I can call repeatedly to create a standard layer hierarchy. What I want to happen is to identify if the layer already exists, and just skip it in that case. It works the first time I call it PERFECTLY, but if I run it again and the layer I want to create already exists, it fails with an weird error on the Rhino.Addlayer line. I tried adding a Rhino.IsLayerChildOf command just before to see if the layer already exists under the parent, but then that line errors instead. I expected AddLayer to return a null if it fails, but instead it fails in the interpreter. I’d rather not use “On Error”, but I can’t see how to make this work any other way.

strFullLayerTreeName = Rhino.Addlayer(strLayerName, lngColor, True, False, strParentLayerID)

Hello - can you post a bit more of your code so we can better see what you’re doing?


If not Rhino.IsLayer(layername) Then Rhino.AddLayer(layername)

I figured it out. The calling routine was sending a null for strParentLayerID if it already existed instead of being created.