could someone be so kind to modify this script that it work on Rhino 5 sublayers too? This script allow to add Pre- and Suffixes to layer names.
Ciao,
Micha
_-Runscript (
Option Explicit
Call LayerPrefix()
Sub LayerPrefix()
Dim arrAllLayers, arrSelLayers, strLayer, strPrefix, strSuffix
arrAllLayers = Rhino.LayerNames
arrSelLayers = Rhino.MultiListBox(arrAllLayers,“Select layers to rename:”,“Rename Layers”)
if isnull(arrSelLayers) then Exit Sub
strPrefix = Rhino.GetString(“Prefix? (ENTER to skip)”)
if isnull(strPrefix) then Exit Sub
strSuffix = Rhino.GetString(“Suffix? (ENTER to skip)”)
if isnull(strSuffix) then Exit Sub
if strPrefix="" and strSuffix="" then Exit Sub
for each strLayer in arrSelLayers
if not Rhino.IsLayer(strPrefix & strLayer & strSuffix) then
Call Rhino.RenameLayer(strLayer, strPrefix & strLayer & strSuffix)
end if
Next
Hi Micha- this seems to handle the nesting correctly- does that do what you need?
_-Runscript(
Option Explicit
Call LayerPrefix()
Sub LayerPrefix()
Dim arrAllLayers, arrSelLayers, strLayer, strPrefix, strSuffix
arrAllLayers = Rhino.LayerNames
arrSelLayers = Rhino.MultiListBox(arrAllLayers, "Select layers to rename:", "Rename Layers")
If isnull(arrSelLayers) Then Exit Sub
strPrefix = Rhino.GetString("Prefix? (ENTER to skip)")
If isnull(strPrefix) Then Exit Sub
strSuffix = Rhino.GetString("Suffix? (ENTER to skip)")
If isnull(strSuffix) Then Exit Sub
If strPrefix = "" And strSuffix = "" Then Exit Sub
Dim arrID, aNames, n, i, Bound
Bound = UBound(arrSellayers)
n = 0
ReDim arrID(Bound)
ReDim aNames(Bound)
For Each strLayer In arrSelLayers
arrID(n) = Rhino.LayerId(strLayer)
aNames(n) = strPrefix & GetShortName(arrID(n)) & strSuffix
n = n + 1
Next
For i = 0 To n - 1
Call Rhino.RenameLayer(arrId(i), aNames(i))
Next
End Sub
Function GetShortName(ID)
Dim sLayer: sLayer = Rhino.LayerName(ID)
'Return the short layer name from a full nested layer path.
Dim intLast: intLast = instrRev(sLayer, chr(58) & chr(58))
If intLast = 0 Then
GetShortName = slayer
Exit Function
End If
GetShortName = Right(slayer, len(slayer) - (intLast + 1))
Rhino.Print Right(slayer, len(slayer) - intLast)
End Function
)