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

What is Framer? Join the Community
Return to index
Joshua Bradley
Posted Jun 21 - Read on Facebook

Hey, I'm sorry for the following potentially idiotic question... If I have an object which stores a set of dimensions like x or y, and their values, like 50 or 100, how could I loop through the object applying the dimension variable to layers (and applying a calculation to set new values)?

This might be clearer with a bit of code.

for layer in ƒƒ()
originalCoordinates =
x: layer.x, y: layer.y
for dimension, value of originalCoordinates
layer.dimension = value * scaleRatio

The last line doesn't work, and I don't have the experience to understand why. If I swap that last line for 'layer.x = value * scaleRatio' it works fine. If I console.log 'dimension' it correctly displays 'x' or 'y'. This leads me to believe that there's some kind of variable 'type'. But how to change from one type to another?

3 Comments

Trevor Phillippi

Not sure what the property "dimension" is. There is a "scale" property of layer. As well as scaleX and scaleY. You shouldn't need to capture x and y values in order to scale them all. So perhaps should be "layer.scale *= scaleRatio" inside of a single loop.

Joshua Bradley

Thanks Trevor Phillippi, I didn't know about these scale properties. I'll see if I can refine my code further. Meanwhile, 'dimension' is just the name I assign to the first column in the originalCoordinates object when I start my loop. Turned out I needed to use square brackets to get the last line before to work. Like this:

layer[dimension] = value * scaleRatio

Not sure why exactly, but I'm pretty sure it has to do with variables being strings or properties (I think the square brackets turn a string var into a property)

Trevor Phillippi

Using dot notation like Layer.dimension searches for a property called "dimension" on the object, while brackets, layer[dimension] evaluates the variable inside of the brackets, so it's as if you're doing layer["x"] or layer.x since that's what it evaluates to.

Read the entire post on Facebook