5 Replies Latest reply on Feb 5, 2016 1:37 AM by Liphou

    [JS] Copy or move paragraph style and character style

    Liphou Level 1

      Hello,
      I try to transfer paragraphs of a document to a block of a second document but I lose all the paragraph style and character style applied.
      I use this command line:


      o.leBlocLegendes.contents = o.leBlocLegendes.contents + leDocument.stories.firstItem().paragraphs[leConteurPara].contents;
      
      


      How to lose nothing?

      Thank you


      Message d'origine

      Bonjour,

      je tente de transfert des paragraphes d'un document à un bloc d'un deuxième document mais je pérd tous le style de paragraphe et les style de caractère appliqué.

      j'utilise cette ligne de commande :

       

      o.leBlocLegendes.contents = o.leBlocLegendes.contents + leDocument.stories.firstItem().paragraphs[leConteurPara].contents;
      

       

      Comment faire pour ne rien perdre ?

       

      Merci

        • 1. Re: [JS] Copy or move paragraph style and character style
          Loic.Aigon Adobe Community Professional

          Hi Liphou,

           

          .contents indeed is a string only property disregardingly of styles, anchor frames and other stuffs.

          You would prefer use stories object and duplicate methods. However styles may be overidden by the target document. So you may want to load styles prior to text duplication.

           

          var main = function() {
              var doc, st, tempDoc, f, tf; 
              if (!app.documents.length 
                  || app.selection.length!=1
                  || !app.selection[0].properties.parentStory) {
                  alert("You need to select text or text frame");
                  return;
              }
          
              doc = app.activeDocument;
              
              if ( !doc.properties.fullName ) {
                  alert("Please save file first !");
                  return;
              }
          
              st = app.selection[0].parentStory;
              f = File ( doc.fullName );
              tempDoc = app.documents.add(); 
              tempDoc. importStyles ( ImportFormat.TEXT_STYLES_FORMAT, f, GlobalClashResolutionStrategy.LOAD_ALL_WITH_OVERWRITE );
              
              tf = tempDoc.textFrames.add();
              st.duplicate(LocationOptions.AT_BEGINNING, tf.insertionPoints[0]);
              tf.fit(FitOptions.FRAME_TO_CONTENT);
              
          }
          
          main();
          

           

          HTH,

           

          Loic

          www.ozalto.com

          • 2. Re: [JS] Copy or move paragraph style and character style
            Liphou Level 1

            Hello Loic.
            Indeed, I came to that conclusion, it copies only the raw text.
            The documents were the same styles.
            I just used the commende move () function it well:




            !leDocument.stories.firstItem().paragraphs[leConteurPara].move(LocationOptions.after, o.leBlocLegendes); !
            


            Thank you

             

            Bonjour Loic.

             

            Effectivement, je suis arrivé à cette conclution, il ne copie que le texte brute.

             

            Les documents on les mêmes Styles.

             

            je viens d'utilisé la commende move() elle function bien :

             

            leDocument.stories.firstItem().paragraphs[leConteurPara].move(LocationOptions.after, o.leBlocLegendes);

             

            Merci

            • 3. Re: [JS] Copy or move paragraph style and character style
              Loic.Aigon Adobe Community Professional

              Move is fine too but as you may know it, move differs from duplicate as it actually removes the object from original document. Duplicates preserves the original object.

              • 4. Re: [JS] Copy or move paragraph style and character style
                Liphou Level 1

                The move () command is good but control is duplicate (), it does exactly what I need.


                La commande move() est bien mais la bonne commande est duplicate(), elle fait exactement ce que j'ai besoin.

                • 5. Re: [JS] Copy or move paragraph style and character style
                  Liphou Level 1

                  Our messages crosses, you are absolutely right, I had to actually experience

                  Nos messages se croise, vous avez totalement raison, je venais d'en fait l'experience