Wish: Make New Layer - Shortcut able?

can we please finally add a command to make a new layer without getting a doctor? i think it is somehow possible to make a macro and program it to go through the gazillion of options to do just that, but i am getting hair loss by just trying… such a simple task should not be so difficult.

and please add the option to make this new layer the current. not sure how that should even be possible in the current syntax to add a new entered name which then will be made current each time i initiate the command anew.

any thoughts? other options?

-Layer New EnterEnd

That would require a script.
-wim

1 Like

No doctors needed when there’s chatgpt that can do the work.

import rhinoscriptsyntax as rs

def create_and_set_layer():
    # Specify the base layer name
    base_layer_name = "YourLayerName"

    # Check if the layer already exists
    existing_layers = rs.LayerNames()
    index = 1
    new_layer_name = base_layer_name

    while new_layer_name in existing_layers:
        # If the layer already exists, add a numerical suffix
        index += 1
        new_layer_name = "{}{}".format(base_layer_name, index)

    # Create a new layer
    new_layer = rs.AddLayer(new_layer_name)

    # Check if the layer was created successfully
    if not new_layer:
        print("Error creating layer!")
        return

    # Set the new layer as the current layer
    rs.CurrentLayer(new_layer)

    # Optionally, print a message to confirm
    print("New layer created and set as current:", rs.LayerName(new_layer))

# Run the function
create_and_set_layer()
import Rhino
import scriptcontext as sc
import System.Drawing.Color

def AddLayer():
    # Cook up an unused layer name
    unused_name = sc.doc.Layers.GetUnusedLayerName(False)

    # Prompt the user to enter a layer name
    gs = Rhino.Input.Custom.GetString()
    gs.SetCommandPrompt("Name of the layer to add")
    bool_option = Rhino.Input.Custom.OptionToggle(True, "Off", "On")
    gs.AddOptionToggle("SetCurrent", bool_option)
    gs.SetDefaultString(unused_name)
    gs.AcceptNothing(True)

    while True:
        get_str = gs.Get()
        if gs.CommandResult() != Rhino.Commands.Result.Success:
            return gs.CommandResult()
        if get_str == Rhino.Input.GetResult.String:
            break

    # Was a layer name entered?
    layer_name = gs.StringResult().Trim()
    if not layer_name:
        print("Layer name cannot be blank.")
        return Rhino.Commands.Result.Cancel

    # Is the layer name valid?
    if not Rhino.DocObjects.Layer.IsValidName(layer_name):
        print(layer_name, "is not a valid layer name.")
        return Rhino.Commands.Result.Cancel

    # Does a layer with the same name already exist?
    layer_index = sc.doc.Layers.Find(layer_name, True)
    if layer_index >= 0:
        print("A layer with the name", layer_name, "already exists.")
    else:
        # Add a new layer to the document
        layer_index = sc.doc.Layers.Add(layer_name, System.Drawing.Color.Black)
        if layer_index < 0:
            print("Unable to add", layer_name, "layer.")
            return Rhino.Commands.Result.Failure
    
    if bool_option.CurrentValue:
        sc.doc.Layers.SetCurrentLayerIndex(layer_index, False)
    return Rhino.Commands.Result.Success

if __name__ == "__main__":
    AddLayer()

NewLayer.py (1.8 KB)

that is a real essential function which is used very very often. a right click wait till pop up then left click to add a new layer is very slow and tedious. or having a huge list of layers then navigating to the upper part of that panel where it is now to add a new layer to navigate back with the mouse to the layer in case i have to change material color and what not is also not adding any health beneficials to my wrist, plus its not fast either.

something like ctrl/cmd alt n to make it fast. any other thoughts?