11 Replies Latest reply on Mar 8, 2017 7:40 AM by Laubender

    Unexpected result of: myCell.contents

    AdobeScripting

      Hello,

       

      I have an Indesign-Table with 4 Rows, it contains Text in the2nd and 3rd row.

       

      We can read the cell-Content of the 2nd row, however we can't read the cell-Content of the 3rd row.

      The code-line firstCellOfThirdRow.contents should provide the value: "MyTextB". However we get a cryptical letter which looks like 'T'.

      Any ideas ?

       

      MyTextA
      MyTextB

       

       

      The Indesign-Template:

      http://www.com-active.de/downloads/ProblematicTable.zip

       

      Here's the code:

       

      // Second Table-Row
      var secondRow = myTable.rows[1];
      var firstCellOfSecondRow = secondRow.cells[0];
      var content2 =  firstCellOfSecondRow.contents;  // "MyTextA"

       

      // Third Table-Row
      var  thirdRow = myTable.rows[2];
      var firstCellOfThirdRow = thirdRow.cells[0];
      var content3 =  firstCellOfThirdRow.contents; // I expected "MyTextB", but that's not the case. Why?

        • 1. Re: Unexpected result of: myCell.contents
          BSKTCreation Level 2

          Hi,

           

          There's something funny with the table. At the end of the 3rd row there are 2 overlapping hash symbols. Turn your hidden characters on and you'll see it. When I use your code on a table I make it has no error. My suggestion is replace the old table with a new one.

           

          Regards,

          Brett

          • 2. Re: Unexpected result of: myCell.contents
            [Jongware] Most Valuable Participant

            It's not a cell inside a table but a table of its own, nested inside the other one.

             

            Accessing the 'contents' forces Javascript here to find a character representation for the cell contents, and so the internal code 0x16 for a table gets converted into the character 22 - which is not a standard character code, and you get something random: sort of a small capital T.

             

            Select that inner table and then choose "Convert to Text" to circumvent the mystery, or rewrite your script to be able to handle tables-within-tables.

            • 3. Re: Unexpected result of: myCell.contents
              AdobeScripting Level 1

              > It's not a cell inside a table but a table of its own, nested inside the other one.

               

              Thank you, that explains everything !

              • 4. Re: Unexpected result of: myCell.contents
                Pickory Level 3

                Story Editor is handy for spotting those funnies.

                 

                P.

                • 5. Re: Unexpected result of: myCell.contents
                  Laubender Adobe Community Professional & MVP
                  myCell.texts[0].tables.length;
                  

                   

                  should reveal the one-cell table nested.

                   

                  Or, if you want a quick overview to indicate, if any nested tables are in the cells of a table:

                   

                  myTable.cells.everyItem().texts.everyItem().tables.length;
                  

                   

                  Uwe

                  • 6. Re: Unexpected result of: myCell.contents
                    JeffArdoise Level 1

                    Ok so you teased that we should just handle table-within-tables, but HOW. I've been looking for this in Applescript, is there anyway to do it?

                     

                    I've used the every table of every story, but it doesn't get tables within tables. Neither will a repeat loop through storyies and tables.

                     

                    Sorry if I'm replying to an already supposedly answered question:-)

                    • 7. Re: Unexpected result of: myCell.contents
                      Laubender Adobe Community Professional & MVP

                      Hi Jeff,

                      you could also do a TEXT search with the special character that constitutes a table in the text.
                      That's even better, because you can access all nested structures of arbitrary depth.

                       

                      In the UI that would be:

                      TEXT search:
                      <0016>

                       

                      With ExtendScript—sorry I cannot tell for AppleScript—that would be:

                       

                      // Special character for a table in the text is Unicode 0016:
                      app.findTextPreferences.findWhat = "<0016>";
                      
                      // Scope is the active document:
                      var tableCharactersArray = app.documents[0].findText();
                      var tablesArray = [];
                      
                      for(var n=0;n<tableCharactersArray.length;n++)
                      {
                      tablesArray[n] = tableCharactersArray[n].texts[0].tables[0];
                      };
                      alert(tablesArray.length+" tables found in document "+app.documents[0].name);
                      

                       

                      That trick does NOT work with a GREP search for: \x{0016}.

                      Not in the UI, not by scripting.

                       

                      Regards,
                      Uwe

                      • 8. Re: Unexpected result of: myCell.contents
                        JeffArdoise Level 1

                        Thanks Uwe,

                        I'm not well versed in ExtendScript so I'm having a hard time "translating" this into applescript.

                         

                        I got this so for, but ID crashes overtime I run it, so not good.

                         

                        tell application "Adobe InDesign CC 2014"

                          tell active document

                          my TableFind("<0016>")

                          set myTableList to change text

                          get myTableList

                          end tell

                        end tell

                         

                         

                         

                         

                        on TableFind(myFindText)

                          tell application "Adobe InDesign CC 2014"

                          set find text preferences to nothing

                          set change text preferences to nothing

                          --Search the document for the string

                          set find what of find text preferences to myFindText

                          set case sensitive of find change text options to false

                          set include footnotes of find change text options to false

                          set include hidden layers of find change text options to false

                          set include locked layers for find of find change text options to false

                          set include locked stories for find of find change text options to false

                          set include master pages of find change text options to false

                          set whole word of find change text options to false

                          end tell

                        end TableFind

                         

                        I'm trying to put what was found into a variable but that doesn't seem to work. I don't know how to search, but not replace a text, and put every item found in an array (or list in AS).

                         

                        Maybe someone else more versed in AS will chime in?

                         

                        Jeff

                        • 9. Re: Unexpected result of: myCell.contents
                          Laubender Adobe Community Professional & MVP

                          Hi Jeff,

                          as I said, I'm really not into AppleScripting.
                          Why do you: set myTableList to change text ?
                          In that phase we do not want to change anything.

                          We would like to find something and work with the found List object.

                           

                           

                          So it could be more like that:

                          set myTableList to find text

                           

                          That would store—at least I hope—the found special characters in a List object.


                          I understand, that such a List object is something like an Array object in ExtendScript.
                          With at least one method we do not have in ExtendScript for InDesign: for each

                           

                          The code below is from an AppleScript noob (me) and should not taken very seriously.

                          Feeding a second list with objects derived from the result of the GREP search is throwing an error

                          The effective lines would be 51 to 53 that I commented out here:

                           

                          -- AppleScript
                          
                          tell application "Adobe InDesign CS6"
                              
                              --Variable definitions:
                              set myDoc to active document
                              set myTableList to {}
                              
                              --Clear the find/change preferences:
                              
                              set find text preferences to nothing
                              set change text preferences to nothing
                              
                              --Set the "find what" property of the find text prefs:
                              
                              set find what of find text preferences to "<0016>"
                              
                              --Set the find options in case you need them (currently all commented out):
                              
                              --set case sensitive of find change text options to false
                              --set include footnotes of find change text options to true
                              --set include hidden layers of find change text options to true
                              --set include locked layers for find of find change text options to true
                              --set include locked stories for find of find change text options to true
                              --set include master pages of find change text options to true
                              --set whole word of find change text options to false
                              
                              --Define the scope of the search.
                              --Scope of script is active document:
                              
                              tell myDoc
                                  
                                  set myFoundTableCharactersList to find text
                                  
                              end tell
                              
                              log (count of myFoundTableCharactersList)
                              
                              --PSEUDO CODE AHEAD:
                              --because I do not know about the right syntax here:
                              
                              --Feeding another List with tables
                              --In ExtendScript that would be:
                              --for(var n=0;n<myFoundTableCharactersList.length;n++)
                              --{
                              --myTableList[n] = myFoundTableCharactersList[n].texts[0].tables[0];
                              --}
                              
                              --I tried that with AppleScript, but I will get an error:
                              repeat with x from 1 to count of myFoundTableCharactersList
                                  
                                  --set end of myTableList to table 1 of text 1 of x of myFoundTableCharactersList
                                  
                              end repeat
                              
                              --Clear the find text preferences:
                              
                              set find text preferences to nothing
                              
                              --Do something with the list of tables myTableList
                              --Loop them and change width perhaps or something
                              -- …
                              log (count of myTableList)
                              
                          end tell
                          

                           

                          After testing a bit with some variants of the loop I'm not sure at all if AppleScript will allow this:

                           

                          // Feed array with the first table of the first text of the found character:
                          myTableList[n] = myFoundTableCharactersList[n].texts[0].tables[0];
                          

                           

                          Regards,
                          Uwe

                          • 10. Re: Unexpected result of: myCell.contents
                            JeffArdoise Level 1

                            Thanks Uwe!

                             

                            I could finally fix the part that didn't work for you in Applescript. There is a couple of place where I don't know why you put that in, like the two log lines. Where Do I see the results of those logs in Script editor, or Script debugger?

                             

                            Anyway, here's what works for me. I haven't put all what I'm doing with the table but you can see that the script works with the set width for the cells.

                             

                            -------------------Start of applescript

                            tell application "Adobe InDesign CC 2014"

                             

                              --Variable definitions:

                              set myDoc to active document

                              --set myTableList to {} --don't know why you declared that variable here either

                             

                              --Clear the find/change preferences:

                             

                              set find text preferences to nothing

                              set change text preferences to nothing

                             

                              --Set the "find what" property of the find text prefs:

                             

                              set find what of find text preferences to "<0016>"

                             

                              --Set the find options in case you need them (currently all commented out):

                             

                              --set case sensitive of find change text options to false

                              --set include footnotes of find change text options to true

                              --set include hidden layers of find change text options to true

                              --set include locked layers for find of find change text options to true

                              --set include locked stories for find of find change text options to true

                              --set include master pages of find change text options to true

                              --set whole word of find change text options to false

                             

                              --Define the scope of the search.

                              --Scope of script is active document:

                             

                              tell myDoc

                              set myFoundTableCharactersList to find text

                              end tell

                             

                              log (count of myFoundTableCharactersList)

                              repeat with i from (count of myFoundTableCharactersList) to 1 by -1

                              --set end of myTableList to table 1 of text 1 of x of myFoundTableCharactersList

                              set myTable to table 1 of text 1 of item i of myFoundTableCharactersList --since this is not a list but adresse each table individually, I changed name to myTable

                              tell cells of myTable

                              set width to "150 pt"

                              end tell

                              end repeat

                              get myTableList

                             

                              --Clear the find text preferences:

                              set find text preferences to nothing

                             

                            end tell

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

                            So thanks again!

                            • 11. Re: Unexpected result of: myCell.contents
                              Laubender Adobe Community Professional & MVP

                              Hi Jeff,

                              thank you for correcting the AppleScript code.

                              Glad, it's working for you now.

                               

                              And personally I'm glad that I can turn back to my ExtendScript (JavaScript) dot notation :-)

                               

                              Ah. About the log line:
                              Check the Event Protocol with your AppleScript Editor.
                              I see output from log like that: (*2*)

                               

                              Regards,
                              Uwe