Script to apply the cell style after paragraph research

Hello

can someone help my make a script to search for all occurrences of a paragraph format in the tables and then apply a cell style to a document the bounding cell.

Thanks in advance.

Peter

BTW Mac InDesign CS 6

Hello

Use this:

var mDoc = app.activeDocument,
pST = mDoc.paragraphStyles.item("paraStyleName"),
cST = mDoc.cellStyles.item("cellStyleName"),
mFound, mParent, count;

app.findTextPreferences = null;
app.findTextPreferences.appliedParagraphStyle = pST;
mFound = mDoc.findText();
count = mFound.length;
while (count--) {
     mParent = mFound[count].parent;
     if (mParent.constructor.name == "Cell")
          mParent.appliedCellStyle = cST;
     }

app.findTextPreferences = null;

change paraStyleName and cellStyleName

Jarek

Tags: InDesign

Similar Questions

  • Help with a script that detects the content in a cell and apply the cell style to line

    Hello


    I am trying to add an article to my table formatting script that is a cell with the word 'Budget' (but this can be written as ' Budget:' or ' Budget: (E) "- but without the speech marks) and apply the cell Style - SponsorCells - to all the cells of the whole line. I currently have on what it will, but it does not work:


    function checkWhichTable()
    {
    // ensure the user made a selection
    if (app.selection.length != 1)
    return null;
    var currentTable = app.selection[0];
    if (currentTable.hasOwnProperty("baseline"))
    {
    currentTable = app.selection[0].parent;
    }
    while (currentTable instanceof Cell || currentTable instanceof Row || currentTable instanceof Column)
    currentTable = currentTable.parent;
    if (!(currentTable instanceof Table))
    {
    // No table selected
    return null;
    }
    return currentTable;
    }
    app.doScript(checkUserSelection, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, "Process Table");
    
    
    function checkUserSelection ()
    {
    var a_table = checkWhichTable();
    if (a_table == null)
    {
    if (confirm("No table selected. Do you want to process *all* tables?") == false)
    return;
    allTables = app.activeDocument.stories.everyItem().tables.everyItem().getElements();
    for (aTable=0; aTable<allTables.length; aTable++)
    {
    processTable (allTables[aTable]);
    }
    } else
    {
    processTable (a_table);
    }
    }
    function processTable(table)
    {
    // do something here!
    
    
    //Set 1st Row Height
    table.rows[0].height = "30mm";
    
    
    //Find Text in Cell and apply Cell Style to Row 
    var  
      myCellText=['Budget', 'Budget:', 'Budget: (E)'];  
     var myRegEx = new RegExp("^("+myCellText.join("|")+")$");
      for (i=0; i<table.cells.length; i++)
      {
        if (table.cells[i].texts[0].contents.match(myRegEx))
          table.cell[i].appliedCellStyle = "SponsorCells";
      }
    
    
    //end - do something here!
    }  
    


    I can get the script to apply the cell style to "SponsorCells" for each cell that contain the word 'Budget' etc, but I need cell ever on this line to have the cell style applied. I tried to re-write line 56 which applies the style to a cell, but I can't seem to make it work. Any help would be great.


    Separate on this issue, I would like to have a line of code similar to the 46 line, which sets the 1st height of lines, but I would like to say "If a cell has 'A cell Style' and then applies the value height 10 mm". If someone could result as a help of bonuses, things would be great double.


    Thanks in advance!

    But that could be painfully slow. To speed things up, follow these steps:

    var cells = table.cells.everyItem().getElements();
    for (var i=0; i
    

    It is faster, because it creates an array of cells with a call to table.cells, which is several times faster than calling table.cells. And before assigning to line 12mm height is useful to check if it is already 12 mm. checking things in InDesign and do things only when it is necessary is much more effective than simply doing things even if they are not necessary.

  • Help with a script to search for text in a table cell and apply the cell style

    Hello

    I build the script which Jongware wrote in his post here http://indesignsecrets.com/tackling-tables-through-scripting.php - I am trying to create a variable in which I can add a number of different parts of the text, in this case it's different parts of the United Kingdom i.e. 'London', 'East', 'Scotland' etc. I just need the script to apply the cell Style - 'District Cell' - to any cell that contains text in the variable. Here's the script, if anyone can help I would be grateful.

    function checkWhichTable()
    {
    // ensure the user made a selection
    if (app.selection.length != 1)
    return null;
    var currentTable = app.selection[0];
    if (currentTable.hasOwnProperty("baseline"))
    {
    currentTable = app.selection[0].parent;
    }
    while (currentTable instanceof Cell || currentTable instanceof Row || currentTable instanceof Column)
    currentTable = currentTable.parent;
    if (!(currentTable instanceof Table))
    {
    // No table selected
    return null;
    }
    return currentTable;
    }
    app.doScript(checkUserSelection, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, "Process Table");
    
    
    function checkUserSelection ()
    {
    var a_table = checkWhichTable();
    if (a_table == null)
    {
    if (confirm("No table selected. Do you want to process *all* tables?") == false)
    return;
    allTables = app.activeDocument.stories.everyItem().tables.everyItem().getElements();
    for (aTable=0; aTable<allTables.length; aTable++)
    {
    processTable (allTables[aTable]);
    }
    } else
    {
    processTable (a_table);
    }
    }
    function processTable(table)
    {
    // do something here!
    
    
    //Find Text in Cell and apply Cell Style
    var textInCell=['London', 'Scotland', 'South West'];
    for (i=0; i<table.cells.length; i++)
    {
    if (table.cells[i].texts[0].contents==textInCell)
    table.cells[i].appliedCellStyle = "District Cell";
    }
    
    
    
    
    }
    

    Hello

    Change this feature:

    function processTable(table)
    {
    //Find Text (exactly as it is) in Cell and apply Cell Style
    var
      textInCell=['London', 'Scotland', 'South West'],
      mFound, cFound;
    
    app.findGrepPreferences = null;
    app.findGrepPreferences.findWhat = "^(" + cities.join("|") + ")$";
    mFound = table.findGrep();
    while( cFound = mFound.pop() )
      cFound.parent.appliedCellStyle = "District Cell";
    }
    

    Jarek

  • How to write the script to apply the character style?

    Hello

    I'm on a Macbook pro and without a numeric keypad, so I can't assign a shortcut to character styles. I heard a roundabout solution where you can assign a shortcut to a script that applies the character styles. Can anyone write this script?

    My character style is called "features"bold. "

    I am new to scripting, sorry if this is a stupid question.

    See you soon

    Hello

    1. save this code as a file inside your Script Panel folder .jsx

    2. apply a shortcut using the menu Edit: shortcuts...

    Option to choose:

    • suggest you choose an option 'background': 'Text', so you can use several shortcuts that are occupied in other contexts.
    #target indesign
    if (app.selection && app.selection[0].hasOwnProperty ("baselineShift") ) {
      var cName = "Features bold";
      var mCstyle = app.activeDocument.characterStyles.item(cName);
      if (mCstyle.isValid)
           app.selection[0].applyCharacterStyle(mCstyle);
      else
           alert ("CharStyle: " + cName + " not found");
      }
    else
      alert ("Some text supposed to be selected...");
    

    Jarek

  • A script to apply the style of cell to whole lines containing specific text

    Hello

    I use InDesign CC 2014

    Does anyone know how apply a cellstyle based on the content of text found in a cell in javascript?

    I need to find the document and change cell style in the entire line to 'cellStyle01' If the 'etc' text appears in the cell.

    I found a similar script here to the forum which apply the table style, but do not know how to change it to apply the cell style!

    var curDoc = app.activeDocument;
    var allTables = curDoc.stories.everyItem().tables.everyItem();
      
    app.findTextPreferences = app.changeTextPreferences = null;
    app.findTextPreferences.findWhat = "someText";
    var allFounds = allTables.findText();
    app.findTextPreferences = app.changeTextPreferences = null;
      
    for ( var i = 0; i < allFounds.length; i++ ) {
    var curFound = allFounds[i];
    if ( curFound.length == 1 ) {
    var curFoundParent = curFound[0].parent;  
    // curFoundParent.parent.appliedTableStyle = curDoc.tableStyles.itemByName( "tableStyle" );  
    curFoundParent.parent.appliedCellStyle = curDoc.cellStyles.itemByName("cellStyle01");  
    }
    }
    
    

    Thank you!

    Hello

    in this new case, you can't just change the last line, because yo I want to find not the entire table and lines and cells.

    Try this modified version:

    var curDoc = app.activeDocument;
    var allTables = curDoc.stories.everyItem().tables.everyItem(); 
    
    app.findTextPreferences = app.changeTextPreferences = null;
    app.findTextPreferences.findWhat = "some Text";
    var allFounds = allTables.findText();
    app.findTextPreferences = app.changeTextPreferences = null;
    
    for ( var i = 0; i < allFounds.length; i++ ) {
        var tableFound = allFounds[i];
        if ( tableFound.length > 0 ) {
            for ( var j = 0; j < tableFound.length; j++ ) {
                var curFound = tableFound[j];
                var cellsInRow = curFound.parent.parentRow.cells.everyItem();
                cellsInRow.appliedCellStyle = curDoc.cellStyles.itemByName( "cellStyle01" );
                cellsInRow.clearCellStyleOverrides( true );
            } // end for
        } // end if
    } // end for
    
  • Apply the table style based on the contents of the cell

    I'm on a Mac, OS 10.8.5 using InDesign 5.

    Does anyone know how to apply a table style based on the content of text found in a cell in javascript?

    I need to find the document and change all the styles table 'LONG orange verbatim' If the text "HS:" appear in the header line.

    I've been playing with scripts found with the following 3 wires, but can get it to apply a table style.

    Thank you!

    Apply Table Cell Style based on text search and How to apply a cell of table based on grep style search? and Re: find PStyle and apply the cell Style in the Table

    Here are the corrected lines:

    var curDoc = app.activeDocument;
    var allTables = curDoc.stories.everyItem().tables.everyItem(); 
    
    app.findTextPreferences = app.changeTextPreferences = null;
    app.findTextPreferences.findWhat = "HS:";
    var allFounds = allTables.findText();
    app.findTextPreferences = app.changeTextPreferences = null;
    
    for ( var i = 0; i < allFounds.length; i++ ) {
        var curFound = allFounds[i];
        if ( curFound.length == 1 ) {
            var curFoundParent = curFound[0].parent;
            if ( curFoundParent.parentRow.rowType == RowTypes.headerRow ) {
                curFoundParent.parent.appliedTableStyle = curDoc.tableStyles.itemByName( "verbatim orange LONG" );
            }
        }
    }
    
  • Apply the character style to the part of the paragraph

    I am inserting text in a block of text with the following code:

    story.insertionPoints [-1] .silence += pgfStr;

    story.insertionPoints [-1] .silence += "\t";

    story.insertionPoints [-1] .silence += refStr;

    story.insertionPoints [-1] .silence += "\r";

    I want to apply the character style to all of the text in refStr (only the part of this paragraph). I know how the syling paragraph applies to the entire paragraph, but not a character style. I should be grateful if you would help. Thank you!

    Hello

    Dan - BTP says:

    ... the size in points and attack can be different on each page...

    You are able to find a rule of these differences?

    ...

    What do depends on what type of rule could be defined

    ...

    The size of reference point that is 1.5 PT lower than the point size of the paragraph, whatever.

    Close to the end of the script, you can code for example:

         //     Your target is "reference" which is a text inbetween tabulator and end of story (or other criteria).
         //     So you could define:
    app.findGrepPreferences = null;      // just for clear it
    app.findGrepPreferences.findWhat = "(?<=\\t).+\\s\\Z";     //     to catch text following tab in last para of story
         //     and after:
    mFound = app.activeDocument.findGrep();
         //     so all desired text objects are in an array "mFound".
         //     you could iterate (backward) through it:
    len = mFound.length;
    while (len-->0)      //     ">0" in case of nothing found
         mFound[len].pointSize -= 1.5;
    
         //     whatever that is - is 1.5 smaller
    

    Jarek

  • How to apply the created style as a number of list twice but the new paragraph begins number 1?

    Hi all

    I work in design and I created a style sheet that applies the list of numbers in the paragraph highlighted.

    NOOW I am facing a problem. If the same style on the same page but for another paragraph he continues with the next number in the first list of numbers, as it actually should start with number 1.

    Does anyone know how to start the next list of numbers with number 1 again even if I apply the same style of number again to a different point on the same page?

    Please let me know.

    Thanks in advance for your help.

    Quick fix:

    Right-click / CTRL-click (to get the context menu) on the first line of the second number list and select Restart numbering from the list of options.

    Repeat as needed for the following lists.

  • delete the cell style - to preserve formatting

    Hello scripters.

    Is it possible to preserve the formatting when I remove a cell applied by the following code style?

    "MyCellStyle.remove (app.activeDokument.cellStyles.firstItem ());

    How can I access this feature in my script? (see also the screenshot-> red arrow)

    perserve_formating.png

    Thanks for the tips.

    Roland

    Roland:
    You can browse all your cells with the applied cell style, select the cells, one after the other and apply a menu action to break the link style ("Break link to Style" / "Operation mit Format Hegelian").

    You can then delete the cell style without losing any formatting.

    To invoke the menu action, you can use this code. For security reasons, I've got it wrapped up with a "try/catch":

    //Disconnect the cell with the applied cell style (option in the cell styles panel of the UI: "Break Link to Style" / "Verknüpfung mit Format aufheben"):
    try{app.scriptMenuActions.itemByID(132129).invoke()}catch(e){};
    

    Uwe

  • Selection of parts and columns, or entire lines and apply the character style

    I am trying to apply character styles to certain parts/whole rows and columns.

    I can change individual cells with the following code...

    table = app.selection[0];
    if (table.hasOwnProperty("baseline")) table = table.parent;
    if (table instanceof Cell) table = table.parent;
    if (table instanceof Column) table = table.parent;
    if (table instanceof Row) table = table.parent;
    if (table instanceof Table)
    
    {
     table.rows[0].cells[6].texts[0].appliedCharacterStyle = "none report";
     }
    

    ... but when I try to select an entire line, I get the error 'Object does not support property or method' texts. "" "When I try one of the following two codes.

    {
     table.rows[0].cells.texts.appliedCharacterStyle = "none report";
     }
    

    {
     table.rows[0].cells.appliedCharacterStyle = "none report";
     }
    

    Anyone know how I can do the following?

    1. Select any row (or column) and apply the character style

    2. Select the last line (regardless of the number of rows in the table) and apply the character style

    3. apply the character style to specific columns (with theexception of the cells of two albums)

    Thank you!

    Hello

    Change this line:

    table.columns[a].cells.itemByRange(2,-1).texts.everyItem().appliedCharacterStyle = "chart orange";
    

    for the first 2 rows in each column

    Jarek

  • Is there a script to apply a certain style to thousands of words arranged in a list?

    Hello, I tried to use FindChangeByList, but I do almost all the work of collage every word on the legs, so I might as well apply the styles to the hand.

    So my plan is to apply the same style to near 11 000 words that appear in a book. These words are for most of the names and marks, and they appear throughout the whole of the text, it would be quite tedious to manually apply this style.

    I have these words put aside in a list.txt

    Anyone know if I could use it in any script and apply the style automatically?

    Like I said, sticking each word in FindChangeByList is out of the question, just like applying style verbatim, it would still...

    ... Thank you!

    Piece of cake. Since you do not specify, this script assumes that your text file is called "list.txt" and is located in your folder (line 1) user documents, and your style is a Style of character called "yourStyle" (line 9).

    textFile = File(Folder.myDocuments+"/list.txt");
    if (textFile.open("r") == false)
    { alert ("yeah ... that file does not exist"); exit(0); }
    strs = textFile.read ();
    textFile.close();
    strs = strs.split("\n");
    app.findGrepPreferences = null;
    app.changeGrepPreferences = null;
    app.changeGrepPreferences.appliedCharacterStyle = app.activeDocument.characterStyles.item("yourStyle");
    while (strs.length > 0)
    {
    app.findGrepPreferences.findWhat = "\\b"+strs.pop()+"\\b";
    app.activeDocument.changeGrep();
    }
    
  • Unable to apply the class style to the line of the table?

    created a class style with pad of 10px on only right & vertical alignment at the top.

    I want to apply this class to a table row - but when I do - I get the correct vertical alignment - but none touch.

    If I apply the same class style to each td cell - then the alignment and buffer work.

    I have a stupid mistake? There are 40 cells of td in the rank - so it would be more quickly just to apply the class to the whole line. any ideas what I am doing wrong? much thanks in advance.

    And by the way, the best way to proceed would be next, using a
    descendant selector-

    .padThis td {vertical-align: top; padding: 10px ;}}

    ...


    Now, all thetags thatwill be filling and alignment
    you want.

    --
    Murray - ICQ 71997575
    Adobe Community Expert
    (If you * MUST * write me, don't don't LAUGH when you do!)
    ==================
    http://www.projectseven.com/go - DW FAQs, tutorials & resources
    http://www.dwfaq.com - DW FAQs, tutorials & resources
    ==================

    "dextre manika" wrote in message
    News:gnauf0$NKT$1@forums. Macromedia.com...
    > created a class style with pad of 10px side right only & vertical
    > alignment to
    > top.
    >
    > I want to apply this class to a table row - but when I do - I get correct
    > vertical alignment - but no key.
    >
    > If I apply the same style of class to each td cell - then the two alignment and
    > pad
    > work.
    >
    > I have a stupid mistake? There are 40 cells of td in the row - so he
    > would be more quickly just to apply the class to the whole line. any ideas what I am
    > making
    > evil? much thanks in advance.
    >

  • Is it possible to add text to the cells and apply the character style in the cell

    I work in InDesign on Mac 5.

    I have two tables of formatting with information that will be eventually combined. I implemented the scripts I found on these forums to add the columns needed, merge lines and fill the cells merged with the appropriate color, but can't two remaining tasks.

    1. is it possible to add text to a cell of some?

    2 and it is possible to apply a character style to cells? (different cells than those that I need to add some text)

    I played with this code but do not know if it is even close...

    {

    table. Rows [0]. Cells [0]. InsertText (' CS/PS");

    }

    {

    table. Rows [0]. Cells [0] .appliedCharacterStyle ("bold");

    }

    Here are the scripts that I have combined so far for the table...

    Add column

    myTable = app.selection [0];

    MyColumn = myTable.columns [1];

    for (a = 0; < 1; a ++)

    {

    myTable.columns.add (LocationOptions.AFTER, myColumn);

    }

    Merge lines

    table = app.selection [0];

    If (table.hasOwnProperty ("baseline") table) = table.parent;

    If (instanceof cell table) table = table.parent;

    If (instanceof column table) table = table.parent;

    If (instanceof row table) table = table.parent;

    If (instanceof Table table)

    {

    table. Rows [0]. Cells [0]. Merge (table.rows [0] .cells [1]);

    }

    {

    colours alternating in merged lines

    r = table.rows [1];

    n = app.activeDocument.swatches.item ("orange");

    b = app.activeDocument.swatches.item ("PANTONE 3005 C");

    for (c = 0; c < r.cells.length; c ++)

    {

    If (c & 1)

    r.Cells [c]. Properties = {fillColor:b};

    on the other

    r.Cells [c]. FillColor = n;

    }

    }

    Hello

    1. If you want to add the text, go further in:

    table. Rows [0]. Cells [0] .insertionPoints [0] .silence = ' CS/PS;

    2 similar with application of styles:

    table. Rows [0]. Cells [0] .texts [0] .appliedCharacterStyle = "bold" / / If this style is present in your doc

    Jarek

  • How to apply the character style to table cell

    I'm sure it's basic, but I can't find any references on how to do it and my attempts have failed.  I use VB and CS5.5

    Basically what I'm trying to do is to select a table cell and apply a character like this style...

    MyCharacterStyle = myDocument.CharacterStyles.Add set

    myCharacterStyle.Name = "TH2".

    myTable2.Cells.Item (1) .appliedCharacterStyle = "TH2".

    with this code, I get a "object does not support this property or method.  myTable2.Cells.Item (...). appliedCharacterStyle ".

    I tried several other versions without success.

    Can someone tell me what would be the proper syntax to apply a character style to text in a table cell, or if it's still the right path to follow on that?

    I have to select the text in the cell rather than the cell itself, and if so, how do you do that?

    Thank you

    You do not need to select the text in the cell, but you need

    to target rather than the cell. It is true that in the user interface, you can

    Select the cell and apply a style of tank, but not with a script. Thus, in

    JavaScript is:

    myCell.texts.item (0) = .appliedCharacterStyle

    app.activeDocument.characterStyles.itemByName ("MyCharStyleName")

    It must be something similar in VB also.

    Of course, you can target the text in different ways:

    myCell.characters.everyItem () or myCell.paragraphs.everyItem () etc etc.

    but I think that the text is the most basic of the lot.

    Ariel

  • How to use GREP to apply the character style just for the first and the second line of the paragraph?

    as the title, I just want to ask how to apply the style of character just for the 1st and 2nd line of the paragraph. Help me pls, tks!

    Can you show the screen shot with the invisible market, looks like you feedback after each line.

    So, something like this would work where I have a return forced for the linebreak (shift + return). The example on the right does not work because the line break is a return:

Maybe you are looking for