Skip to main content
March 23, 2014
Answered

Move textFrame to previous position

  • March 23, 2014
  • 2 replies
  • 1327 views

Hi Forum,

Need indeed help from you.

After grouping all the pageItems and resizing (scaling) to new page Height, I want to move the text Frames.geometricBounds[1] to the previous position before scaling was done.

for example before scaling: textFrames.geometricBounds[1] is 12mm, 16.5mm respectively.

after grouping and scaling the group to new page height, i want to move back the textFrames.geometricBounds[1] to same 12mm, 16.5 position.

I tried to memorise the geometricBounds[1] of textframes into array and after scaling was done, ungrouped and tried to move all the textframes to the previous position.

var tf = app.activeDocument.textFrames.everyItem().getElements();

for(i=0; i<tf.length; i++) {
var vat= [];
vat.push(tf.geometricBounds[1].join('\r'));

// here scaling the group is done to new page size...

if (tf].geometricBounds[1]<app.activeDocument.pages.item(0).marginPreferences.left;)

{ tf.move([tf.parentPage, tf.geometricBounds[0]]).

//trying to move all the textframe to the previous position, when the textframe.geometricBounds[1] are outside the left margin.

}}

// trying to move all the textframes which are outside the page.bounds[1] marginPreferences.left,  after resizing the document.

Thanks for helping on this.

This topic has been closed for replies.
Correct answer Jump_Over

Hello Jarek & pixel.

Please see the snapshot attached.

My intention is to move the textframes which are outside the page bounds[0], back to the page.

when i group the pageitems and scale the text frames goes out the margins. and when running pixxel idea. the text frames goes upside and downside differently.

screen shot 1 before page resizing and scaling.

after page resizing and scaling.done.

the magenta textframe goes above and cyan text frame comes below. and cyan text frame is not toucing the margin as shown in screen shot 1.

I want to visual the same thing after resizing and scaling. just to move the textfrae again to the page.

my scribble ugly  works is ;

var tf = app.activeDocument.textFrames.everyItem().getElements();
for(k=0; k<tf.length;k++) {
var oldPosition = [tf.geometricBounds[1].toFixed(3), tf.geometricBounds[0].toFixed(3)];
tf.label =
     tf.geometricBounds[1].toFixed(3) +     "|" +     tf.geometricBounds[0].toFixed(3);

var g = app.activeDocument.pageItems.everyItem();
try {
var gr = app.activeDocument.groups.add(g);
} catch (e) {}
var bgr = gr.geometricBounds;
var hgr = bgr[2]-bgr[0];

// resize document
app.activeDocument.documentPreferences.pageWidth = 600;
app.activeDocument.documentPreferences.pageHeight = 1200;

var pm= gr.parent.marginPreferences;
with(pm)
{
var t = top;
var b = bottom;
    }

app.activeDocument.pages.item(0).marginPreferences.top = 15;

 

// scale group to page height
var hn = app.activeDocument.pages.item(0).bounds[2] - app.activeDocument.pages.item(0).bounds[0];
var s = hn / hgr ;
tM = app.transformationMatrices.add({horizontalScaleFactor:s,   verticalScaleFactor:s}); 

gr .transform(CoordinateSpaces.INNER_COORDINATES, AnchorPoint.TOP_CENTER_ANCHOR, tM );
app.select(gr);

//move the scaled item centrally:

htt =app.selection[0].geometricBounds[3]-app.selection[0].geometricBounds[1];

center = (app.activeDocument.pages.item(0).bounds[3]-htt)/2;

gr.move([center, app.activeDocument.pages.item(0).bounds[0]]);

app.activeDocument.pages.item(0).groups.everyItem().ungroup();

//send back the text frame to previous position, if they are outside the page left margin.

tf.move([tf.label.split("|")[0], tf.label.split("|")[1]]);
alert ("moved to old position");
}

Jarek please dont scold me for this ugly work... Im just a beginner...


Hi,

Try this for resizing last page of doc. Do it with other pages if needed.

var

     targetPage = app.activeDocument.pages[-1];

     changedPageSize = [210,180];     // width, height

     currentPageSize = [

          targetPage.bounds[3] - targetPage.bounds[1],

          targetPage.bounds[2] - targetPage.bounds[0]

          ];

     wFactor = changedPageSize[0]/currentPageSize[0];

     hFactor = changedPageSize[1]/currentPageSize[1];

     mGroup = targetPage.groups.add( targetPage.allPageItems );

                   

     targetPage.resize(

          CoordinateSpaces.INNER_COORDINATES,

          AnchorPoint.TOP_LEFT_ANCHOR,

          ResizeMethods.MULTIPLYING_CURRENT_DIMENSIONS_BY,

          [wFactor, hFactor]);

     mGroup.resize(

          CoordinateSpaces.INNER_COORDINATES,

          AnchorPoint.TOP_LEFT_ANCHOR,

          ResizeMethods.MULTIPLYING_CURRENT_DIMENSIONS_BY,

          [wFactor, hFactor]);

Jarek

2 replies

pixxxelschubser
Community Expert
Community Expert
March 23, 2014

Hi Unique,

at first you should round your text frame position values. Otherwise, it's pretty hard to compare the values​​.

For moving you can try something like this (e.g. for the first text frame):

// http://forums.adobe.com/thread/1434223?tstart=0

// regards pixxxelschubser

var tf = app.activeDocument.textFrames.everyItem().getElements();

var oldPosition = [tf[0].geometricBounds[1].toFixed(3),tf[0].geometricBounds[0].toFixed(3)];

var newPosition = [100,100];

// moving or scaling gives a new position

tf[0].move(newPosition);

alert ("move 1");

// back to old position

tf[0].move(oldPosition);

alert ("moved to old position");

Have fun

March 23, 2014

Hello Jarek and pixxxel,

thanks a lot of helping me out.

Let me ask a few questions, if you dont mind.

pixxxel you have assigned tf[0].. is that mean for single text frame...

so can i use your suggestion in for loop to move tf and will that works after the below steps.

1. storing all the textframes geometric bounds in memory.

2. resizing the document by grouping all the textframes.

3. then again moving back the textframes to previous position.

Dear jarek.

1. would be much thanks to you, to have idea to, store each textframes with different lable names.

2. how could i get gb[0] and gb[1] of textframe without pushing the numbers to array and get them.

3. sorry for my silly questions.......

many thanks to you2...

Jump_Over
Legend
March 23, 2014

Hi,

For each pageItem you can do this (including pixxxell suggestion):

pageItem.label =

     pageItem.geometricBounds[1].toFixed(3) +

     "|" +

     pageItem.geometricBounds[0].toFixed(3);

Later on (assuming each pageItem has its label filled like above) you can move their left-up corner to previous position like this:

pageItem.move( pageItem.label.split("|")[0], pageItem.label.split("|")[1] );

Jarek

Jump_Over
Legend
March 23, 2014

Hi,

1. You have to read 2 textFrame.geometricBounds to get its position, i.e.:

     leftup corner = gb[1] and gb[0] ==> as x nad y

     rightbottom corner = gb[3] and gb[2] ==> as x and y

2. gb[1].join() is trying to execute array's method with a number (error)

3. did you consider to store textFrame.geometricBounds as its label, so you can get it back anytime you need?

4. Exam your group.resize method since getting pageItem outside (smaller) page is something weird

Jarek