Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
2

For Loop

Community Beginner ,
Nov 30, 2023 Nov 30, 2023

Copy link to clipboard

Copied

I am trying to make a grid (6 columns) as I duplicate layers, when I reach copy 7 it is positioned below the first ones. I achieved it with an if else expression but it is manual, I have to replicate the statement every 6 layers for it to repeat. "number" I added with the index of the layer.

 

a2f99ed7-056c-4d70-8154-becc99413b3c.jpg

 

basically I have the loop in javascript but I don't know how to integrate it to the Y axis position, I want the first row 1 (layer 1 to 6) to be at 5 pixels, row 2 (layer 7 to 12) to be 10 px and so on

Screenshot 2023-11-28 at 17.48.48.png

TOPICS
Expressions , How to , Resources , Scripting

Views

225
Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 2 Correct answers

Community Expert , Nov 30, 2023 Nov 30, 2023

"Math.ceil(number/6)" should give you the row number (starting with 1).

 

Hence, you want something like

5 + 5 * Math.ceil(number/6)

Votes

Translate
Community Expert , Nov 30, 2023 Nov 30, 2023

I'm not sure this formula is exactly right for your situation, but it should get you close:

numCols = 6;
n = index - 1;
col = n%numCols;
row = Math.floor(n/numCols);
x = 10 + col*5;
y = (row+1)*5;
[x,y]

Votes

Translate
Community Expert ,
Nov 30, 2023 Nov 30, 2023

Copy link to clipboard

Copied

"Math.ceil(number/6)" should give you the row number (starting with 1).

 

Hence, you want something like

5 + 5 * Math.ceil(number/6)

Mathias Möhl - Developer of tools like BeatEdit and Automation Blocks for Premiere Pro and After Effects

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 30, 2023 Nov 30, 2023

Copy link to clipboard

Copied

LATEST

I'm not sure this formula is exactly right for your situation, but it should get you close:

numCols = 6;
n = index - 1;
col = n%numCols;
row = Math.floor(n/numCols);
x = 10 + col*5;
y = (row+1)*5;
[x,y]

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines