2 Replies Latest reply on Jun 20, 2011 11:18 PM by John Hawkinson

    How to select "next object below"?

    Kan7

      Hi all,

       

      I have selected group objects then How to select "next object below" frames using javascript in indesign cs3?

        • 1. Re: How to select "next object below"?
          milligramme Level 3

          Hi

          I interpreted you request as this figure below.

          It works for me IDCS3 OSX 10.6.7

           

          groupobject ( pageitem A-E)

            ├pageitem A

            ├pageitem B

            ├pageitem C

            ├pageitem D

            ├pageitem E

           

          1. Current selection is B and run script.

          2. C is selected

          3. And then, current selection is E and run script.

          4. A is selected

          // select a pageitem in group object

          if (app.selection.length === 0) {exit();};

          if (app.selection[0].parent.constructor.name !== 'Group') {exit()};

           

          var current_sel = app.selection[0];

          var current_id = current_sel.id;

          var parent_group = current_sel.parent;

          for (var i=0, iL=parent_group.pageItems.length; i < iL ; i++) {

               if (parent_group.pageItems[i].id === current_id) {// current object

                    // select next object

                    if (i+1 < iL) {

                         parent_group.pageItems[i+1].select();

                    }

                    else { // if selected last object, select first object

                         parent_group.pageItems[0].select();

                    }

               };

          };

          thank you
          mg.

          • 2. Re: How to select "next object below"?
            John Hawkinson Level 5
                      // select next object
                      if (i+1 < iL) {
                         parent_group.pageItems[i+1].select();
                      }
                      else { // if selected last object, select first object
                         parent_group.pageItems[0].select();
                      }
            
            

             

            Instead, just use the modulo (remainder) operator, % sign.:

             

            parent_grouppageItems[(i+1)%iL].select()