This is a read-only archive of the Framer Community on Facebook.

What is Framer? Join the Community
Return to index
Ben Rodenhäuser
Posted Feb 06 - Read on Facebook

This is really more of a Sketch question, but I figured it might be relevant for other Framerists, too. I have a Sketch document with 500 layers. I would like to put each layer in a group bearing the name of the layer. I found a Sketch plugin for batch renaming, but I really need the groups (you know why). It would also be ok actually, if all the groups were just named "Group", or something like that. Any ideas how I could go about this, short of hitting Command-G 500 times? (which, on reflection, perhaps wouldn't be so bad, but still...)

8 Comments

Naema Baskanderi

I can't help, but would love to know how you figure out this problem

Ben Rodenhäuser

Well, I went with the manual Command-G solution ... but would be interesting to know if somehow this could be avoided on future occasions :)

Naema Baskanderi

oh, I was looking at sketch plugins and found one called 'Rename It' it says it's for layers I tried it on groups and it worked :) https://github.com/rodi01/RenameIt

Ben Rodenhäuser

But will it wrap layers in groups? I could not find one that does that ... Seems to be a very Framer-specific requirement.

Joshua Dickens

Try running this in the custom script menu in Sketch:

var selection = context.selection;
var doc = context.document;

function run() {
var i, l = selection.length();
for ( i = 0; i < l; i++) {
var layer = selection[i]

var parentGroup = [layer parentGroup];
if(!parentGroup) parentGroup = doc;
var newGroup = [parentGroup addLayerOfType:'group'];
newGroup.name = [layer name] ;

//create a new group and move the sublayers into it.
[parentGroup removeLayer:newGroup]
[parentGroup insertLayers:[newGroup] beforeLayer:layer]
[parentGroup removeLayer:layer]

//add the layers into the group
[newGroup insertLayers:[layer] beforeLayer:nil];
[newGroup resizeToFitChildrenWithOption:0]

}

}

run()

Ben Rodenhäuser

awesome, thanks, I will definitely try that tomorrow!

Aalok Trivedi

just tried joshua's script and it works!

Ben Rodenhäuser

Also works for me ... very cool -- thanks again, Joshua!

Read the entire post on Facebook