5 Replies Latest reply on Feb 15, 2014 7:36 AM by MadMac55

    Stacking, Snapping & Align in one script

    MadMac55 Level 1

      Try to imagine a series of 4-5 elements errantly on the page.

       

      And a script that Ungroups if grouped, that Aligns to the nearest column guide left, and that Distributes Vertical Spacing using 0p0 values.

       

      Does anyone have a trick up their sleeve?

        • 1. Re: Stacking, Snapping & Align in one script
          MadMac55 Level 1

          It might be ambitious to check for grouping, then ungroup, etc ...  but I do have this going.

           

           

          This segment will align all selected objects to the nearest left column margin.   My next hurdle is to find out how to Distribute Vertical Space by 0p0.

           

           

          Main();

          function Main() {

          var myDoc = app.documents[0];

          var myPage = myDoc.spreads[0].pages[0];

          var myBounds = app.selection[0].geometricBounds;

          var myLeft = myDoc.marginPreferences.left;

          var myColCount = app.activeDocument.pages[0].marginPreferences.columnCount;

          var myColDefs = app.activeDocument.pages[0].marginPreferences.columnsPositions;

           

           

          for(myCounter = 0; myColDefs[myCounter] < myBounds[1] ; myCounter += 2 ){

                          myNewX2 = myColDefs[myCounter] + myLeft;

                          myNewY2 = myBounds[3] + myLeft - (myBounds[1]-myNewX2+myLeft);

           

           

          app.selection[0].geometricBounds = [myBounds[0], myNewX2, myBounds[2], myNewY2];

           

           

          }

          }

          • 2. Re: Stacking, Snapping & Align in one script
            [Jongware] Most Valuable Participant

            MadMac55 wrote:

             

            [...] My next hurdle is to find out how to Distribute Vertical Space by 0p0.

             

             

            Quick thought: you can try http://jongware.mit.edu/idcs6js/pc_Document.html#distribute -- use its last two optional parameters.

            • 3. Re: Stacking, Snapping & Align in one script
              MadMac55 Level 1

              Hah!  I was just noodling around in there.   For some reason, the snapLeft (column guide) broke.   Trying to fix that.   It does nothing.  Ugh!!!

              • 4. Re: Stacking, Snapping & Align in one script
                MadMac55 Level 1

                Hell freezes over — I found the (incredibly simple) answer searching and learning.   I have so much to learn, I'm reading in my spare time, but I need to stick with it.

                 

                 

                var myDoc = app.activeDocument;

                var mySel = myDoc.selection;

                myDoc.distribute(mySel, DistributeOptions.VERTICAL_SPACE, AlignDistributeBounds.ITEM_BOUNDS);

                app.activeDocument.align (app.selection, AlignOptions.LEFT_EDGES);

                • 5. Re: Stacking, Snapping & Align in one script
                  MadMac55 Level 1

                  Just a note ...   this does not find grouped objects, then ungroup, align and regroup.  It also does not align to nearest, left-most columngutter or column guide.   A work in progress, but I'm happy so far.