Skip to main content
Participating Frequently
February 20, 2008
Question

cant move paragraph from textFrame to another

  • February 20, 2008
  • 7 replies
  • 788 views
what is the problem with the move method???

<pre>var myDoc = app.activeDocument;
var myPStmuna = myDoc.paragraphStyles.item("תמונה");
var myPScomment = myDoc.paragraphStyles.item("הערה");
for(i=0;i<myDoc.pages.length;i++){
  myPage=myDoc.pages.item(i);
  tf=myPage.textFrames.item(0);
  for(g=0;g<tf.paragraphs.length;g++){
    if(tf.paragraphs.length>0){
      myPara=tf.paragraphs.item(g);
      if(myPara.appliedParagraphStyle == myPStmuna){
        newTF=myPage.textFrames.add();
        myPara.move(LocationOptions.affter,newTF.insertionPoints.item(0));
        newTF.fit(FitOptions.frameToContent);
      }
    }else{
      break;
    }
  }
}</pre>
This topic has been closed for replies.

7 replies

Participating Frequently
February 21, 2008
cleaning the label didnwt work. but using the id solved the problem. thanks alot i was desperate.
Inspiring
February 21, 2008
Hi elic,

Now I have tried to adress the text frame tf by it's label (call him by it's name but not by it's index) - and it seems to work.

<pre>
var myDoc = app.activeDocument;
var myPStmuna = myDoc.paragraphStyles.item("תמונה");
var myPScomment = myDoc.paragraphStyles.item("הערה");
for(i=0;i<myDoc.pages.length;i++){
myPage=myDoc.pages.item(i);
// set label-property
myPage.textFrames.item(0).label = 'myFrame';
tf=myPage.textFrames.item('myFrame');
for(g=tf.paragraphs.length-1;g>=0;g--){
if(tf.paragraphs.length>0){
myPara=tf.paragraphs.item(g);
if(myPara.appliedParagraphStyle == myPStmuna){
newTF=myPage.textFrames.add();
myBounds = myGetBounds(myDoc,myPage);
newTF.geometricBounds = myBounds;
newTF.contents="bla bla\r";
myPara.move(LocationOptions.atEnd,newTF);
}
}else{
break;
}
}
// reset label-property
tf.label = '';
}
</pre>

Don't forget to reset the label auf tf.
It could make the script get confused if you run the script twice and more in the same document because the length of tf with the same label within one page will grow every time the script runs.

Martin
Harbs.
Legend
February 21, 2008
You don't need to play around with labels. Use the frame id like this:

tf=myPage.textFrames.itemByID(myPage.textFrames[0].id);


Harbs
Participating Frequently
February 21, 2008
I tried newTF.contents="bla bla..." and it gets into the newTF.

this is my updated code:
<pre>var myDoc = app.activeDocument;
var myPStmuna = myDoc.paragraphStyles.item("תמונה");
var myPScomment = myDoc.paragraphStyles.item("הערה");
for(i=0;i<myDoc.pages.length;i++){
  myPage=myDoc.pages.item(i);
  tf=myPage.textFrames.item(0);
  for(g=tf.paragraphs.length-1;g>=0;g--){
    if(tf.paragraphs.length>0){
      myPara=tf.paragraphs.item(g);
      if(myPara.appliedParagraphStyle == myPStmuna){
        newTF=myPage.textFrames.add();
        myBounds = myGetBounds(myDoc,myPage);
        newTF.geometricBounds = myBounds;
        newTF.contents="bla bla\r";        
        myPara.move(LocationOptions.atEnd,newTF);
        
      }
    }else{
      break;
    }
  }
}

function myGetBounds(myDocument, myPage){
var myWidth = myDocument.documentPreferences.pageWidth;
var myHeight = myDocument.documentPreferences.pageHeight;
var myX1 = myPage.marginPreferences.left;
var myY1 = myPage.marginPreferences.top;
var myX2 = myWidth - myPage.marginPreferences.right;
var myY2 = myHeight - myPage.marginPreferences.bottom;
return [myY1, myX1, myY2, myX2];
}</pre>
Participating Frequently
February 21, 2008
I set set geometricBounds and yet there its not working.
Inspiring
February 21, 2008
Maybe after the new textframe has been added the index of the old textframe has changed and myPara will no longer adress the paragraph in a textframe which index has changed.

Check the contents of tf and newTF after adding newTF.

Martin
Participating Frequently
February 21, 2008
thanks harbs, but it is not working even after i wrote "after"!
Harbs.
Legend
February 21, 2008
Like I said: You probably need to set you geometricBounds.

Harbs
Harbs.
Legend
February 21, 2008
This line for one.
myPara.move(LocationOptions.affter,newTF.insertionPoints.item(0));
"after" is with one "f"

myPara.move(LocationOptions.after,newTF.insertionPoints.item(0));

You probably also want to set geometricBounds for your newTF.

Harbs