9 Replies Latest reply on Feb 21, 2008 4:31 AM by (elic_elico)

    cant move paragraph from textFrame to another

      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>
        • 1. Re: cant move paragraph from textFrame to another
          Harbs. Level 6
          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
          • 2. Re: cant move paragraph from textFrame to another
            Level 1
            thanks harbs, but it is not working even after i wrote "after"!
            • 3. Re: cant move paragraph from textFrame to another
              Harbs. Level 6
              Like I said: You probably need to set you geometricBounds.

              Harbs
              • 4. Re: cant move paragraph from textFrame to another
                Martin Fischer Level 2
                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
                • 5. Re: cant move paragraph from textFrame to another
                  Level 1
                  I set set geometricBounds and yet there its not working.
                  • 6. Re: cant move paragraph from textFrame to another
                    Level 1
                    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>
                    • 7. Re: cant move paragraph from textFrame to another
                      Martin Fischer Level 2
                      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
                      • 8. Re: cant move paragraph from textFrame to another
                        Harbs. Level 6
                        You don't need to play around with labels. Use the frame id like this:

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


                        Harbs
                        • 9. Re: cant move paragraph from textFrame to another
                          Level 1
                          cleaning the label didnwt work. but using the id solved the problem. thanks alot i was desperate.