12 Replies Latest reply on Feb 15, 2016 6:38 AM by tpk1982

    Need Quick help for Insertion point

    tpk1982 Level 4

      Hi,

       

      I am trying to overrides the paragrpah style after i pasting text from word. It works fine if i don't have paragraph return.

       

      app.menuActions.item("$ID/Paste").invoke(); //paste
      var myDoc=app.activeDocument;  
      mySel=app.selection[0];
      mypara=mySel.paragraphs[0].insertionPoints[-1].paragraphs[0];
      
      
      app.findTextPreferences = null;     app.changeTextPreferences = null;  
      app.findTextPreferences.fontStyle="Bold";
      app.changeTextPreferences.appliedCharacterStyle=myDoc.characterStyleGroups.itemByName("General").characterStyles.item("Bold");
      mypara.changeText();  
      
      
      app.scriptMenuActions.itemByID(8498).invoke(); //clearing overrides in paragraph style
      
        • 1. Re: Need Quick help for Insertion point
          tpk1982 Level 4

          Screen Shot 2016-02-13 at 4.55.25 PM.png

           

          But not working if i have paragraph return.

          • 2. Re: Need Quick help for Insertion point
            Vamitul Level 4

            instead of findText() and findTextPreferences use

            findGrep() and findGrepPreferences.

            for extra, you can use app.findGrepPreferences.findWhat=(?s).+

            • 3. Re: Need Quick help for Insertion point
              tpk1982 Level 4

              Hi Vamitful,

               

              I get the below error message. If i use (?s).+ it will select do find and change for current paragraph only?


              Screen Shot 2016-02-15 at 11.57.24 AM.png



              I previously used the below coding to remove overrides


              var mySel=app.selection[0];
              var mypara=mySel.paragraphs[0].insertionPoints[0].paragraphs[0].appliedParagraphStyle.name;
              app.findTextPreferences.appliedParagraphStyle = mypara.toString();
              app.changeTextPreferences.appliedParagraphStyle =mypara.toString();
              

               

               

              But the problem is the paragraph style is in style group. SO i failed with this method. I am not sure the style name, it may be varies. Is it possible to use this method?

               

              Thanks,

              Karthi

              • 4. Re: Need Quick help for Insertion point
                Vamitul Level 4

                Before you post, please try and read the documentation first. http://www.indesignjs.de/extendscriptAPI/indesign11/#FindGrepPreference.html

                Second thing, please try to think for yourself. What kind of data are you trying to pass to app.findGrepPreferences.findWhat? What kind of data could (?s).+ be in Javascript? Yes, i made a typo there, but i was not trying to spoon-feed you an answer, but just point you to the right direction.

                     app.findGrepPreferences.findWhat="(?s).+";

                 

                Second question... again, RTFM!!

                InDesign ExtendScript API (11.0)

                And to spoon-feed you the answer again:

                    myPara.clearOverrides(OverrideType.PARAGRAPH_ONLY);

                 

                Lastly, if you have a question, please mark your thread as such!

                 

                LE: This "Answer is being moderated crap is really really annoying. @Adobe, if you cannot find some better system, at the very least you could implement some whitelist of commonly used sites.

                • 5. Re: Need Quick help for Insertion point
                  ypsillon

                  Hi,

                  I've had similar problem :-)

                  try to iterate through array: allParagrahpStyles

                  it works !

                   

                  eg.

                   

                  var myDoc = app.activeDocument;

                  var myPStyles = myDoc.allParagraphStyles;

                  for ( n = 0; n < myPStyles.length; n++) {

                  var A = myPStyles[n].name; $.writeln(A);

                  switch (A) {

                  case "desired_style_name" :

                  // ----------------- do what you need -----------------

                  break;

                   

                  default :

                  break;

                  }

                  }

                  • 6. Re: Need Quick help for Insertion point
                    tpk1982 Level 4

                    Hi Vamitful,

                     

                    In my coding i already used the below code to override.

                     

                    app.scriptMenuActions.itemByID(8498).invoke(); //clearing overrides in paragraph style


                    Only thing i need is, to apply the find and change for particular paragraph. So that i used Insertion point.


                    The following steps i am doing:


                    1) Copying text from word file (including bold and italic applied texts)


                    2) Pasting those text in indesign (i already have bold and italic character style so it find and apply the respective style).


                    3) I am clearing overrides for the pasted particular paragraph.


                    As you said i aware what i want. But struck in the insertionpoint concept. If i give insertionPoints[-1].paragraphs[0] it will apply only on current paragraph.


                    I need only one help. How to do "find and replace" for current paragraph alone.


                    I don't know how to change the thread as marked. Sorry for that.


                    Thanks,

                    Karthi



                    • 7. Re: Need Quick help for Insertion point
                      tpk1982 Level 4

                      My Biggest headache is, i don't know the style name and stylegroup name. If i find this with 'for' loop the script maybe sluggy.

                       

                      If i know i can use the below code to find appliedstyle. My problem was solved. :

                       

                      app.findGrepPreferences.appliedParagraphStyle = app.activeDocument.paragraphStyleGroups.item("xx").paragraphStyles.item("xx");


                      But i don't know the style name and stylegroup name

                      • 8. Re: Need Quick help for Insertion point
                        Vamitul Level 4

                        you mean you are looking for:

                        app.fidGrepPreferences.appliedParagraphStyle=myPara.appliedParagraphStyle;

                        ????

                        • 9. Re: Need Quick help for Insertion point
                          tpk1982 Level 4

                          Not exactly.. the appliedstyle method i searched before is to clear the overrides..

                           

                          but the style is in the stylegroup..

                           

                          Screen Shot 2016-02-15 at 4.28.44 PM.png

                           

                          so i ignore that method and jump into another method using

                           

                          insertion point (for current paragraph)

                           

                          and app.scriptMenuActions.itemByID(8498).invoke() (for overrides clearing)

                           

                          Here is the my first tested method with applied paragraph:

                           

                          app.menuActions.item("$ID/Paste").invoke(); 
                          var myDoc=app.activeDocument;   
                          var mySel=app.selection[0]; 
                          var mypara=mySel.paragraphs[0].insertionPoints[0].paragraphs[0].appliedParagraphStyle.name; 
                          app.findTextPreferences = null;     app.changeTextPreferences = null;   
                          app.findTextPreferences.fontStyle="Bold"; 
                          app.findTextPreferences.appliedParagraphStyle = mypara.toString(); 
                          app.changeTextPreferences.appliedCharacterStyle=myDoc.characterStyleGroups.itemByName("General").characterStyles.item("Bold"); 
                          app.changeTextPreferences.appliedParagraphStyle =mypara.toString();   
                          app.changeText();
                          
                          

                           

                          It will work only If i give the paragraph stylegroup name perfectly.

                          • 10. Re: Need Quick help for Insertion point
                            tpk1982 Level 4

                            The above coding work with the below setting:

                             

                            Screen Shot 2016-02-15 at 4.42.46 PM.png

                             

                            Means style is in outside of group.

                            • 11. Re: Need Quick help for Insertion point
                              tpk1982 Level 4

                              In other simple words:

                               

                              I need to apply find and change only the cursor placed paragraph in the document.

                              • 12. Re: Need Quick help for Insertion point
                                tpk1982 Level 4

                                Any suggestion is appreciated. Please help regarding this issue sort out.