This isn’t the prettiest solution, but it works without showing any error messages if a layer already exists (at the Layer.Create node) or if it doesn’t exist yet (at the Document.LayerByName node).
Thoughts? Perhaps someone else has a cleaner, easier to follow solution
It does, I’m sure they can be later adjusted in the script. I don’t know how many layers do you have, if you have many layers with large variety of settings this isn’t optimal.
For me it was convinient, because it made it possible to rerun the script in Player as it deletes all objects as well, so recreates layer and also the objects and then sets colors and maybe visibibility, if I remember correctly. But this is about 10 or so layers.
EDIT: Nevermind I’m stupid and I lied. I remembered deleting the layers, but I only delete the objects. So that way new layers are created if needed by the Object.ByGeometry node and I do the settings later. Sorry.
I’m pretty sure the Arkance Systems Node Library contains a node to create a layer or return the existing one. Maybe Camber too.
Keep in mind if you use the API in, for example, Python, a deleted layer still remain until the drawing is closed. A check for an existing layer will return a false positive. In that case you need to check if a layer is deleted if the API claims it exists.