1 Reply Latest reply on Nov 6, 2016 11:45 AM by Jump_Over

    Code to be evaluated! [006] // Create round corner table(s)! …

    Obi-wan Kenobi Adobe Community Professional

      Hi all Scripters!

       

      Depending on what is the target (doc, story, one table or tables contained in a text selection), this code is supposed to round table corners"!

      At the moment, it just round my brain pea!!  In other words, nothing happens!!! 

       

      Ideas?!

      [note: The text frame that receives the table has a "RoundCornerTable" object style whose an option is "round corners"!]

       

      Thanks as usual for any help! 

       

       

      app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;      
      app.doScript(main, ScriptLanguage.JAVASCRIPT, [], UndoModes.ENTIRE_SCRIPT, "Round Corners Tables! …" );
            
      function main()      
      {
      
      
      (function () {  
        
          function getTables () {  
              if (app.selection.length == 0) return app.documents[0].stories.everyItem().tables.everyItem().getElements();  
              else if (app.selection[0].tables.length > 0) return app.selection[0].tables.everyItem().getElements();  
              else if (app.selection[0].parent instanceof Cell) return [app.selection[0].parent.parent];  
              else if (app.selection[0].hasOwnProperty ('parentStory')) return app.selection[0].parentStory.tables.everyItem().getElements();  
          }  
        
          function RoundCornerTables (tables) {  
              for (var t = tables.length-1; t >= 0; t--) {  
                      var scores = app.documents[0].stories.everyItem().characters[tables[t].storyOffset.index];
                      frame = scores.insertionPoints[-1].textFrames.add();  
                      scores[t].characters.itemByRange (0, scores[t].characters.length-2).move (LocationOptions.after, frame.insertionPoints[0]);  
                      frame.applyObjectStyle (myDoc.objectStyles.item('RoundCornerTable'));  
              }  
          }  
         
          if (app.documents.length > 0)  RoundCornerTables (getTables());  
        
      }());
      
      
      }
      

       

      (^/)

       

      PS: Even if somebody fixes my issue, the script is not finished!

       

      Last question: Why, when I place a table (no external stroke) in a text frame with round corners, do we see little white "gaps"?

      See "red" stroke table!  For the "green" stroke table, I used another way!

       

      Capture d’écran 2016-11-05 à 15.34.03.png

       

      Zoom:

       

      Capture d’écran 2016-11-05 à 15.34.27.png

        • 1. Re: Code to be evaluated! [006] // Create round corner table(s)! …
          Jump_Over Level 5

          Hi,

           

          About getTables():

          I can see some misses here:

          • case 2 and 4 do almost the same ( if text selected)
          • if user select a part of table (cells, column) - no case to return

           

          I suggest to clarify a target for your script.

          Assuming the target is an array of tables ==> lets switch

          case 'text inside a table OR table OR part of table selected': return 1-element array with THIS table only

          case 'text outside table is selected': return an array with every table found in entire parentStory

          case 'textFrame is selected': return array of tables located in this textFrame only

          otherwise: return every table found in a doc (array)

           

          It shouldn't be a problem to switch by selection properties (alike you do with some modification)

           

          About RoundCornerTables()

          Assuming there is an array of table returned as input to 2nd function.

          1 question - which version of InDesign is in use? Does it allow method textFrame.add() for insertionPoint object? CS5 doesnt.

          2nd question - why do you set a var scores as an array of everyStory.characters[THIS table storyOffset].index ?

           

          I suggest to call simply ThisTable.storyOffset. It is an insertionPoint (object) which can be your current target for further proccessing. (still using backward loop of cource).

           

          So there are 2 more question left:

          1. How to create a textFrame

          2. How to fit this frame to current table size

           

          both depends on version of InDesign in use so I break here...

           

          Jarek