Capitalize first letter + Leave rest alone?

I have this script, and I’m trying to output the sublayers as camel-case, where the parent layer is named by the user input, and the sublayers use that string as a suffix, but capitalizes the first letter, like this (Note: the indents arent coming through, so I’m using “……”)

newElement
……crvNewElement
……lightNewElement

Seems using capitalize() and title() both return

newElement
……crvNewelement
……lightNewelement

Also, I’ll have to re-create it, but I seem to remember that before I used the color settings, it worked fine. Hm…
Thoughts?

addLayerAsTree_v01.py (899 Bytes)

this seems to work:

import rhinoscriptsyntax as rs
from System.Drawing import Color

new_element = rs.GetString("New Element?")


rs.AddLayer(new_element)
new_element = new_element[0].upper()+new_element[1:]
rs.AddLayer("crv"+new_element, Color.Red, parent=new_element)
rs.AddLayer("bbox"+new_element, Color.Gray, parent=new_element)
rs.AddLayer("light"+new_element, Color.Cyan, parent=new_element)
rs.AddLayer("glass"+new_element, Color.FromArgb(25, 105, 105, 105), parent=new_element)
rs.AddLayer("sol"+new_element, Color.Green, parent=new_element)
rs.AddLayer("ref"+new_element, Color.Black, parent=new_element)
rs.AddLayer("SM_"+new_element, Color.White, parent=new_element)

layers = rs.LayerNames(new_element)
if layers:
    for layer in layers:
        black = rs.CreateColor((0,0,0))
        if rs.LayerPrintColor(layer)!=black:
            rs.LayerPrintColor(layer, black)

source:

Ah, thank you. I’ll try that.

I’ll look it up using that form, but what if theres an unknown number of words strung together? Like:

newIntVehicleElement

it shouldn’t matter, it just takes the first letter and capitalizes it, then pastes the rest of the string to it.

1 Like

Perfect, thank you!

FWIW when you want to maintain indentation in text you post here on Discourse you can give it as a code block. Enclose it in tripple backticks or in tripple tildes

text
  with
    indentation
      using
        tripple backticks

and

more
  indented
    text
this
  time
    with
      tripple tildes
1 Like

That’s “trippple” - you need three p’s
Doubble only needs two b’s
:stuck_out_tongue_winking_eye:

3 Likes