7 Replies Latest reply on Jul 15, 2014 8:55 AM by HarveyLiu

    Can you fix scripts problem?

    HarveyLiu Level 1

      I got these three script, their work very well, but not in the cell, can you fix it:

       

      Script 1:

       

      00.// left Indent: whatever, firstLineIndent: 8 mm 
      01. 
      02.var curDoc = app.activeDocument; 
      03. 
      04.if ( !app.selection.length ) { 
      05.    var paras = curDoc.stories.everyItem().paragraphs; 
      06.} 
      07.else if(app.selection.length == 1 && app.selection[0].hasOwnProperty( “baseline” )) { 
      08.        var paras = app.selection[0].paragraphs; 
      09.} 
      10.else { 
      11.    alert(“Something wrong with your selection!”); 
      12.    exit(); 
      13.} 
      14. 
      15.paras.everyItem().firstLineIndent = “8mm”; 

       

       

      Script 2:

       

      01.// left Indent: whatever, firstLineIndent: 0 
      02. 
      03.var curDoc = app.activeDocument; 
      04. 
      05.if ( !app.selection.length ) { 
      06.    var paras = curDoc.stories.everyItem().paragraphs; 
      07.} 
      08.else if(app.selection.length == 1 && app.selection[0].hasOwnProperty( “baseline” )) { 
      09.        var paras = app.selection[0].paragraphs; 
      10.} 
      11.else { 
      12.    alert(“Something wrong with your selection!”); 
      13.    exit(); 
      14.} 
      15. 
      16.paras.everyItem().firstLineIndent = “0mm”; 

       

       

      Script 3:

       

      01.// left Indent: 8 mm, firstLineIndent: -8 mm 
      02. 
      03.var curDoc = app.activeDocument; 
      04. 
      05.if ( !app.selection.length ) { 
      06.    var paras = curDoc.stories.everyItem().paragraphs; 
      07.} 
      08.else if(app.selection.length == 1 && app.selection[0].hasOwnProperty( “baseline” )) { 
      09.        var paras = app.selection[0].paragraphs; 
      10.} 
      11.else { 
      12.    alert(“Something wrong with your selection!”); 
      13.    exit(); 
      14.} 
      15. 
      16.for ( var i = 0; i < paras.length; i ++ ) { 
      17.    var curPara = paras[i]; 
      18.    if ( curPara.leftIndent == 0 ) { 
      19.        curPara.leftIndent = “8mm”; 
      20.    } 
      21.    curPara.firstLineIndent = “-8mm”; 
      22.} 

        • 1. Re: Can you fix scripts problem?
          Kai Rübsamen Adobe Community Professional

          Harvey, if you use the advanced editor, you see also a button called "insert". Here you will find "syntaxhighlighting" > javascript. Please use this, if you post code.

           

          I change the lines only for the first script. As lesson for you, change the additonal lines by yourself!

           

          The script will work if nothing is selected, if a textframe is selected or if some paragraphs and a table are selected. It will not work, if only specific rows are selected.

           

          // left Indent: whatever, firstLineIndent: 8 mm  
            
          var curDoc = app.activeDocument;  
            
          if ( !app.selection.length ) {
            var allStories = curDoc.stories.everyItem();
              var paras = allStories.paragraphs.everyItem(); 
              var parasInTables = allStories.tables.everyItem().cells.everyItem().paragraphs.everyItem();    
          }  
          else if( app.selection.length == 1 && ( app.selection[0].hasOwnProperty( "baseline" ) || app.selection[0].constructor.name == "TextFrame" ) ) {  
              var paras = app.selection[0].paragraphs.everyItem();  
              var parasInTables = app.selection[0].tables.everyItem().cells.everyItem().paragraphs.everyItem();    
          
          }  
          else {  
              alert( "Something wrong with your selection!" );  
              exit();  
          }  
            
          paras.firstLineIndent = "8mm"; 
          parasInTables.firstLineIndent = "8mm";
          
          • 2. Re: Can you fix scripts problem?
            HarveyLiu Level 1

            thank you , thank you for your help,

             

            but I still get this error:

             

            222.jpg

            • 3. Re: Re: Can you fix scripts problem?
              Kai Rübsamen Adobe Community Professional

              Harvey,

               

              an alert is not an error. Try this one:

               

              // left Indent: whatever, firstLineIndent: 8 mm
              
              // das aktive Dokument
              var curDoc = app.activeDocument;
              // Anzahl der ausgewählten Objekte
              var nSel = app.selection.length;
              
              // wenn nichts ausgewählt ist
              if ( nSel == 0 ) {
                  // alle Textabschnitte im Dokument
                  var allStories = curDoc.stories.everyItem();
                  // alle Absätze in Textabschnitten
                  var paras = allStories.paragraphs.everyItem();
                  // alle Absätze in Tabellen (wirft Fehler, wenn es keine Tabellen gibt!)
                  try {
                      var parasInTables = allStories.tables.everyItem().cells.everyItem().paragraphs.everyItem();
                  }
                  catch (e) {
                  }
                  makeIndent( paras, parasInTables );
              }
              // wenn etwas ausgewählt ist
              else {
                  // Hilfszähler
                  var probCtr = 0;
                  // Eine Schleife durch die Auswahl
                  for ( var n = 0; n < nSel; n++ ) {
                      var curSel = app.selection[n];
                      // der Typ der aktiven Auswahl
                      var selType = curSel.constructor.name;
                      // prüfen, ob Text (inkl. Tabelle) oder Textrahmen ausgewählt ist
                      if ( curSel.hasOwnProperty ( "baseline" ) || selType == "TextFrame" ) {
                          var paras = app.selection[n].paragraphs.everyItem();
                          try {
                              var parasInTables = app.selection[n].tables.everyItem().cells.everyItem().paragraphs.everyItem();
                          }
                          catch (e) {
                          }
                      }
                      // falls nur eine Tabelle ausgewählt ist
                      else if ( selType == "Table" ) {
                          var parasInTables = app.selection[n].cells.everyItem().paragraphs.everyItem();
                      }
                      // wenn eine Zelle ausgewählt ist
                      else if ( selType == "Cell" ) {
                          var parasInTables = app.selection[n].paragraphs.everyItem();
                      }
                      // falls etwas anderes ausgewählt ist
                      else {
                          // Hilfszähler wird hochgezählt, Schleife aber nicht abgebrochen
                          probCtr++;
                      }
                      makeIndent( paras, parasInTables );
                  } // end for
                  if ( probCtr == n ) {
                      // der Hinweis erfolgt nur, wenn die Auswahl gar nicht passt. Ansonsten werden "falsche" Objekte einfach ignoriert.
                      alert ( "Something wrong with your selection!" );
                      exit();
                  }
              } // end else
                  
              
              // die Einzüge verändern
              function makeIndent( paras, parasInTables ) {
                  try {
                      paras.firstLineIndent = "8mm";
                  }
                  catch (e) {
                  }
                  try {
                      parasInTables.firstLineIndent = "8mm";
                  }
                  catch (e) {
                  }
              }
              
              • 4. Re: Can you fix scripts problem?
                HarveyLiu Level 1

                Hi,

                 

                 

                • 5. Re: Can you fix scripts problem?
                  Kai Rübsamen Adobe Community Professional

                  Harvey, as promissed: Have a look at the function makeIndent() and change these lines for the other two scripts by yourself.

                  I notice that you often ask here for a script. So the goal is, not to ask for everything, instead learn how to read (not to write) scripts.


                  If you can read scripts, it is easy to change them for your own needs .

                  –Kai

                  • 7. Re: Can you fix scripts problem?
                    HarveyLiu Level 1

                    I have changed it already

                     

                    thank you