3 Replies Latest reply on Jun 1, 2016 7:09 AM by Trevorׅ

    Cleaning up the look of this script ?

    cbishop01 Level 2

      Hello I've had a ton of help on here for this script. I have done some changes and was just wondering if it was possible to clean it up Below is the Picture and Script so far. I would like the script to look like the bottom Table on this pic.  The top pic is Whats actually WOrking right now.  Any Help would be greatly appreciated.

      Screen Shot 2016-05-31 at 4.45.13 PM.png

      Here's the Script.

         function doTextFrameOnPageOne()  
       // Name of the Text Frame The Save information is in.
          var myBlendingSettings = { blendMode : BlendMode.OVERLAY };  
          var myTransparencySettings = { blendingSettings : myBlendingSettings };   
          var doc, tf, tvINFO, ip;  
              doc = app.activeDocument;  
      // TEXT FRAME PROPERTIES        
              tf = doc.pages[0].textFrames.add({ fillColor :"Yellow", fillTint: 20, transparencySettings : myTransparencySettings, geometricBounds: ['-.75','-4.45in','1.5in','-.75in'] });
      // Text frame information
              ip = tf.insertionPoints;
              ip[-1].contents = "Document:"+"\t "+ doc.name  +'\r'; 
              ip[-1].contents = "User Name:" +"\t"+ getAppUserName() +'\r';
              ip[-1].contents = "Computer Name:" +"\t"+ getLogInUserName()+'\r';
              tvINFO = ip[-1].textVariableInstances.add(LocationOptions.AFTER, ip[-1]);  
              "Date Modified:" +'\t'; tvINFO.associatedTextVariable = doc.textVariables.itemByName("Modification Date");  
              ip[-1].contents = '\r';
              tvINFO = ip[-1].textVariableInstances.add(LocationOptions.AFTER, ip[-1]);  
              tvINFO.associatedTextVariable = doc.textVariables.itemByName("Output Date");  
              ip[-1].contents = '\r';  
              tvINFO = ip[-1].textVariableInstances.add(LocationOptions.AFTER, ip[-1]);  
              tvINFO.associatedTextVariable = "Date Created:" +'\t'; doc.textVariables.itemByName("Creation Date");  
       // Change Properties of Text Frame.:                  }  


      Thank you


      Chris bishop

        • 1. Re: Cleaning up the look of this script ?
          Laubender Adobe Community Professional & MVP

          This is a question basically about creating a table with ExtendScript for InDesign.


          Basically you have two options here:


          [ A ] Convert the text in your text frame to a table

          [ B ] Create a new table and assign the contents via the contents property of the table


          [ A ] would basically work for you.

          But as I can see from your first screen capture it would not work as expected, if you are transforming your current contents into a table, because you are missing the necessary contents of column one for some rows. Plus the deviding tabulators. If you would provide that, you could use the following code:




          [ B ] Would work with the result of your functions and methods and the necessary strings for column one and two stored into one or two arrays.



          var columnOneContentsArray = 
               "Document:" ,
               "User Name:",
               "Output Date:"
          var columnTwoContentsArray = 
               "USE FOR TEST SCRIPTS.indd" ,
               "Chris Bishop" ,
               "" // Not really necessary to use an empty string, but could be used to indicate, that this cell will be empty for now.
          var doc = app.documents.add();
          var tf = doc.textFrames.add({geometricBounds : [0,0,"100mm","100mm"]});
          var myTable = tf.texts[0].tables.add
                    bodyRowCount : 3 , // You could use a larger number here, even if your contents array uses less entries.
                    columnCount : 2 
                    // Use other property/value pairs to define the width of the table, stroke weights, fill color etc.pp.
                    // ...
          myTable.columns[0].contents = columnOneContentsArray;
          myTable.columns[1].contents = columnTwoContentsArray;


          In your specific case you would leave out the contents of your text variables in the columnTwoContentsArray and substitute their contents with an empty string "" perhaps.


          Later, after creating the table, you would insert the text variable in the right cell using the first insertion point of the cell.


          var cell3OfColumn2insertionPoint1 = myTable.columns[1].cells[2].insertionPoints[0];
          var tvINFO = cell3OfColumn2insertionPoint1.textVariableInstances.add(LocationOptions.AFTER, cell3OfColumn2insertionPoint1);    
          tvINFO.associatedTextVariable = doc.textVariables.itemByName("Output Date");


          Warning: Check before, if your text variable already exists in your document.

          If yes, use the existing one. If not, create a new one.

          Note: I did not test the snippet with the text variable above.


          Btw.: This thread should go to the InDesign Scripting forum.

          InDesign Scripting



          1 person found this helpful
          • 2. Re: Cleaning up the look of this script ?
            Trevorׅ Adobe Community Professional



            An alternative approach would be to add the following line to the end of the function (Before the closing bracket!)




            • 3. Re: Cleaning up the look of this script ?
              Trevorׅ Adobe Community Professional

              Sorry Uwe I didn't see that in your answer. I should have looked more carefully!