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

cant move paragraph from textFrame to another

New Here ,
Feb 20, 2008 Feb 20, 2008
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>
TOPICS
Scripting
755
Translate
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
LEGEND ,
Feb 20, 2008 Feb 20, 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
Translate
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
New Here ,
Feb 20, 2008 Feb 20, 2008
thanks harbs, but it is not working even after i wrote "after"!
Translate
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
LEGEND ,
Feb 20, 2008 Feb 20, 2008
Like I said: You probably need to set you geometricBounds.

Harbs
Translate
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
Contributor ,
Feb 20, 2008 Feb 20, 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
Translate
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
New Here ,
Feb 20, 2008 Feb 20, 2008
I set set geometricBounds and yet there its not working.
Translate
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
New Here ,
Feb 20, 2008 Feb 20, 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>
Translate
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
Contributor ,
Feb 20, 2008 Feb 20, 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
Translate
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
LEGEND ,
Feb 20, 2008 Feb 20, 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
Translate
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
New Here ,
Feb 21, 2008 Feb 21, 2008
LATEST
cleaning the label didnwt work. but using the id solved the problem. thanks alot i was desperate.
Translate
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