1 Reply Latest reply on Dec 31, 2016 4:33 AM by Obi-wan Kenobi

    Code to be evaluated! [013] Auto-numbering Bullets and wrapping! …

    Obi-wan Kenobi Adobe Community Professional

      Hi all!

       

      A nice layout headache to finish the year! …

       

      Video:  Bullets Wrapping Layout! … - YouTube

       

      Capture d’écran 2016-12-30 à 18.45.34.png

      Capture d’écran 2016-12-30 à 18.44.56.png

      Capture d’écran 2016-12-30 à 18.45.14.png

       

      Cool to imagine and write! … but Hot for me!

       

      Thanks for your comments! 

       

      app.doScript("main()", ScriptLanguage.javascript, undefined, UndoModes.FAST_ENTIRE_SCRIPT, "Bullets + Wrapping! …");  
        
      function main()  
      {
      
      
          var myDoc = app.activeDocument;
      
      
          var savedHorizontalMeasurementUnits = myDoc.viewPreferences.horizontalMeasurementUnits;  
          var savedVerticalMeasurementUnits = myDoc.viewPreferences.verticalMeasurementUnits;  
          myDoc.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.POINTS;  
          myDoc.viewPreferences.verticalMeasurementUnits = MeasurementUnits.POINTS;
      
      
          var myParas = app.selection[0].paragraphs.everyItem().getElements();    
          var P = myParas.length;
      
      
          while (P--)
              {
                  app.findGrepPreferences = app.changeGrepPreferences = null;
                  app.findGrepPreferences.findWhat = "^(~a|~i)";
                  app.changeGrepPreferences.changeTo = "";
                  myParas[P].changeGrep();
              }
        
          ///////  FIRST PARA ///////
      
      
          var myP = myParas[0];
          
          var myL = myP.lines;
          var L = myL.length;
      
      
          while ( L-- )
              {
                  var A = myL[L].insertionPoints[0].horizontalOffset;
                  var B = myL[L-1].insertionPoints[0].horizontalOffset;
                  if ( A != B )
                  {
                      var myX = myL[L].insertionPoints[0].horizontalOffset;
                      var myY = myL[L].characters[0].baseline;
                      var myH = myL[L].paragraphs[0].characters[-1].baseline - myY;
                      myAnchor = myL[L].paragraphs[0].insertionPoints[0].rectangles.add({geometricBounds: [myY, myX, myY + myH, myX + UnitValue('5mm').as('pt')]});
                      myAnchor.appliedObjectStyle = myDoc.objectStyles.item("In-Visible");
      
      
                      var myGB = myAnchor.geometricBounds;
      
      
                      var transMatrix = app.transformationMatrices.add({verticalTranslation: myY - myGB[0] - 1, horizontalTranslation: myX - UnitValue('10mm').as('pt')});  
                      myAnchor.transform(CoordinateSpaces.PASTEBOARD_COORDINATES, AnchorPoint.TOP_LEFT_ANCHOR, transMatrix);
                      break;
                  }
              }
      
      
          var myParas = app.selection[0].paragraphs.everyItem().getElements();    
          var P = myParas.length;
      
      
          ///////  INTERMEDIATE PARAS ///////
      
      
          for ( var p = 1; p < P-1 ; p++ )
              {  
                  var myP = myParas[p];
          
                  app.findGrepPreferences = app.changeGrepPreferences = null;
                  app.findGrepPreferences.findWhat = "~a|~i";
                  app.changeGrepPreferences.changeTo = "";
                  myP.changeGrep();
      
      
                  app.findGrepPreferences = app.changeGrepPreferences = null;
                  app.findGrepPreferences.findWhat = "^.";
                  app.changeGrepPreferences.changeTo = "~i$0";
                  myP.changeGrep();
                  app.findGrepPreferences = app.changeGrepPreferences = null;
              }
      
      
          ///////  LAST PARA ///////
      
      
          var myP = myParas[P-1];
          
          var myL = myP.lines;
          var L = myL.length;
      
      
          while ( L-- )
              {
                  var A = myL[L].insertionPoints[0].horizontalOffset;
                  var B = myL[L-1].insertionPoints[0].horizontalOffset;
                  if ( A != B )
                  {
                      var myY0 = myL[1].baseline;
                      var myX1 = myL[1].insertionPoints[0].horizontalOffset;
                      var myY2 = myL[L-1].baseline;
                      var myX3 = myX1+ UnitValue('5mm').as('pt');
                      myAnchor = myL[1].insertionPoints[0].rectangles.add({geometricBounds: [myY0, myX1, myY2, myX3]});
                      myAnchor.appliedObjectStyle = myDoc.objectStyles.item("In-Visible");
                      exit();
                  }
              }
         
          myDoc.viewPreferences.horizontalMeasurementUnits = savedHorizontalMeasurementUnits;  
          myDoc.viewPreferences.verticalMeasurementUnits = savedVerticalMeasurementUnits;  
      
      
      }
      

       

      (^/)