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

ID cs6:How to Fit Frame to Version heart(or Page) with script?

Advocate ,
Feb 22, 2014 Feb 22, 2014

Copy link to clipboard

Copied

More times, I need my Frame fit to my Version,or fit to my page,fit to version hear.jpg

I looking for the scrip in the Internet, only see "frames  to content"

Who would like to help me?

Thank you very much~

TOPICS
Scripting

Views

2.0K

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
Community Expert ,
Feb 22, 2014 Feb 22, 2014

Copy link to clipboard

Copied

I've moved your question to the scripting forum. I think you'll get more help here.

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 ,
Feb 22, 2014 Feb 22, 2014

Copy link to clipboard

Copied

Hi,

you can try the following lines:

var curDoc = app.activeDocument;

if ( app.selection.length != 1 ) {

    ( alert ( "Something wrong with your selection!" ) );

    exit();

    }

var curSel = app.selection[0];

var curPage = curSel.parentPage;

var rO = curDoc.viewPreferences.rulerOrigin;

if (rO != 1380143215) {

    curDoc.viewPreferences.rulerOrigin = RulerOrigin.pageOrigin;

}

var pW = curDoc.documentPreferences.pageWidth;

var y1, x1, y2, x2;

if ( curPage.side == PageSideOptions.leftHand ){

    x2 = curPage.marginPreferences.left;

    x1 = curPage.marginPreferences.right;

}

else {

    x1 = curPage.marginPreferences.left;

    x2 = curPage.marginPreferences.right;

}

x2 = pW - x2;

var gB = curSel.geometricBounds;

// fit to margins

gB[1] = x1;

gB[3] = x2;

curSel.geometricBounds = gB;

// fit to page

/* gB[1] = 0;

gB[3] = pW;

curSel.geometricBounds = gB; */

curSel.fit ( FitOptions.FRAME_TO_CONTENT );

resetAsBefore();

function resetAsBefore() {

    if ( rO != 1380143215 ) {

            curDoc.viewPreferences.rulerOrigin = rO;

    }

}

Everything in /* */ will not executed. So at the moment your selection will fit to the page margins. If you put the lines under // fit to margins in /* */ and delete those under // fit to page, your textframe will fit to the page.

best

Kai

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 ,
Feb 23, 2014 Feb 23, 2014

Copy link to clipboard

Copied

Hi  Kai Rübsamen

Thank  you very much.

Some times I must press Ctrl+Z, It will  be ok?


and ,I want to select more than one text frame.


and, the script is wrong in some document ,Tested, I find  should be make the Coordinate origin to the The upper left corner

Could you like to add this Function into the scrip.

thanks

duble-click.jpg


fit to margins

-------------------------------------------------------------------------------------------------------------------------------------------------------------

var curDoc = app.activeDocument;

if ( app.selection.length != 1 ) {

    ( alert ( "Something wrong with your selection!" ) );

    exit();

    }

var curSel = app.selection[0];

var curPage = curSel.parentPage;

var rO = curDoc.viewPreferences.rulerOrigin;

if (rO != 1380143215) {

    curDoc.viewPreferences.rulerOrigin = RulerOrigin.pageOrigin;

}

var pW = curDoc.documentPreferences.pageWidth;

var y1, x1, y2, x2;

if ( curPage.side == PageSideOptions.leftHand ){

    x2 = curPage.marginPreferences.left;

    x1 = curPage.marginPreferences.right;

}

else {

    x1 = curPage.marginPreferences.left;

    x2 = curPage.marginPreferences.right;

}

x2 = pW - x2;

var gB = curSel.geometricBounds;

// fit to margins

gB[1] = x1;

gB[3] = x2;

curSel.geometricBounds = gB;

curSel.fit ( FitOptions.FRAME_TO_CONTENT );

resetAsBefore();

function resetAsBefore() {

    if ( rO != 1380143215 ) {

            curDoc.viewPreferences.rulerOrigin = rO;

    }

}

-------------------------------------------------------------------------------------------------------------------------------------------------------------

fit to page

-------------------------------------------------------------------------------------------------------------------------------------------------------------

var curDoc = app.activeDocument;

if ( app.selection.length != 1 ) {

    ( alert ( "Something wrong with your selection!" ) );

    exit();

    }

var curSel = app.selection[0];

var curPage = curSel.parentPage;

var rO = curDoc.viewPreferences.rulerOrigin;

if (rO != 1380143215) {

    curDoc.viewPreferences.rulerOrigin = RulerOrigin.pageOrigin;

}

var pW = curDoc.documentPreferences.pageWidth;

var y1, x1, y2, x2;

if ( curPage.side == PageSideOptions.leftHand ){

    x2 = curPage.marginPreferences.left;

    x1 = curPage.marginPreferences.right;

}

else {

    x1 = curPage.marginPreferences.left;

    x2 = curPage.marginPreferences.right;

}

x2 = pW - x2;

var gB = curSel.geometricBounds;

// fit to page

gB[1] = 0;

gB[3] = pW;

curSel.geometricBounds = gB;

curSel.fit ( FitOptions.FRAME_TO_CONTENT );

resetAsBefore();

function resetAsBefore() {

    if ( rO != 1380143215 ) {

            curDoc.viewPreferences.rulerOrigin = rO;

    }

}

-------------------------------------------------------------------------------------------------------------------------------------------------------------

best wishes

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 ,
Feb 23, 2014 Feb 23, 2014

Copy link to clipboard

Copied

Hi,

the script is not wrong. You get, what you showed in your screen: One frame that fits either to the type area or to the bounds of the page.

If you want to select more than one frame or want to change all frames in a story, this is probably also possible, but: If you draw your frames correct from the beginning, in most cases there is no need for aligning them afterwards.

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 ,
Feb 23, 2014 Feb 23, 2014

Copy link to clipboard

Copied

HI

Kai Rübsamen

I know how to ues it,

but I find something,I have update my Relay of the up (3 floor)

Some times I must press Ctrl+Z, It will  be ok?


and ,I want to select more than one text frame.


and, the script is wrong in some document ,Tested, I find  should be make the Coordinate origin to the The upper left corner

Could you like to add this Function into the scrip.


and it is now fit horizontal, Could you add fit to Vertical

thanks


http://forums.adobe.com/servlet/JiveServlet/showImage/2-6148509-554890/duble-click.jpg

thanks

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 ,
Feb 23, 2014 Feb 23, 2014

Copy link to clipboard

Copied

The next version should solve the problem with your zeroPoint. It is now also possible to have a textframe with a short single line.

var curDoc = app.activeDocument;

if ( app.selection.length != 1 || app.selection[0].constructor.name != "TextFrame" ) {

    ( alert ( "Something wrong with your selection!" ) );

    exit();

    }

var curSel = app.selection[0];

var curPage = curSel.parentPage;

// set the zeroPoint to 0

var zP = curDoc.zeroPoint;

if (zP != [0,0]) {

    curDoc.zeroPoint = [0,0];

}

var rO = curDoc.viewPreferences.rulerOrigin;

if (rO != 1380143215) {

    curDoc.viewPreferences.rulerOrigin = RulerOrigin.pageOrigin;

}

var pW = curDoc.documentPreferences.pageWidth;

var y1, x1, y2, x2;

if ( curPage.side == PageSideOptions.leftHand ){

    x2 = curPage.marginPreferences.left;

    x1 = curPage.marginPreferences.right;

}

else {

    x1 = curPage.marginPreferences.left;

    x2 = curPage.marginPreferences.right;

}

x2 = pW - x2;

var gB = curSel.geometricBounds;

// fit to margins

gB[1] = x1;

gB[3] = x2;

curSel.geometricBounds = gB;

// fit to page

/* gB[1] = 0;

gB[3] = pW;

curSel.geometricBounds = gB; */

fitFrame(curSel);

resetAsBefore();

function fitFrame(aFrame) {

    var gB = aFrame.geometricBounds;

    gB[2] = gB[2]+ 50;

    aFrame.geometricBounds =  gB;

    var lastBaseLine = aFrame.lines.lastItem().baseline;

    aFrame.geometricBounds =  [ gB[0], gB[1], lastBaseLine, gB[3] ];

}

function resetAsBefore() {

    if ( rO != 1380143215 ) {

            curDoc.viewPreferences.rulerOrigin = rO;

    }

    // set the zeroPoint back to the origin state

    if (zP != [0,0]) {

        curDoc.zeroPoint = zP;

    }

}

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 ,
Feb 23, 2014 Feb 23, 2014

Copy link to clipboard

Copied

If you want to align your frame horizontally and vertically you can change the corresponding parts to something like:


var doc = app.activeDocument;

var curSel = app.selection[0];

var curPage = curSel.parentPage;

//Get page width and page height using the function "getBounds"

var gB = getBounds( doc, curPage);

//Resize the text frame to match the publication margins

curSel.geometricBounds = gB;

function getBounds( doc, curPage){

    var pW = doc.documentPreferences.pageWidth;

    var pH = doc.documentPreferences.pageHeight;

   

    var y1, x1, y2, x2;

    x1 = curPage.marginPreferences.left;

    x2 = curPage.marginPreferences.right;

   

    y1 = curPage.marginPreferences.top;

    x2 = pW - x2;

    y2 = pH - curPage.marginPreferences.bottom

    return [y1, x1, y2, x2];

}

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 ,
Feb 23, 2014 Feb 23, 2014

Copy link to clipboard

Copied

thank you thank you

You are too enthusiastic.~!

It is very good, only, I can not understant, have a "+", the height not Enough?

verygood.jpg

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 ,
Feb 24, 2014 Feb 24, 2014

Copy link to clipboard

Copied

If you select the frame above, your second example (the frame at the bottom) can never be a result of my script (hopefully ;-)). So I did not understand, what cause the overflow in your case.

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 ,
Feb 24, 2014 Feb 24, 2014

Copy link to clipboard

Copied

I find it, for it is missing this ...

" curSel.fit ( FitOptions.FRAME_TO_CONTENT );

resetAsBefore();

"

I Still can not add the  vertical in the below script, Always Cause Coordinate origin to be Fail

-single-handed,It is right.

--------------------------------------------------------------------------------------------------------------------------

var curDoc = app.activeDocument;

if ( app.selection.length != 1 ) {

    ( alert ( "Something wrong with your selection!" ) );

    exit();

    }

var curSel = app.selection[0];

var curPage = curSel.parentPage;

// set the zeroPoint to 0

var zP = curDoc.zeroPoint;

if (zP != [0,0]) {

    curDoc.zeroPoint = [0,0];

var rO = curDoc.viewPreferences.rulerOrigin;

if (rO != 1380143215) {

    curDoc.viewPreferences.rulerOrigin = RulerOrigin.pageOrigin;

}

var pW = curDoc.documentPreferences.pageWidth;

var y1, x1, y2, x2;

if ( curPage.side == PageSideOptions.leftHand ){

    x2 = curPage.marginPreferences.left;

    x1 = curPage.marginPreferences.right;

}

else {

    x1 = curPage.marginPreferences.left;

    x2 = curPage.marginPreferences.right;

}

x2 = pW - x2;

var gB = curSel.geometricBounds;

// fit to margins

gB[1] = x1;

gB[3] = x2;

curSel.geometricBounds = gB;

// fit to page

/*gB[1] = 0;

gB[3] = pW;

curSel.geometricBounds = gB;*/

curSel.fit ( FitOptions.FRAME_TO_CONTENT );

resetAsBefore();

function resetAsBefore() {

    if ( rO != 1380143215 ) {

            curDoc.viewPreferences.rulerOrigin = rO;

    }

    // set the zeroPoint back to the origin state

    if (zP != [0,0]) {

        curDoc.zeroPoint = zP;

    }

}


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 ,
Feb 24, 2014 Feb 24, 2014

Copy link to clipboard

Copied

Hopefully you understand, that you have here different needs and the various script-elements does different things here 😉

If you want to align your textframe to all four sides of the type-are, you can try this one. Try also to delete the // at the line with "fitFrame". I spent also some comments for a better understanding.

// the current document

var curDoc = app.activeDocument;

// there must be one selection with the selection-tool and the selection must be a textframe

if ( app.selection.length != 1 || app.selection[0].constructor.name != "TextFrame" ) {

    ( alert ( "Something wrong with your selection!" ) );

    exit();

    }

// the current selection

var curSel = app.selection[0];

// the page of the current selection

var curPage = curSel.parentPage;

// set the zeroPoint to 0

var zP = curDoc.zeroPoint;

if (zP != [0,0]) {

    curDoc.zeroPoint = [0,0];

}

// set the ruler to page origin and store the user-pref

var rO = curDoc.viewPreferences.rulerOrigin;

if (rO != 1380143215) {

    curDoc.viewPreferences.rulerOrigin = RulerOrigin.pageOrigin;

}

// page width and height

var pW = curDoc.documentPreferences.pageWidth;

var pH = curDoc.documentPreferences.pageHeight;

var y1, x1, y2, x2;

// check if the page is a single, left or right page and store the margins

if ( curPage.side == PageSideOptions.leftHand ){

    x2 = curPage.marginPreferences.left;

    x1 = curPage.marginPreferences.right;

}

else {

    x1 = curPage.marginPreferences.left;

    x2 = curPage.marginPreferences.right;

}

y1 = curPage.marginPreferences.top;

x2 = pW - x2;

y2 = pH - curPage.marginPreferences.bottom;

var gB = curSel.geometricBounds;

// fit to margins

gB[0] = y1;

gB[1] = x1;

gB[2] = y2;

gB[3] = x2;

curSel.geometricBounds = gB;

// fitFrame(curSel);

// set the zeroPoint and ruler to the original state

resetAsBefore();

function fitFrame(aFrame) {

    var gB = aFrame.geometricBounds;

    gB[2] = gB[2]+ 50;

    aFrame.geometricBounds =  gB;

    var lastBaseLine = aFrame.lines.lastItem().baseline;

    aFrame.geometricBounds =  [ gB[0], gB[1], lastBaseLine, gB[3] ];

}

function resetAsBefore() {

    if ( rO != 1380143215 ) {

            curDoc.viewPreferences.rulerOrigin = rO;

    }

    // set the zeroPoint back to the origin state

    if (zP != [0,0]) {

        curDoc.zeroPoint = zP;

    }

}

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 ,
Feb 24, 2014 Feb 24, 2014

Copy link to clipboard

Copied

Hi

Kai Rübsamen

It is just I want,It is very good!

You are so Calendar harm, Very, very,very Invincible

The best wishes  for you

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 ,
Feb 25, 2014 Feb 25, 2014

Copy link to clipboard

Copied

Hi

Kai Rübsamen

The script of "fit to 4 size page"  is very Perfect

I am so sorry,for I comebake to Pester you,I must admit, I am so greedy

① I find the"fit to margins " and "fit to page" is not rigth,when my text only 1 row~

② and I want to know,How to fit to Column......

Thank you very much~

one row.jpg

Fit to ColuColumn.jpg

It is the script

------------------------------------------------------------------------------------------------------------------------------------------

var curDoc = app.activeDocument;

if ( app.selection.length != 1 ) {

    ( alert ( "Something wrong with your selection!" ) );

    exit();

    }

var curSel = app.selection[0];

var curPage = curSel.parentPage;

// set the zeroPoint to 0

var zP = curDoc.zeroPoint;

if (zP != [0,0]) {

    curDoc.zeroPoint = [0,0];

var rO = curDoc.viewPreferences.rulerOrigin;

if (rO != 1380143215) {

    curDoc.viewPreferences.rulerOrigin = RulerOrigin.pageOrigin;

}

var pW = curDoc.documentPreferences.pageWidth;

var y1, x1, y2, x2;

if ( curPage.side == PageSideOptions.leftHand ){

    x2 = curPage.marginPreferences.left;

    x1 = curPage.marginPreferences.right;

}

else {

    x1 = curPage.marginPreferences.left;

    x2 = curPage.marginPreferences.right;

}

x2 = pW - x2;

var gB = curSel.geometricBounds;

// fit to margins

gB[1] = x1;

gB[3] = x2;

curSel.geometricBounds = gB;

// fit to page

/*gB[1] = 0;

gB[3] = pW;

curSel.geometricBounds = gB;*/

curSel.fit ( FitOptions.FRAME_TO_CONTENT );

resetAsBefore();

function resetAsBefore() {

    if ( rO != 1380143215 ) {

            curDoc.viewPreferences.rulerOrigin = rO;

    }

    // set the zeroPoint back to the origin state

    if (zP != [0,0]) {

        curDoc.zeroPoint = zP;

    }

}

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 ,
Feb 25, 2014 Feb 25, 2014

Copy link to clipboard

Copied

As I said before: You got different things for different needs here!

fitFrame(curSel) and curSel.fit() are not the same things! The first one should solve your problem.

To your columns question: I never scripted this before and have sadly at the moment no time to dive in this, sorry.

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 ,
Mar 18, 2014 Mar 18, 2014

Copy link to clipboard

Copied

Hi Kai Rübsamen~

I miss you very much!

Text suitable column is very very useful for me, example  in Magazine publishing,there are Many text boxes, it can beQuickly align column edge。

Hope you can help me achieve~

Best wishes for you~

http://forums.adobe.com/servlet/JiveServlet/showImage/2-6154317-555469/Fit+to+ColuColumn.jpg

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 ,
Mar 18, 2014 Mar 18, 2014

Copy link to clipboard

Copied

Hi,

you have luck, I find the question interesting but I’m not sure, if I do this in the right way. I’m a graphic designer and not really a scripter 😉

Find here a first version. This version is not really flexible. The script assumes, that you select a textframe or a rectangle.

I would think, that the second version should compare the distance between the left edge and the nearest column. I’m busy at the moment. Maybe I have the next days a bit time to dive in for this second version.

Any feedback in the meantime appreciated.


var curDoc = app.activeDocument;

var curSel = app.selection[0];

var gB = curSel.geometricBounds;

// Masseinheiten, Ursprung und Nullpunkt speichern und bei Bedarf verändern

hM = curDoc.viewPreferences.horizontalMeasurementUnits;

vM = curDoc.viewPreferences.verticalMeasurementUnits;

rO = curDoc.viewPreferences.rulerOrigin;

zP = curDoc.zeroPoint;

_setPref();

// Variablen initialisieren

var pWidth = curDoc.documentPreferences.pageWidth;

pWidth = Math.floor((pWidth * 1000) + 0.5) / 1000;

var pHeight = curDoc.documentPreferences.pageHeight;

pHeight = Math.floor((pHeight * 1000) + 0.5) / 1000;

var curPage = app.activeWindow.activePage;

// weitere Variablen deklarieren

var curPage;

var pM;

var curPos;

var allPos = new Array;

if(curPage.side == PageSideOptions.leftHand) {

    // bei Doppelseiten bedeutet left > innen; right > außen

    pM = curPage.marginPreferences.right;

}

else{

    // entweder Einzelseite oder rechte Seite

    pM = curPage.marginPreferences.left;

}

// die Anzahl der Spalten auf der Seite

var nC = curPage.marginPreferences.columnCount;

// die Positionen der Spaltenlinien

var colPos = curPage.marginPreferences.columnsPositions;

// Schleife durch alle Positionen, der Spaltenlinien, Werte runden

for (var k=0; k<colPos.length; k++) {

    curPos = (Math.floor((colPos * 1000) + 0.5) / 1000) + pM;

    allPos.push(curPos);

}

gB[1] = allPos[0];

gB[3] = allPos[1];

curSel.geometricBounds = gB;

if (curSel.constructor.name == "TextFrame") fitFrame(curSel);

_reStorePref();

// --------------------- Funktionen -------------------------

function fitFrame(aFrame) {

    var gB = aFrame.geometricBounds;

    gB[2] = gB[2]+ 50;

    aFrame.geometricBounds =  gB;

    var lastBaseLine = aFrame.lines.lastItem().baseline;

    aFrame.geometricBounds =  [ gB[0], gB[1], lastBaseLine, gB[3] ];

}

// Voreinstellungen verändern und zurücksetzen

function _setPref() {

    curDoc.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.millimeters;

    curDoc.viewPreferences.verticalMeasurementUnits = MeasurementUnits.millimeters;

    curDoc.viewPreferences.rulerOrigin = RulerOrigin.PAGE_ORIGIN;

    curDoc.zeroPoint = [0,0];

}

function _reStorePref() {

    curDoc.viewPreferences.horizontalMeasurementUnits = hM;

    curDoc.viewPreferences.verticalMeasurementUnits = vM;

    curDoc.viewPreferences.rulerOrigin = rO;

    curDoc.zeroPoint = zP;

}

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 ,
Mar 19, 2014 Mar 19, 2014

Copy link to clipboard

Copied

LATEST

HI~Kai Rübsamen~

I have see you~you so great,I only can say:I love you ~ best wishes for you!

I test it It is very good~,have some  advice:When this point at Which column, it should fit to Which column, But not always fit to the first column.

Thank you very much~

.column-01.jpg

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