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

What is Framer? Join the Community
Return to index
Arvi Raquel-Santos
Posted Jun 17 - Read on Facebook

I have the same properties for a few elements. I assume I can write an array that will apply the same property to a number of elements? If so, how would I write that? I tried this but doesn't work...

myLayers = [layer1, layer2, layer3]
myLayers.opacity = .5

Any help would be great, thanks!

18 Comments

Jordan Robert Dobson

You could also set one and use layer1.copy()

Jordan Robert Dobson

for layer in [l1,l2,l3]
layer.opacity = .5

Jordan Robert Dobson

Either approach should work.

Arvi Raquel-Santos

ah.. OK. I didn't think I need to say "for layer..." thanks!

Jordan Robert Dobson

You need to loop over each one with a For loop.

Jordan Robert Dobson

for number in [90,87,1,6]
print number + 5

Andreas Wahlström

If you have a lot of layers sharing the same properties you can group them in sketch and access them by Group.subLayers. Sometimes restructuring isn't possible, though. For these cases you might want to target them with a common keyword using https://github.com/awt2542/Layers-for-Framer

Giovanni Caruso

Jordan Robert Dobson is there a way to target all the elements of a given array, except one? Example:

arr = [layerA, layerB, layerC]

for i in arr
i.on Events.Click,->
#all the items get opacity = 0 except "this"

Jordan Robert Dobson

Yep.

I.opacity = 0 unless layerB

Giovanni Caruso

is it that easy? no way! ... let me try!!! :)

Jordan Robert Dobson

Oops!

Jordan Robert Dobson

i.opacity = 0 unless i is layerB

Giovanni Caruso
Giovanni Caruso

....found the problem: "i.opacity = 0 unless @ is layerB"

Jordan Robert Dobson

Oh yeah. Gotta keep the context.

Jordan Robert Dobson

Awesome. Glad you got it.

Giovanni Caruso

Thanks for your help!!! :)

John Lee

Andreas Wahlström This is a beautiful piece of code: https://github.com/awt2542/Find-for-Framer
I might use it in my best man speech – it's that damm good!

Read the entire post on Facebook