AppleScript to apply styles of table and cell in IDCS4

I have an Applescript script to format all the tables in a document as I want.  It is adapted from a previous version that did not use styles, that works perfectly.  This script creates styles if they are not present and this bit works fine, but when it starts to try to apply them to the tables, it falls.

tell application "Adobe InDesign CS4"
     tell active document
          set BlackColor to color "Black"
          set SolidStroke to stroke style "Solid"
     end tell
     tell active document
          try
               set myTablePara to paragraph style "4.2 Table text"
          on error
               set myTablePara to make paragraph style with properties {name:"4.2 Table text", applied font:"Helvetica Neue", font style:"Regular", point size:"8.5", leading:"10"}
          end try
          try
               set myBasicCell to cell style "Basic cell"
          on error
               set myBasicCell to make cell style with properties ¬
                    ¬
                         {name:¬
                              "Basic cell", bottom edge stroke weight:0 ¬
                              , bottom edge stroke color:BlackColor ¬
                              , bottom edge stroke type:SolidStroke ¬
                              , right edge stroke weight:0 ¬
                              , right edge stroke color:BlackColor ¬
                              , right edge stroke type:SolidStroke ¬
                              , top edge stroke weight:0 ¬
                              , top edge stroke color:BlackColor ¬
                              , top edge stroke type:SolidStroke ¬
                              , left edge stroke weight:0 ¬
                              , left edge stroke color:BlackColor ¬
                              , left edge stroke type:SolidStroke ¬
                              , left inset:¬
                              "0p4", right inset:¬
                              "0p4", top inset:¬
                              "0p4", bottom inset:¬
                              "0p4", vertical justification:top align ¬
                              , applied paragraph style:myTablePara}
          end try
          try
               set myHeader to cell style "Header"
          on error
               set myHeader to make cell style with properties ¬
                    {name:¬
                         "Header", based on:myBasicCell ¬
                         , bottom edge stroke weight:¬
                         "0.5pt", top edge stroke weight:"0.75pt", vertical justification:bottom align ¬
                         }
          end try
          try
               set myFooter to cell style "Final Row Cell"
          on error
               set myFooter to make cell style with properties ¬
                    {name:¬
                         "Final Row Cell", based on:myBasicCell ¬
                         , bottom edge stroke weight:¬
                         "0.75pt"} ¬
                         
          end try
          try
               set myLeftCol to cell style "First Column Cell"
          on error
               set myLeftCol to make cell style with properties ¬
                    {name:"First Column Cell", based on:myBasicCell, left inset:0}
          end try
          try
               set myLeftHeader to cell style "First Row, First Column Cell"
          on error
               set myLeftHeader to make cell style with properties ¬
                    {name:"First Row, First Column Cell", based on:myHeader, left inset:0}
          end try
          try
               set myLeftFooter to cell style "First Column Last Row Cell"
          on error
               set myLeftFooter to make cell style with properties ¬
                    {name:"First Column Last Row Cell", based on:myFooter, left inset:0}
          end try
          
          try
               set myTableStyle to table style "Horizon"
          on error
               set myTableStyle to make table style with properties {name:¬
                    "Horizon", body region cell style:¬
                    myBasicCell, header region cell style:¬
                    myHeader, footer region cell style:¬
                    myFooter, left column region cell style:myLeftCol}
          end try
     end tell
     set allTables to every table of every story of active document
     repeat with i from 1 to count of allTables
          set myTable to item i of allTables
          set table style of myTable to myTableStyle
          set properties of cells of myTable to ¬
               {cell style:myBasicCell}
          set properties of cells of first column of myTable to ¬
               {cell style:myLeftCol}
          set properties of cells of first row of myTable to ¬
               {cell style:myHeader}
          set properties of cells of last row of myTable to ¬
               {cell style:myFooter}
          set properties of first cell of first row of myTable to ¬
               {cell style:myLeftHeader}
          set properties of first cell of last row of myTable to ¬
               {cell style:myLeftFooter}
          clear cell style overrides
          clear table style overrides
     end repeat
end tell

When it is to 'set style table of myTable to myTableStyle' it is said ' impossible to define style table id of the table to text frame id page id 220 190 of spread id 185 [the first table] document \"Untitled-1\" table style id 264 [style newly generated] document \"Untitled-1\" 224 "  But I can't tell why.  Can anyone help?

Table and cell styles are objects. When you want to apply, you must set the appropriate properties that are 'applied the style of table"and"cell style ". So: «the game applied style table myTable...» »

But in terms of results, you'll be probably happier using the commands ' apply the style of table cell / ' instead, which allows you to clear the replacements.

--

Shane Stanley [email protected]>

AppleScript Pro Sessions http://scriptingmatters.com/aspro>

Tags: InDesign

Similar Questions

  • Table and cell Style

    Hi all

    Greetings...

    The script below works perfectly in indesign CS3 to apply table and cell style. But in indesign CS4 shows runtime error. Kindly help me on this...

    var myTable = app.activeDocument.stories.everyItem().tables; 
    
    for (var n=0; n < myTable.length; n++)
    { 
         myTable[n].appliedTableStyle = "Table Style 1"; 
         myTable[n].cells.everyItem().appliedCellStyle = app.activeDocument.cellStyles.item("[None]");
         myTable[n].cells.everyItem().clearCellStyleOverrides (true); 
    
         alert(myTable[n].rows.length);
    
        for (var a = 1; a < myTable[n].rows.length - 2; ++a)
         {
               myTable[n].rows[a].cells.everyItem().appliedCellStyle = "T body";
               alert(a);
         }
      
        myTable[n].rows[0].cells.everyItem().appliedCellStyle = "T col hd";//First Row 
         myTable[n].rows[-1].cells.everyItem().appliedCellStyle = "T body bot";//Last Row
    
    }
    

    Thank you

    Knockaert

    Hi Karthik,

    Please try the JS Code below and come back.

    var myTable = app.activeDocument.stories.everyItem().tables;
     for (var n=0; n < myTable.length; n++){
    //~      myTable[n].appliedTableStyle = "Table Style 1";
    //~      myTable[n].cells.everyItem().appliedCellStyle = app.activeDocument.cellStyles.item("[None]");
    //~      myTable[n].cells.everyItem().clearCellStyleOverrides (true); 
    
    // Please check the table cell styles name is correct or not?
        var myActiveTable = myTable[n];
        myActiveTable.rows.itemByRange(0,-2).cells.everyItem().appliedCellStyle = "TB";
        myActiveTable.rows[0].cells.everyItem().appliedCellStyle = "TCH";//First Row
       myActiveTable.rows.itemByRange(-2,-1).cells.everyItem().appliedCellStyle = "TBB";//Last Row
        }
    

    the output of code js above looks like this snapshot.

    THX

    csm_phil

  • Tame the table and cell styles

    I find table styles and cell styles to be quite a nightmare in InDesign - in other words, as long as the paragraph style is included in the definition of the cell style. The only way I could get a table without substitution involves the steps as much as it is not effective:

    1) click an empty paragraph.

    (2) apply the paragraph style.

    (3) type the text that will come eventually in a table cell. (All my paintings are a cell, a column tables).

    (4) select the text without selecting the symbol of paragraph at the end.

    (5) choose table > convert text to table.

    I would be very happy if anyone knows of a script that can do these steps and can put me out of my misery.

    (Or maybe is there a way to avoid cell style replacements that I did not discover. (There was a discussion on this problem to http://forums.adobe.com/message/2043634#2043634, but none of the suggestions got rid of substitutions of paragraph style cell.)

    Hi jay

    You should check the character styles. If paragraph styles will not be on the trip, I found that it is because it applies a character style. Some people use styles to the paragraphs format characters. (?!)

    RB

  • Auto character style applies in new tables and imported text

    Hi, I saw a post related to this problem, but it does not solve mine (check the default object style).

    So my problem is that when I import a Word document or I create a new table in InDesign, it is always a character that automatic style applies to my text and I don't really know why, I don't know what kind of option/preference to watch, I was looking in the paragraph/object/table styles, nothing seems to show me the character style that applies by default everywhere.

    Someone has an idea? I'm sure it's an easy problem to solve.

    Thanks in advance!

    Make sure that the standard paragraph is selected before importing the text. Or at least the Style of the paragraph that you want to the text.

  • How can I export table and cell styles to use in another InDesign document?

    I've been looking for... and looking but cannot find out how to export table styles in InDesign CC. If there is an option of the control panel load table styles, it goes without saying that there should be an export. Any help would be appreciated, thanks.

    Frank.GRG wrote:

    If there is an option of the control panel load table styles, it goes without saying that there should be an export.

    I understand your logic, but you think too much of it. Charge function Styles opposes the need for an export feature. When you call the function of load, you simply select the source document, then the individual styles that exist already in it. They need not be implemented beforehand.

  • Centering the table and cell borders.

    Hello, everyone:

    I am creating a tabular presentation and wish to have my main table (containing another table in some of its cells) is centered in the window of my browser so that as the viewer resizes the window web page design remains in the Middle both in horizontal and vertical plans. I found a command in Dreamweaver that allows me to Center a table on the horizontal plane, but nothing that allows me the same thing on the vertical plane. How can this be accomplished? I prefer to stay away from CSS that I'm still not familiar and sufficiently comfortable around her. I prefer to stay with a simple table layout.

    I also try to set fixed sizes for my table cells, but have not found a way to do it. I managed to create transparent GIF images to use as placeholders but (1) this seems to be too much work for something that probably can be accomplished in a much easier way and (2) the cells are not confined to the size of the GIFs and eventually larger than GIF images.

    Any suggestions will be appreciated.

    Thank you in advance,

    Joseph Chamberlain

    James:

    I thank you for your help and you have my apologies for this late reply.

    I looked at the link you provided and it has the answer to my question. Thank you once again. I wish just that there is a simpler and intuitive to do.

    Best regards

    Joseph Chamberlain

  • Table and cell borders

    I use CS4. I created a table style in my stylesheet that calls for an orange 2 px wide border. The border only described the entire table, but not individual cells. Anyone know how I can fix this in the stylesheet?
    The URL is http://www.virginiacpac.org/pages/conference.html
    Thank you

    Hello

    Try this:

    {.table_border}
    border-collapse: collapse;
    }
    .table_border td {}
    border: 2px solid #E2832F;
    padding: 2px;
    }

    Take care
    Tim

    "dlipscombe" wrote in message
    News:giekco$BQJ$1@forums. Macromedia.com...
    > I'm using CS4. I set up a table style in my stylesheet that calls for a 2
    > px
    > orange wide border. The border only outlines the entire table but not the
    > individual cells. Anyone know how I can fix this in the stylesheet?
    > The URL is http://www.virginiacpac.org/pages/conference.html
    > Thank you,
    >
    > .table_border {}
    > border: 2px solid #E2832F;
    > padding: 2px;
    > }
    >

  • tables and cell phone screen

    Does anyone know an html tag or css that can load another page, if the browser detects Web site is loaded on a phone screen?  or any other solution to put a couple of things in tables maybe so they load correctly on a mobile phone?  I have some pages I'm working very well and they load fine on my laptop and my MS Surface, but watching them in dreamweaver using the resolution feature, the tables don't look just to the right, so I would like to know if there is an alternative out there that might work and always show things in a table properly.

    Thank you.

    Use div tags 3 or more floating that breaks over a width of single column on smaller devices.

    CSS MEDIA QUERY

    =================

    @media only screen and (min-width: 769px) {}

    . Row {overflow: hidden}

    / * clear floats * /.

    . Row: after {}

    Clear: left;

    Display: block;

    content: '.';

    visibility: hidden

    }

    . Box {}

    Width: 33.33%;  / * 3 rows * /.

    float: left;

    }

    }

    HTML CODE:

    ================

    It's 1 box

    It is area 2

    It's box 3

    It's 1 box

    It is area 2

    It's box 3

    Nancy O.

  • I am self-taught and use since CS4 - archaic, tables, etc. for years smoothly other than those associated with tables and cells.

    I can not Dreamweaver to find the .jpgs I put on the remote server.  I can bring to the top of the page on the Internet, but not jpg - three on the page.

    I can't get Dreamweaver to keep the remote path.  I don't have local copies of my existing site on Dreamweaver.  The page works fine, links, etc.  I'm trying to add a page, not a site, but when the page is in place the jpgs will not appear.  My only choice in Dreamweaver are refferences "site" and the document.  I put the remote path in a zillion times in many ways.  But no connection.

    I created a new page and it is the only one that I'm trying to get the jpg images to be called from.  The remote page is: www.columbianexpositiontickets.com/All Pages/ferrispage/mainferris.htm ticket sales.  There are three JPGs on the page and everything just, I don't know how to change the situation where the jpg files will appear.

    I have three JPEG images in the folder 'ferrispage' and even a 'pictures' folder in the same folder.

    CS4, Win7.

    I do not know how to change the remote possibility, just "site" and "pertinent" are presented.  I sometimes get a "530 login incorrect.

    Drives me crazy, as everyone and suggestions would be appreciated.

    Thank you, Hal Hill

    Well, let's start with this unfortunate image in your source code:

    "height FTP://halhill:***@74.91.214.252/columbianexpositiontickets.com/All%20Ticket%20Sales%20page s/ferrispage/frontlargecert.jpg" ="388" border ="0" width = "500" > ".

    Immediately, I know what the problem with this link.  The question is do you have?

    TIP #1: %20 is spaces.  Use no spaces or special characters in web folder or file names.  She creates problems on the server.

    TIP #2: Remove all this:

    FTP://halhill:***@74.91.214.252/


    and replace with this:

    http://

    It is a problem solved.

    See if you can solve yourself the other paths of bad image.

    Nancy O.

  • Create and search the tables and apply the style

    Hello

    I am very new to scripting. I want to learn the basics like creating a table, creating anchored frames, frames of related texts, etc..

    Now, I want to create/search tables in a document, and I want to apply styles. I saw a script to do this. When I paste the Extendscript CS4 script, as the program crash.

    The crash of the program in part 1. When I create another script with only part 2 (see //part 2) then there is no problem.

    What I've done wrong? And can someone tell me what part 1 of the script do?

    Thank you

    Part 1

    using your version; I prefer return 0 if table not found
    function findTable (obj) { }
    while (obj.constructor.name! = 'Table') {
    obj = obj.parent;
    if (obj.constructor.name is 'Application') {
    throw 'Can't find table'
    }
    }
    return obj
    }

    Part 2


    var myTable = 0;
    if (app.documents.length > 0 & & app.selection.length > 0)
    myTable = findTable(app.selection[0]);

    check at least enough lines for 1 row from the top, 1 body line, row 1 down
    if (myTable! = 0 & & myTable.rows.length > = 3) {
    / / remove all the rules; INSET value 0
    myTable.cells.everyItem () .appliedCellStyle = "[None]";

    / / format row down
    / / (do not forget the lines use count 0-base)
    a = myTable.rows.length - 1;
    myTable.rows [a].cells.everyItem () .appliedCellStyle = "" 4.cell_body_last"";

    / / format stored
    first = 1;
    last = myTable.rows.length - 2;
    for (a = first; has < = last; ++ a)
    myTable.rows [a].cells.everyItem () .appliedCellStyle = "" 3.cell_body"";

    / / format the top row
    a = 0;
    myTable.rows [a].cells.everyItem () .appliedCellStyle = "" 2.cell_header"";
    }

    Part 1 provides that the text cursor to be anywhere inside of a table - in ordinary text, either with a cell, row, column or all of the selected table.

    He walks 'up' with his mother until he comes to the purpose of the table itself.

    This will work only if the text cursor is anywhere within a table. It does nothing when you're somewhere else, and it only works with the table 'ongoing'.

  • Apply a paragraph style to the first cell in the first row of a table

    I want to apply a paragraph style to the first cell in the first row of a table.

    I use JavaScript with ID CS 5.

    Thank you.

    . aragraphStyles.itemByName ("NameOfStyle") .p appliedParagraphStyle = app.activeDocument.paragraphStyleGroups.itemByName ("NameOfGroup")

  • Hello everyone. How can I make the styles for tables, I mean the table itself not the cells. A style that I can call for a table instead of copy paste an existinf one. Thanks for your help!

    And of course a table with cells embeded style styles...

    Have you tried to table styles (window > Styles > table style)?

  • With the last update, I am unable to merge cells in a table and Ive tried Split and Live view.

    With the last update, I am unable to merge cells in a table and Ive tried Split and viewing live, all the tutorial and manuals say to do in Design view, which is no longer available.  How to merge cells in a table now?

    To get the fashion Design back in a checkerboard to fluid...

    Close all other files, open the fluid grid css and add the X below:

    /*

    Properties Grid Dreamweaver fluid

    ----------------------------------

    DW-num-CLO-mobile: X 4;

    DW-num-CLO-Tablet: 8;

    DW-num-OCOL-Office: 12;

    DW-gutter-percentage: 25;

    =====================================

    Then save and close the file.

    DW restart and you should have mode Design from here out on all files using this fluid grid .css file.

  • CSS: apply the border of the table one table and not another

    I applied the underside of the table for all tables border on my site

    table { width: 100%; border-collapse: collapse; border-spacing: 0; } th, td{ border: 1px solid #999;

    How can I make no border on certain tables while keeping the border on the other?

    I tried to add only one class for some tables and elements and which does not:

    .borderlessTable {
      border
    : none;
    }

    Use CSS classes in your stylesheet.

    table.bordered {border: 1px solid #333}

    table {border: none}

    This table has borders

    This table has no borders

    Nancy O.

  • Character in the styles of table styles

    Hello world.

    I created my paintings so that all the other ranks are a dark blue fill, but keeps the text in the lines accordingly be white with the ulternate bloak text lines.

    Don't know if I'm able to do it quickly, for the moment I create the table and then selecting each other rtow manaually to change the style of text required

    @Garethirwin,

    That is right. There is no option to apply a cell style to every other row in a table style. This may require the manual approach that you already do.

    I suspect, it could be a film script, but I'm not a scripter and could not help you with that.

Maybe you are looking for