Separating shapes into another layer

Hello there!

Not sure if this has been mentioned before. Is there a tool or python script where you can select some shapes in a layer with tracking information and help move the shapes into a duplicated layer with the same tracking information but only storing the shapes selected.

@EugeneMatthew
There is not currently a way to do this. I’ll add a request for this.

So you want to “bake” the tracking data into the shapes so you no longer need the layer transform?

Eugene can clarify when he is around later, but I read this as:
Duplicate the layer using only the selected shapes. Tracking data is duplicated and shapes are not baked.

Ah, understood!

Eugene, paste this code into the Silhouette Script Editor, select some shapes, and press the Execute button. This script does this:

  1. finds the top-level root Layer for all selected shapes (but only for shapes that share the first root layer found)
  2. duplicates that layer, deleting all of its duplicated child objects
  3. inserts clones of the selected shapes into the layer
  4. adds the layer to the current node

Note this only works if the active node supports child objects.

from fx import *

# find the root layer of a selected object
def get_root_layer(object):
	parent = object.parent
	if parent.isType("Node"):
		if object.isType("Layer"):
			return object
		return None
	return get_root_layer(object.parent)

# enumerate root layer and selected objects to be copied
objects = []
root_layer = None
for s in selection():
	layer = get_root_layer(s)
	if s != layer:
		if not root_layer:
			objects.append(s.clone())
			root_layer = layer
		elif layer == root_layer:
			objects.append(s.clone())

# clone root layer
new_layer = root_layer.clone()
new_layer.label = uniqueLabel(new_layer.label)

# delete all of its children
new_layer.property("objects").removeObjects(new_layer.children)

# add copied objects to layer
new_layer.property("objects").addObjects(objects)

beginUndo("Copy Selected Layer Children")
activeNode().property("objects").addObjects([new_layer])
endUndo()
2 Likes

Yep @marco is correct. Just want to separate the shapes into another layer with tracking information and the shapes are not baked :slight_smile:

Oh wow, nice!! I’ll try this out. Thank you so much!

I guess it works if the shape is in the parent layer. The moment the shape is in a nested layer, it’ll copy the shapes to the parent layer and wont follow the hierarchy and miss the nested layer that has the tracking information. Other than that, it works perfectly :slight_smile:

I assumed your tracking data was in the root layer. But it can be changed to preserve the layer hierarchy by cloning the root layer(s) and deleting anything in them that wasn’t selected. Unfortunately, that’s a bit more complicated.