Skip to main content
Sketch_Ak
Inspiring
June 12, 2015
Answered

Is there a javascript to resize a frame to Page, Margin, Bleed or Slug?

  • June 12, 2015
  • 3 replies
  • 3773 views

There are a lot of fit frame to content but I often resize frames to fit a page or bleed or slug. Does anyone know if this could be done?

Thanks

This topic has been closed for replies.
Correct answer Marc Autret

Hi Sketch_Ak,

The basic brick is:

myFrame.geometricBounds = myPage.bounds;

Now you'll find for sure many variants and adjusted snippets in browsing this forum.

@+

Marc

3 replies

Sketch_Ak
Sketch_AkAuthor
Inspiring
July 24, 2017

For those that need these scripts now and don't have the time to learn how to write them this link will help greatly:

https://sellfy.com/p/JMJu/

Sergey_Anosov
Participating Frequently
June 13, 2015

Hello!

There is a script almost conforming your requirements, but it creates a new rectangle, does not transform an existing one:

https://sites.google.com/site/dtpscripting/indesign-scripts/makerectangle-jsx

Inspiring
June 12, 2015

Please try this

var selFolder=Folder.selectDialog("Choose folder for Application File");

app.scriptPreferences.userInteractionLevel = UserInteractionLevels.NEVER_INTERACT;

if (selFolder!=null)

{

    var all_file=selFolder.getFiles("*.indd");

    for (var no_file=0; no_file<all_file.length;no_file++)

    {

        var cur_doc=app.open(File(all_file[no_file],false));

        cur_doc.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.centimeters;

        cur_doc.viewPreferences.verticalMeasurementUnits = MeasurementUnits.centimeters;

        cur_doc.viewPreferences.rulerOrigin = RulerOrigin.pageOrigin;

        cur_doc.zeroPoint =[0, 0];

        cur_doc.documentPreferences.pageWidth =17;

        cur_doc.documentPreferences.pageHeight =24;

        cur_doc.masterSpreads.item(0).pages.item(0).marginPreferences.right = 2.8;

        cur_doc.masterSpreads.item(0).pages.item(1).marginPreferences.right = 2.8;

        for (no_pg=0;no_pg<cur_doc.masterSpreads.item(0).pages.length;no_pg++)

        {

            var mypage=cur_doc.masterSpreads.item(0).pages[no_pg];

            for (no_tx=0;no_tx<mypage.textFrames.length;no_tx++)

            {

                if (mypage.textFrames[no_tx].geometricBounds[0]<mypage.marginPreferences.top-0.5)

                {

                    txBound=mypage.textFrames[no_tx].geometricBounds;

                    mypage.textFrames[no_tx].move([txBound[1],1.4575]);

                }

            }

        }

        cur_doc.close(SaveOptions.YES);

    }

}

alert("Process Completed");

Sketch_Ak
Sketch_AkAuthor
Inspiring
June 12, 2015

Thank you for replying sreekarthik.k,

Sorry I should have given more details.

1. I'd use this script with a document already open.

2. The page size can be any size depending on the job.

3. I draw a frame, and I want to automatically fit this frame to the page edge width and height (which is a variable size).

I hope that makes sense?

sidneydavenport
Inspiring
July 27, 2015

Hi Marc Autret,

Here is the script I've ended up with to fit a frame to a document page size:

var doc = app.activeDocument; 

var myPage = doc.pages[0];

var fit = myPage.bounds;  

var myFrame = app.selection[0]; 

myFrame.geometricBounds = fit;

I was also able to find other scripts for bleed and slug thanks to your feedback.

Cheers

Os


Thanks so much -- this little script is saving me.

FYI: If doc has spreads rather than individual pages, ruler needs to be set to "ruler per page" to set the right-hand page coordinates correctly.