4 Replies Latest reply on Apr 20, 2016 11:16 AM by S Hopkins

    Is there a script that can chang Multiple object into same width(I need width)?

    喜狼_edny Level 1

      For example,I want to Change 3 object's width to 40mm, also,Their high is changed with wide

      It can also be applied to the picture,and object.

      Thanks~~

      I've asked for a long time before, but I can't set my value.

       

      Change+the+width+of+objects.jpg

        • 1. Re: Is there a script that can chang Multiple object into same width(I need width)?
          dnyaneshlb Level 1

          Hello,

           

          I am not InDesign developer but I write scripts for Illustrator. I think its straight forward.

           

          var  doc = app.activeDocument;

          var items = doc.groupItems;

          for(var index=0; index<items.length; index++)

          {

               var item = items[index];

               item.width = 40;

               item.height = 30;

               if(index=0)

               {

                    item.top = 0;

                    item.left = 0;

               }

               else

               {

                    item.top = 0;

                    item.left = items[index-1].width+10; // 10 is spacing you want in terms of pixels

               }

          }

           

           

          This is vague code I have written (not tested). There can be syntax errors. But all in all the script is self explanatory.

           

          Cheers,

          Dnyanesh

          • 2. Re: Is there a script that can chang Multiple object into same width(I need width)?
            喜狼_edny Level 1

            Thankyou very much,dnyaneshlb

            but it dosn't work~~

            • 3. Re: Is there a script that can chang Multiple object into same width(I need width)?
              Stefan Rakete Level 2

              for the horizontal distribution:

               

              var curDoc = app.activeDocument;

              var itemsToDistribute = curDoc.pageItems;

              var gap = 5;

              curDoc.distribute(itemsToDistribute, DistributeOptions.HORIZONTAL_SPACE, undefined, true, gap);

              • 4. Re: Is there a script that can chang Multiple object into same width(I need width)?
                S Hopkins Adobe Community Professional

                It seems to me that your big problem is in resizing the items before distributing. The following script may be helpful. You may also want to check out my blog for today that discusses some of the problems you may encounter in working with align distribute (yourscriptdoctor.com/blogs)

                set gap to 10

                  try

                  set keyObject to missing value

                  tell application "Adobe InDesign CC 2015"

                tell script preferences to set measurement to millimeters

                set docRef to active document

                --set selList to my pageItemsSelected()

                tell docRef

                set selList to selection

                if length of selList > 2 then

                set testItem to selection key object

                if testItem is not nothing then

                set keyObject to testItem

                set origBounds to geometric bounds of keyObject

                end if

                distribute align distribute items selList distribute option horizontal space align distribute bounds item bounds absolute distribute measurement 5 with use distribute measurement

                end if

                end tell

                if keyObject is not missing value then

                --using original bounds of selection key object to move selected items

                set newBounds to geometric bounds of keyObject

                if (item 2 of newBounds > item 2 of origBounds) then

                set relMove to (item 2 of newBounds) - (item 2 of origBounds)

                else

                set relMove to (item 2 of origBounds) - (item 2 of newBounds)

                end if

                move selList by {relMove, 0}

                end if

                end tell

                  on error (errStr)

                activate

                display alert "Error: " & errStr

                  end try

                 

                  (*Returns reference to page items selected if more than 1; otherwise throws error*)

                  on pageItemsSelected()

                set errStr to "Requires a selection of 2 or more page items"

                tell application "Adobe InDesign CC 2015"

                set selList to selection

                if length of selList < 2 then

                error errStr

                end if

                set selItem to item 1 of selList

                if class of selItem is not in {text frame, rectangle, oval, polygon} then

                error errStr

                end if

                end tell

                return selList

                  end pageItemsSelected