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

Automated tab position in table figures....

Explorer ,
Feb 01, 2024 Feb 01, 2024

Copy link to clipboard

Copied

I am working with hundreds of account tables. In the figures, I keep -2 point (right) decimal tab  [ ) ] to keep digits  align. But time to time, table sizes change and therefore I have to change this tab position manually. Is that any automated way to handle this? Any GREP formate or style condition? If so, it will save lot of my time. I greatly appreciate your advice...... Thank you.  

TOPICS
How to , Scripting

Views

372

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 1 Correct answer

Participant , Feb 02, 2024 Feb 02, 2024

Ah I see -- try this one:

app.doScript(Main, undefined, undefined, UndoModes.ENTIRE_SCRIPT,"Run Script");
function Main(){

    /*Searches for all instances of "Table_Figures" paragraph style. 
    (Paragraph style must be saved within the "Table_Styles" folder.)
    For each result, finds width of parent cell. Overrides the first 
    (existing) tab stop position to: cell width minus 2mm. 
    Deletes all other tab stops.*/
    app.findGrepPreferences = NothingEnum.nothing; 
    app.findGrepPref
...

Votes

Translate

Translate
Participant ,
Feb 01, 2024 Feb 01, 2024

Copy link to clipboard

Copied

Can you create a few different paragraph styles, one for each column width, and define the tab settings within each style? Or am I misunderstanding your request?

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 ,
Feb 01, 2024 Feb 01, 2024

Copy link to clipboard

Copied

Thanks for your promt reply. 

But this is not I mean. My tables has different size columns. When I change fist column text, other columns needs to resize. Then this tab position change. Example:

Column width - 30 points

Decimal tab position - 28 points. 

When I change this column width to 40 points, still this decimal tab stay in 28 point. I need it goes to 38 point. Always minus 2 points with the column width. I want to do it automated, because working with hundreds of tables. I think GREP command built in cell style can solve this issue.  Or any other way. 

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
Participant ,
Feb 01, 2024 Feb 01, 2024

Copy link to clipboard

Copied

This is a very rudimentary script but maybe it could work for you. See the notes I included below -- I made a few assumptions but let me know if those aren't true. When you place your cursor in a cell and run the script, it will go through each cell in that column and replace the existing tab stop with a new one. Note it's not creating any new paragraph styles, so these are just overrides we're making, which will make it difficult to readjust en masse later. But if you were going to do manual updates anyway, maybe this could save you some time.

Are you familiar with how to save and run scripts? 

//Place cursor in the column to be updated (do not highlight a whole cell or column).
//Then run the script.
//Assumes there is only one paragraph in each cell.
//Assumes there is already a tab set up for the paragraphs.
//Will not adjust tabs in top (header) cell.
app.doScript(Main, undefined, undefined, UndoModes.ENTIRE_SCRIPT,"Run Script");
function Main(){

var myColumn = app.selection[0].parent.parentColumn;
var myCells = myColumn.cells;
var myParagraph;
var myTabStop;

var myDecimalPosition = myColumn.width - 2; 
//Replace number 2 above with the desired inset from right. 
//Uses measurement units as defined in the document (e.g., pts, picas).

    for (i=1; i<myCells.length; i++) {
        myParagraph = myCells[i].paragraphs[0];
        myTabStop = myParagraph.tabStops[0];
        myTabStop.alignment = TabStopAlignment.CHARACTER_ALIGN;
        myTabStop.position = myDecimalPosition;
    }

}

 

 

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 ,
Feb 01, 2024 Feb 01, 2024

Copy link to clipboard

Copied

Hello danaken3

Thank you very much for your script. Seems to be this is what I doing now manually. Highlight whole column and change the tab position. Working with different size columns and different size of tables, it's so difficult. Here I attached sample table. I need to auto position tab for increase/decrease column width. GREP can do magics !!!!!  is it not possible here..... please give a try. ..... I appreciate all of your efforts....... Thank you. 

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
Participant ,
Feb 01, 2024 Feb 01, 2024

Copy link to clipboard

Copied

I don't know of any way to do this without scripting — but the following script does a global find/replace using your paragraph style "Table_Figures". From your sample document, it looks like you want the tab stop to be 2 millimeters less than the column width (rather than 2 points), correct? Give this one a try.

/*Searches for all instances of "Table_Figures" paragraph style. 
(Paragraph style must be saved within the "Table_Styles" folder.)
For each result, finds width of parent cell. 
Overrides the first (existing) tab stop in the paragraph to: cell width minus 2mm. */
app.doScript(Main, undefined, undefined, UndoModes.ENTIRE_SCRIPT,"Run Script");
function Main(){

    app.findGrepPreferences = NothingEnum.nothing; 
    app.findGrepPreferences.appliedParagraphStyle = app.activeDocument.paragraphStyleGroups.item("Table_Styles").paragraphStyles.item("Table_Figures");
    var myResults = app.findGrep();
    var myCell;
    var origViewMeasurements = app.activeDocument.viewPreferences.horizontalMeasurementUnits;
    app.activeDocument.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.millimeters;

    for (i=0; i<myResults.length; i++) {
        try {
            myCell = myResults[i].parent;
            myResults[i].tabStops[0].position = myCell.width - 2;
        }
        catch(err) {
        }
    }
    app.findGrepPreferences = NothingEnum.nothing;
    app.activeDocument.viewPreferences.horizontalMeasurementUnits =origViewMeasurements;
}

 

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 ,
Feb 02, 2024 Feb 02, 2024

Copy link to clipboard

Copied

WOW !!!!!!

It works...... wonderful....... 

I select the table and run the script. It adjusted tabs according to the lolumn width. Amazing!!!! It will save lot of time......  Thank you very much..... 

One thing. I saw script make new tab position related to the column width. But old tab is also there. Those tables  again and again useing and therefore many tabs saving in each time.  Can you remove old tab position with this same script? Then the table is clear. ...... 

Again, thank you for your wonderful effort.......  

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 ,
Feb 02, 2024 Feb 02, 2024

Copy link to clipboard

Copied

And one another thing danaken3, 

Some header rows conain bottom line with years and LKR '000. This part also need to adjust with the figures. Do you have any idea about how to do that? If this script can't do that, any new script for run again? No matter to use two mouse clicks per table....... I am happy enough..... 

 

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
Participant ,
Feb 02, 2024 Feb 02, 2024

Copy link to clipboard

Copied

Ah I see -- try this one:

app.doScript(Main, undefined, undefined, UndoModes.ENTIRE_SCRIPT,"Run Script");
function Main(){

    /*Searches for all instances of "Table_Figures" paragraph style. 
    (Paragraph style must be saved within the "Table_Styles" folder.)
    For each result, finds width of parent cell. Overrides the first 
    (existing) tab stop position to: cell width minus 2mm. 
    Deletes all other tab stops.*/
    app.findGrepPreferences = NothingEnum.nothing; 
    app.findGrepPreferences.appliedParagraphStyle = app.activeDocument.paragraphStyleGroups.item("Table_Styles").paragraphStyles.item("Table_Figures");
    var myResults = app.findGrep();
    var myCell;
    var origViewMeasurements = app.activeDocument.viewPreferences.horizontalMeasurementUnits;
    app.activeDocument.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.millimeters;

    for (i=0; i<myResults.length; i++) {
        try {
            if (myResults[i].tabStops.length > 1) {
                for (j=myResults[i].tabStops.length-1; j>0; j--) {
                    myResults[i].tabStops[j].remove();
                }
        }
            myCell = myResults[i].parent;
            myResults[i].tabStops[0].position = myCell.width - 2;
        }
        catch(err) {
        }
    }

    /*Searches for all instances of "Table_Header" paragraph style. 
    (Paragraph style must be saved within the "Table_Styles" folder.)
    For each result, finds width of parent cell. Overrides the first 
    (existing) tab stop position to: cell width minus 2mm. 
    Deletes all other tab stops.*/
    app.findGrepPreferences = NothingEnum.nothing; 
    app.findGrepPreferences.appliedParagraphStyle = app.activeDocument.paragraphStyleGroups.item("Table_Styles").paragraphStyles.item("Table_Header");
    myResults = app.findGrep();
    app.activeDocument.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.millimeters;

    for (i=0; i<myResults.length; i++) {
        try {
            if (myResults[i].tabStops.length > 1) {
                for (j=myResults[i].tabStops.length-1; j>0; j--) {
                    myResults[i].tabStops[j].remove();
                }
        }
            myCell = myResults[i].parent;
            myResults[i].tabStops[0].position = myCell.width - 2;
        }
        catch(err) {
        }
    }    

    app.findGrepPreferences = NothingEnum.nothing;
    app.activeDocument.viewPreferences.horizontalMeasurementUnits = origViewMeasurements;

    alert("Script complete");

}

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 ,
Feb 02, 2024 Feb 02, 2024

Copy link to clipboard

Copied

danaken3, 

Yes... it works!!!!!! 

Please give your attention to my previous request.... Do you have any idea to remove old decimal tabs........

If so, this script valued much... Please give your attention one more time...... 

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
Participant ,
Feb 02, 2024 Feb 02, 2024

Copy link to clipboard

Copied

Hmm this should be removing all of the old tab stops already. Can you share a screenshot or example file where it's not working?

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 ,
Feb 02, 2024 Feb 02, 2024

Copy link to clipboard

Copied

danaken3, 

See attached ID file. I keep one tab  and run the script. After that, new and old - two tabs are there. 

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
Participant ,
Feb 02, 2024 Feb 02, 2024

Copy link to clipboard

Copied

To clarify -- the most recent script I posted contains solutions to both of your latest requests (adjusting the tab stops for the Table-Header style, and removing any extra tab stops). If you run that, it should properly adjust the tab stops for both the Table_Figures and the Table_Header paragraph styles. It should also remove any extra tab stops. When I run the script on that file, it works for me. 

 

Are you using the latest script or one of my previous scripts I posted?

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 ,
Feb 02, 2024 Feb 02, 2024

Copy link to clipboard

Copied

LATEST

Sorry danaken3, 

It's my mistake. This is what I want !!!!! 

Thanks a lot..... I'm sure someone who works with lot of account tables, this script helps lot. 

You are a wonderful creator...... Thank you !!!!! 

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
People's Champ ,
Feb 01, 2024 Feb 01, 2024

Copy link to clipboard

Copied

It sounds like this (not free) script of mine might help: https://www.id-extras.com/products/centertablecolumns/

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 ,
Feb 01, 2024 Feb 01, 2024

Copy link to clipboard

Copied

Hi @nalink10768017:

 

Outside of @TᴀW's script, there isn't an easy answer. This is why a lot of folks give up on decimal alignment, and just center the numbers. It's not the right way to do it, but it's quicker. Personally, I'd go with the script!

 

~Barb

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