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

What is Framer? Join the Community
Return to index
Taylor Palmer
Posted Apr 27 - Read on Facebook

Hi all, I have a Sketch file with multiple layers with the same name "card", but Framer brings them in as card1, card2, etc. This prevents me from being able to select them all with sketch.childrenWithName("card"). What's best practice here, without renaming all of them individually?

12 Comments

Dave Crow

Not sure how your sketch file is structured, but is it possible to group the card layers in Sketch and then reference them with sketch.cardGroup.children?

Taylor Palmer

Hey Dave Crow, they're actually children of separate groups that I need for functionality. Take a look at the structure here:

Dave Crow

So which layers are you wanting to target?

Taylor Palmer

At different times I want to target all of the "options" layers or all of the "artwork" layers

Nick Simonson

Simplest way would be to hard code the layers into an array and loop over them when you need to.

Celeste DeMartis

For layer in sketch.options.children ->

Dave Crow

Ditto. I think hard coding an array is the way I'd go.

Kevin Mao

Just ran into this annoying problem. I thought it only happened when importing from Figma.

I did something like this (underscores are whitespace):

for layer in sketch.cards.descendants
__ if layer.name.startsWith('options')
____ #dosomething
__ if layer.name.startsWith('artwork')
____ #dosomethingelse

Not sure if that's a better way than hard coding an array, but it worked for what I needed!

Andreas Wahlström

You can give this module a try: https://github.com/awt2542/Find-for-Framer

Taylor Palmer

Thanks Andreas Wahlström I had used that before but forgotten about it!

The problem with hardcoding the array is that is takes just as long as renaming the layers. What if there were 100 of them? Not scalable.

Nicolai Doreng-Stearns

Populate your arrays with the function Kevin Mao wrote above

Justin Ma

If you're trying to target "personaCard" & "personaCard1", you could do that with a for loop?

eg. for card inside cards.subLayers. That should return personaCard, and personaCard1. If that sounds like it's what you're looking for, I wrote an article about how I do this with sketch and framer here : https://blog.prototypr.io/using-for-loops-to-power-up-your-framer-prototype-7e37c63412d2

Read the entire post on Facebook