@ectapia wrote:
Hey all, I am new to Rhino Python and am looking for an easier way to do a painful task in Rhino. I am currently using Rhino 6 (we just upgraded from 5) to design aluminum ships. We need the ability to rename multiple layers (parent or child) to a specific name. I have been using the Python script I found from Steve Baer (FROM HERE)which works great if you only need to rename 1 layer. I have searched for days trying to piece this together and would love for someone to take a look and see if there is a better way. I have close to 500 “OldName” “NewName” instances in about 500 individual .3dm files.
Here is my current working script…
import rhinoscriptsyntax as rs from scriptcontext import doc def rename(): layerName = ("OLDNAME") matchingLayers = [layer for layer in doc.Layers if layer.Name == layerName] layerToRename = None if len(matchingLayers) == 0: return if len(matchingLayers) == 1: layerToRename = matchingLayers[0] elif len(matchingLayers) > 1: i = 0; for layer in matchingLayers: print "({0}) {1}".format( i+1, matchingLayers[i].FullPath.replace("::", "->")) i += 1 selectedLayer = rs.GetInteger( "which layer?", -1, 1, len(matchingLayers)) if selectedLayer == None: return layerToRename = matchingLayers[selectedLayer - 1] layerName = ("NEWNAME") layerToRename.Name = layerName layerToRename.CommitChanges() return if __name__ == "__main__": rename()After this is done, I start it over with the next “Old / New” names.
I have an excel .xlsx file but can’t figure out how to get it to open, then lookup the correct old name and replace it with the correct new name.
As you can see below, our layer structure
Im not sure it is even possible, but would love to be able to run this one time and it opens all files in a folder, runs the script, saves, and opens the next file.
I appreciate any advice you may have,
Thanks.
Emanuel T.
Posts: 1
Participants: 1


