• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

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

Advocate ,
Apr 13, 2016 Apr 13, 2016

Copy link to clipboard

Copied

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

TOPICS
Scripting

Views

480

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Apr 13, 2016 Apr 13, 2016

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Apr 15, 2016 Apr 15, 2016

Copy link to clipboard

Copied

Thankyou very much,dnyaneshlb

but it dosn't work~~

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Apr 19, 2016 Apr 19, 2016

Copy link to clipboard

Copied

for the horizontal distribution:

var curDoc = app.activeDocument;

var itemsToDistribute = curDoc.pageItems;

var gap = 5;

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Apr 20, 2016 Apr 20, 2016

Copy link to clipboard

Copied

LATEST

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines