I’m doing a lot of copy/paste history and getting annoyed that something in the history chain wasn’t selectable. I’m rusty with python, but ChatGPT helped me out a bit. It got a few things wrong, like not knowing about scriptcontext.sticky[ ... ] (used doc user text), but all in all, it was actually helpful.
There are four scripts:
- AllSelectable.py - turn on/unlock all layers, then _Show/_Unlock. It saves the existing state.
- SelAllParents.py - Pick what you want to copy, and it will find all its parents and isolate them. You can manually hide things you don’t want to be included in the next step.
- CopyWithHistory.py - Copies it to the clipboard, hides the original, pastes, and selects objs without history. This lets you move the pasted stuff to a new location.
- You also have the option to change layer names. This lets you copy something from layer X and paste to layer Y.
- UndoAllSelectable.py - Restores the original selectability of things before you ran AllSelectable.py
First, there is a shared ‘eLib.py’ to share between all the scripts:
import rhinoscriptsyntax as rs
import scriptcontext as sc
layerStatesKey = "layerState"
hiddenObjsKey = "hiddenObjs"
lockedObjsKey = "lockedObjs"
class LayerState:
def __init__(self, layerId, visible, locked):
self.layerId = layerId
self.visible = visible
self.locked = locked
class LayerName:
def __init__(self, layerId, oldName, newName):
self.layerId = layerId
self.oldName = oldName
self.newName = newName
def removeLayerParents(layerName):
nameParts = layerName.split("::")
return nameParts[-1]
def renameLayer(oldName, newName):
modNewName = removeLayerParents(newName)
rs.RenameLayer(oldName, modNewName)
5 posts - 1 participant