5 Replies Latest reply on May 4, 2012 8:32 AM by [Jongware]

    Character Styles are lost???

    Selva_TRM Level 1

      Hi all,

       

       

      I have now experienced with all the character styles are lost when I apply paragraph style using "appliedParagraphStyle".

       

       

      var myText = myTextFrame.parentStory.paragraphs.item(1);
      myText.appliedParagraphStyle = myDocument.paragraphStyleGroups.item("Text").paragraphStyles.item("FC");

       

       

      any idea?

       

       

      Thanks

      Selva

        • 1. Re: Character Styles are lost???
          TᴀW Adobe Community Professional & MVP

          If you use the applyParagraphStyle method of a text object instead of

          changing its appliedParagraphStyle property, you get the option of

          choosing whether to clear local overrides. So try:

           

          myText.applyParagraphStyle(myParaStyle, false);

           

          HTH,

          Ariel

          • 2. Re: Character Styles are lost???
            Selva_TRM Level 1

            Sorry, its not working.

             

             

            Selva

            • 3. Re: Character Styles are lost???
              csm_phil Level 4

              Hi Selva,

               

              The Ariel solution its working fine, please find the below snapshot & js code.

               

              Selva_TRM wrote:

               

              Sorry, its not working.

               

               

              Selva

               

              var myDoc = app.activeDocument;
              var myTextFrame = myDoc.textFrames[0];
              var myText = myTextFrame.parentStory.paragraphs.item(1);
              //var myParaStyle = myDoc.paragraphStyles.item("1");
              var myParaStyle = myDoc.paragraphStyleGroups.item("Text").paragraphStyles.item("FC");
              myText.applyParagraphStyle(myParaStyle, false);
              

               

               

              thx

              csm_phil

              • 4. Re: Character Styles are lost???
                Selva_TRM Level 1

                Thanks phil.

                 

                Actually i gave  piece of coding. I think you got idea to see my full coding. My goal is Import images using script. So first i collect the figure captions into a text box in a  document, then run my script. it import the images with caption in a new page. all are work corretly but the character sytles are missing.Below is my code.

                 

                var myDocument = app.activeDocument;

                var a = Folder.selectDialog ("Choose the Folder");

                var b = a.getFiles("*.*");

                 

                myDocument.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.points;

                myDocument.viewPreferences.verticalMeasurementUnits = MeasurementUnits.points;

                 

                var top = 36;

                var left = 36;

                var bot = 144;

                var right = 144;

                 

                for (var i = 0; i <= b.length-1; i++){

                    var inddFileName = b[i].name;

                    var myTextFrame = myDocument.pages.add().textFrames.add(myDocument.layers.item("ArtTables"), {geometricBounds:[top, left, bot, right]});

                    var img = myTextFrame.parentStory.insertionPoints.item(-1).place(File(b[i]));

                    myTextFrame.appliedObjectStyle = myDocument.objectStyles.item("ArtPortrait");

                   

                    var myTextFrame1 = myDocument.pages.item(0).textFrames.item(0).parentStory.paragraphs.item(i);

                    

                    myTextFrame.parentStory.insertionPoints.item(-1).contents = "\r"+myTextFrame1.contents;

                    var myText = myTextFrame.parentStory.paragraphs.item(1);

                //    myText.appliedParagraphStyle = myDocument.paragraphStyleGroups.item("Text").paragraphStyles.item("FC");

                //    myText.applyParagraphStyle(myDocument.paragraphStyleGroups.item("Text").paragraphStyles.i tem("FC"), true);

                       var myParaStyle = myDocument.paragraphStyleGroups.item("Text").paragraphStyles.item("FC");

                    myText.applyParagraphStyle(myParaStyle, false);

                 

                      myTextFrame.fit(FitOptions.frameToContent);

                 

                }

                 

                Thanks

                Selva

                • 5. Re: Character Styles are lost???
                  [Jongware] Most Valuable Participant

                  There is nothing left to be preserved, so that's why the 'preserve overrides' trick doesn't work for you:

                   

                  Selva_TRM wrote:

                   

                   

                      myTextFrame.parentStory.insertionPoints.item(-1).contents = "\r"+myTextFrame1.contents;

                   

                  BAM! All your formatting is gone.

                  See, for instance, this recent thread for more on this: replacing text that maintains styling issue