Selecting specific textIndex

Explorer ,
May 24, 2022 May 24, 2022

Copy link to clipboard

Copied

Hello,

how do I simplify and optimize the code below? As you can see I would like to affect every 6th character starting with #2 when the length of the text is not predetermined. Thank you in advance.

 

if(textIndex == 2 || textIndex === 8 || textIndex === 14 || textIndex === 20 || textIndex === 26) {

     100;

} else {

     0;

}

TOPICS
Expressions , How to

Views

238

Likes

Translate

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

Adobe Community Professional , May 24, 2022 May 24, 2022

Like this maybe:

textIndex%6 == 2 ? 100 : 0

Likes

Translate

Translate
Adobe Community Professional , May 24, 2022 May 24, 2022

Like this I guess:

n = thisProperty.propertyGroup(3).name%6;
textIndex%6 == n ? 100 : 0

Likes

Translate

Translate
Adobe Community Professional ,
May 24, 2022 May 24, 2022

Copy link to clipboard

Copied

textIndex % 6 + 2

 

Mylenium

Likes

Translate

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
Explorer ,
May 24, 2022 May 24, 2022

Copy link to clipboard

Copied

Thank you.

When I replace 

(textIndex == 2 || textIndex === 8 || textIndex === 14 || textIndex === 20 || textIndex === 26)

with

(textIndex % 6 + 2)

the effect is not the same.

Attached is the screenshot of what I am trying to achieve and it is working with my expression, but I would just like to simplify it so I can automate different scenarios. 

 

 

Likes

Translate

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
Adobe Community Professional ,
May 24, 2022 May 24, 2022

Copy link to clipboard

Copied

Like this maybe:

textIndex%6 == 2 ? 100 : 0

Likes

Translate

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
Explorer ,
May 24, 2022 May 24, 2022

Copy link to clipboard

Copied

Thank you so much, that works!!!

Likes

Translate

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
Explorer ,
May 24, 2022 May 24, 2022

Copy link to clipboard

Copied

Hi Dan,

any ideas why when it comes to the 6th row it doesn't work?

so 

textIndex%6 == 6 ? 100 : 0

is not working (no errors) but doesn't do anything. Thank you

Likes

Translate

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
Adobe Community Professional ,
May 24, 2022 May 24, 2022

Copy link to clipboard

Copied

Ah, OK, so you have a different version of the expression applied to each row. Try it this way:

textIndex%6 == 0 ? 100 : 0

Likes

Translate

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
Explorer ,
May 24, 2022 May 24, 2022

Copy link to clipboard

Copied

Thank you.

Likes

Translate

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
Explorer ,
May 24, 2022 May 24, 2022

Copy link to clipboard

Copied

Dan,

apologizes for taking more of your time for such basic questions,
but what is the best way to combine

 

textIndex%6 == 2 ? 100 : 0

and

textIndex%6 == 0 ? 100 : 0

so one expression will cover both of these situations.

I am asking all of this because I am taking  #2 from 

 

thisProperty.propertyGroup(3).name;

 

where "Animator" name is "2".

Of course, I start with "1" and by duplicating the animator everything works fine until I hit the 6th copy. As you recommended I could change it manually into "0" but I am looking for the way that the original expression applied to the "1" will work in the "6" etc., as well.
Thank you in advance.

Likes

Translate

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
Adobe Community Professional ,
May 24, 2022 May 24, 2022

Copy link to clipboard

Copied

Like this I guess:

n = thisProperty.propertyGroup(3).name%6;
textIndex%6 == n ? 100 : 0

Likes

Translate

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
Explorer ,
May 24, 2022 May 24, 2022

Copy link to clipboard

Copied

Beautiful. Thank you so much.

 

By the way, I am trying to understand what is going on here and I was looking around but could not find anything regarding what "%" represents.  Thank you again

Likes

Translate

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
Explorer ,
May 25, 2022 May 25, 2022

Copy link to clipboard

Copied

Don't worry I found it. It is a remainder %. 

Likes

Translate

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
Explorer ,
Jul 02, 2022 Jul 02, 2022

Copy link to clipboard

Copied

Hi,

one additional question. Dan's solution from above works perfectly for selecting rows. I would like an added checkbox to be able to switch from selecting from rows to columns. The only way right now I can do it with the expression below but I have to manually switch Expression selector>Based On from Characters which will give me row selection to LINES which will select columns.

 

row = effect("ROWS")("Slider");

column = effect("COLUMNS")("Slider");

checkN = effect("if OFF vertical COLORS --- if ON horizonatal COLORS")("Checkbox");

 

numb = (checkN == 0) ? row : column;

 

numToColor = thisProperty.propertyGroup(3).name%numb;

 

textIndex%numb == numToColor ? 100 : 0

 

Is there any way to add expressions to select 1st, 2nd, etc columns so I avoid manually switching Expression selector?

A few screenshots are included one is with what happens with the character selected, one is with lines selected, and one is a screenshot of the expression's timeline section just for reference.

As always thank you so much.

Likes

Translate

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
Adobe Community Professional ,
Jul 02, 2022 Jul 02, 2022

Copy link to clipboard

Copied

I think your setup is the opposite of what I'm used to, but when I've done grids in the past, you get the column number with index%numberOfColumns and you get the row number with Math.floor(index/numberOfColumns). I don't know if that helps at all.

Likes

Translate

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
Explorer ,
Jul 02, 2022 Jul 02, 2022

Copy link to clipboard

Copied

Thank you, Dan, for your time,

I am not sure if I was clear enough in my question.

 

Just to explain something in general, I am building the box chart graphic using Webdings "g" letter which is a square (you can see the reference image in the attachment above)

 

Let's say I have a box graph with 4 rows and 5 columns

 

With the expression that I used based on your previous advice, it selects 1st box and then 5th, 9th, 13th and 17th.

 

My question is how can I write the expressions that select 1st 4 boxes.

And because I am using thisProperty.propertyGroup(3).name but duplicating the "Animator"

I should be able to select 5th to 8th and then 9th to 12th and so on.

 

This may be very basic and I thank you again for your help.

 

 

Likes

Translate

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
Adobe Community Professional ,
Jul 03, 2022 Jul 03, 2022

Copy link to clipboard

Copied

OK, so I've been playing around with this, and hopefully I've set it up like you have it. I think you can get everything you need with just the one checkbox control. This is what I have:

checkN = effect("if OFF vertical COLORS --- if ON horizonatal COLORS")("Checkbox").value;
numRows = text.sourceText.split("\r").length;
numCols = text.sourceText.split("\r")[0].length;
numColors = thisProperty.propertyGroup(4).numProperties;
myRow = Math.floor((textIndex-1)/numCols) + 1;
myCol = (textIndex - 1)%numCols + 1;

n = parseInt(thisProperty.propertyGroup(3).name,10); // number of this selector

if (checkN){
  myRow == n ? 100 : 0;
}else{
  myCol == n ? 100 : 0
}

You won't need the numColors variable unless you have a situation where there are more rows (or columns) than there are colors, in which case you'll have to add some additional modulo math to the expression to get the colors to cycle. I hope you find it useful.

Likes

Translate

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
Explorer ,
Jul 03, 2022 Jul 03, 2022

Copy link to clipboard

Copied

Absolutely beautiful. Thank you so much, Dan.

I have sent a little tip for you, to have a coffee or a beer on me. 

Likes

Translate

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
Adobe Community Professional ,
Jul 03, 2022 Jul 03, 2022

Copy link to clipboard

Copied

Thanks -- I appreciate it! BTW, this has the mods to make the colors cycle:

checkN = effect("if OFF vertical COLORS --- if ON horizonatal COLORS")("Checkbox").value;
numRows = text.sourceText.split("\r").length;
numCols = text.sourceText.split("\r")[0].length;
numColors = thisProperty.propertyGroup(4).numProperties;
myRow = Math.floor((textIndex-1)/numCols)%numColors + 1;
myCol = ((textIndex - 1)%numCols)%numColors + 1;

n = parseInt(thisProperty.propertyGroup(3).name,10); // number of this selector

if (checkN){
  myRow == n ? 100 : 0;
}else{
  myCol == n ? 100 : 0
}

 

Likes

Translate

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
Explorer ,
Jul 03, 2022 Jul 03, 2022

Copy link to clipboard

Copied

Thank you, Dan!!! It is amazing and so generous that you are always willing to help and provide guidance to everyone no matter how our questions sometimes could be so basic (maybe not in this case) and our skills level 
so very novice.

The first solution worked perfectly for me. Just a quick question about the second "colors cycle" solution, in what situation that solution would be fitting.  Thank you.

Likes

Translate

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
Adobe Community Professional ,
Jul 04, 2022 Jul 04, 2022

Copy link to clipboard

Copied

LATEST

If you expand the grid of squares so that there are more rows and/or columns than color selectors, when it runs out of colors, it will start over, and cycle through the colors again.

Likes

Translate

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
Adobe Community Professional ,
May 24, 2022 May 24, 2022

Copy link to clipboard

Copied

Here's another solution:

 

gLen=6;
gOff=2;

((textIndex+gOff) % gLen)*selectorValue

 

Mylenium

Likes

Translate

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
Explorer ,
May 24, 2022 May 24, 2022

Copy link to clipboard

Copied

Thank you Mylenium. That is interesting but it gives different results than what I was looking for. It applies color to 1-3 skips 4 and then applies to 5-6. Check the attached if curious.

Likes

Translate

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