Highlighted

Getting the longest physical width of text in a cell column and use it as reference for tab stop.

Community Beginner ,
Apr 02, 2020

Copy link to clipboard

Copied

Hello,

I need help. I am working with columns. I need to find the longest character width and create a tabstop aligning (character alignment: ")" ) all the figures to the longest character in the selected column.

 

This is the unformatted: (in center align)

Capture.PNG   

This is formatted with tab stop: (character align: ")", left-justified)

 Capture2.PNG

This is the script that I'm using. It only applies to individual cells so basically, it just center-aligns every cell. 

 

var textsArray = app.selection[0].cells.everyItem().texts.everyItem().getElements();
var tabStopProperties =
{
    alignment : TabStopAlignment.CHARACTER_ALIGN ,
    alignmentCharacter : ")"
};

for(var n=0;n<textsArray.length;n++)
{
    start = textsArray[n].insertionPoints[0].horizontalOffset;
    end = textsArray[n].insertionPoints[-1].horizontalOffset;
    distance = end - start;

    var widthA = app.selection[0].cells[0].width;
    var widthB = distance;
    var widthC = widthA - widthB;
    var widthD = widthC/2
    var position = widthA - widthD;
    
    textsArray[n].tabStops.everyItem().remove();
    textsArray[n].tabStops.add();
    textsArray[n].tabStops[0].properties = tabStopProperties;
    textsArray[n].tabStops[0].position = position;
    textsArray[n].justification = Justification.LEFT_ALIGN;

};

 

Thanks,

Martin

 

Hi Brian!

 

I think Martin tries to get something like this!

[script written for a client 3 years ago!]

 

(^/) The Jedi

 

Capture d’écran 2020-04-03 à 15.10.50.png

Topics

Scripting

Views

247

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

Getting the longest physical width of text in a cell column and use it as reference for tab stop.

Community Beginner ,
Apr 02, 2020

Copy link to clipboard

Copied

Hello,

I need help. I am working with columns. I need to find the longest character width and create a tabstop aligning (character alignment: ")" ) all the figures to the longest character in the selected column.

 

This is the unformatted: (in center align)

Capture.PNG   

This is formatted with tab stop: (character align: ")", left-justified)

 Capture2.PNG

This is the script that I'm using. It only applies to individual cells so basically, it just center-aligns every cell. 

 

var textsArray = app.selection[0].cells.everyItem().texts.everyItem().getElements();
var tabStopProperties =
{
    alignment : TabStopAlignment.CHARACTER_ALIGN ,
    alignmentCharacter : ")"
};

for(var n=0;n<textsArray.length;n++)
{
    start = textsArray[n].insertionPoints[0].horizontalOffset;
    end = textsArray[n].insertionPoints[-1].horizontalOffset;
    distance = end - start;

    var widthA = app.selection[0].cells[0].width;
    var widthB = distance;
    var widthC = widthA - widthB;
    var widthD = widthC/2
    var position = widthA - widthD;
    
    textsArray[n].tabStops.everyItem().remove();
    textsArray[n].tabStops.add();
    textsArray[n].tabStops[0].properties = tabStopProperties;
    textsArray[n].tabStops[0].position = position;
    textsArray[n].justification = Justification.LEFT_ALIGN;

};

 

Thanks,

Martin

 

Hi Brian!

 

I think Martin tries to get something like this!

[script written for a client 3 years ago!]

 

(^/) The Jedi

 

Capture d’écran 2020-04-03 à 15.10.50.png

Topics

Scripting

Views

248

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
Adobe Community Professional ,
Apr 02, 2020

Copy link to clipboard

Copied

You need to iterate through each cell, not use everyItem in this case. (But I don't know why you just wouldn't use right align for the text and save yourself the trouble?)

var cells = app.selection[0].cells;
for (var i = 0; i < cells.length; i++) {
   var texts = cells[i].texts.everyItem().getElements();
   ...
}

 

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
Reply
Loading...
Advocate ,
Apr 03, 2020

Copy link to clipboard

Copied

Hi Brian!

 

I think Martin tries to get something like this!

[script written for a client 3 years ago!]

 

(^/) The Jedi

 

Capture d’écran 2020-04-03 à 15.10.50.png

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
Reply
Loading...
Community Beginner ,
Apr 04, 2020

Copy link to clipboard

Copied

Hi Michel,

 

This is what I need to achieve. Can you share it with me? Hehe.

 

-Martin

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
Reply
Loading...