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

Creating vertical gradients in table rows

Explorer ,
Apr 12, 2017 Apr 12, 2017

Copy link to clipboard

Copied

Is it possible to create vertical gradients across each row in a table? I know this has been discussed on and off here but I can't find any good answers.

This code almost works . . . it assumes that there is text in the first cell of each row, and calculates the page coordinates of the cell (and hence the row) from the baseline:

var defineRowGradient = function ( theRow ) {

     var firstCharacter = theRow.cells[ 0 ].characters[ 0 ];

     var minimumOffset = theRow.minimumFirstBaselineOffset;

     var topInset = theRow.topInset;

     var top = firstCharacter.baseline - ( minimumOffset + topInset );

     var left = firstCharacter.horizontalOffset - theRow.leftInset;

     theRow.gradientFillStart = [ left, top ];

     theRow.gradientFillAngle = -90;

     theRow.gradientFillLength = theRow.height;

}

By "almost works" I mean that it works fine on tables that fit in a single frame. It falls apart when the table flows to another frame or another page. The page coordinate calculations seem to hold up, but the gradient isn't applied correctly to each row. The vertical position creeps up or down, or the rows are filled with solid color or left blank. It doesn't seem to matter if the gradient is applied as part of the cell style, or as an override. It seems as if something needs to be reset each time the table jumps to a new frame.

What's missing? Is there a way to fix this so it will work with multi-frame tables?

TOPICS
Scripting

Views

622

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
Community Expert ,
Apr 13, 2017 Apr 13, 2017

Copy link to clipboard

Copied

Hi Steve,

what is your version of InDesign?

Also consider that row height could change after the gradient is applied.
E.g. text is edited. I think, every time something is done to the table, the gradient must be applied anew.

Could you share a screenshot where you see the problem with a table that is running through different text frames?
Maybe this problem also occurs, if the table flows through different columns of one single text frame?

Regards,
Uwe

Votes

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
Community Expert ,
Apr 13, 2017 Apr 13, 2017

Copy link to clipboard

Copied

See the following screenshot.

The first table is just one I added to the frame without doing anything in regards of row height.
A default table where I added "a" to the first cell of the second row.

I assume that you expect a result like the one at the bottom.

LinearGradientAppliedToTableRow.png

I think, there is more to consider than only tables that flow with more than one text frame.

FWIW: Without a character in the cell your function is not working.
Consider the baseline value of the first insertion point of a cell to start out calculating anything.

Regards,
Uwe

Votes

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 ,
Apr 13, 2017 Apr 13, 2017

Copy link to clipboard

Copied

Thanks for the replies. I'm using the latest version of InDesign CC. Please see my original post regarding the need for text in the first cell of each row. The script does require that in order to calculate the page position of the row. And you are right about the need to reapply the script after the table is edited. This may limit its usefulness. But in my case the tables only extend a few pages, and the work required to reapply (and tweak) the gradients would be manageable.

Here is the script applied to a two-page table:

gradientSpread.png

Left page: Perfect! Right page: Not so much. The first row is OK but then the gradient drifts upward until it disappears. I have checked the numbers calculated by the script, and the gradient start positions and lengths are correct.

And you are right about multiple-column tables. Here is a two-column table on a single page. Similar result:

gradientSingle.png

Votes

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 ,
Apr 13, 2017 Apr 13, 2017

Copy link to clipboard

Copied

Also meant to say thanks for the tip re: using the first insertion point instead of first character. I will look into that.

Steve

Votes

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
Community Expert ,
Apr 13, 2017 Apr 13, 2017

Copy link to clipboard

Copied

LATEST

Hi Steve,
I can confirm your problems with table rows running in a second column or in a second text frame.

And there are odd things going on, if you change the height of the text frame and allow more or less cells flow in one column of the text frame.

Regards,
Uwe

Votes

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