17 Replies Latest reply on Apr 25, 2013 11:29 PM by Vamitul

    Deleteing assoiated text form conditional text dialiog

    Ranjan_123_singh Level 1

      Hi,

       

       

                I have made some contition set using "conditional text" dialig. I want, when I delete those condition set, there associated text should also be deleted. How is that possible. If anyone knows please tell me

       

      Thanks in advance

      Ranjan

        • 1. Re: Deleteing assoiated text form conditional text dialiog
          Trevorׅ Adobe Community Professional

          I'm sure there's a better way of doing it but this works.

           

          #target indesign
          var myDoc = app.activeDocument;
          app.findGrepPreferences = app.changeGrepPreferences = null;
          // Change "Condition 1" to name of your condition
          myCondition = "Condition 1";
          app.findGrepPreferences.appliedConditions = [myCondition] ;
          app.findGrepPreferences.findWhat = ".+";
          myDoc.changeGrep();
          app.activeDocument.conditions.item(myCondition).remove();
          
          • 2. Re: Deleteing assoiated text form conditional text dialiog
            Trevorׅ Adobe Community Professional

            Ranjan

             

            Was the code above helpfull, Correct?

             

            If yes then mark it as correct and a little bit of manners would be to say thank you, it doesn't hurt.

             

            I saw of all the post you have posted you have not marked any as correct or said thank you one time after receiving the answer you want.

             

            I don't think that people who demand scripts (not you) or people who show no recognition / appreciation to those who help them (you) can expect to receive help.

            • 3. Re: Deleteing assoiated text form conditional text dialiog
              Vincent-Sweden Level 1

              Hello Trevor,

              I am experiencing the same problem as Ranjan. I'm totally new att this scripting feature, and I don't know how to add this... is is javascript?

               

              Thank you.

              • 4. Re: Deleteing assoiated text form conditional text dialiog
                Vamitul Level 4

                Hi Vincent.

                 

                Copy the above script to a plain text file, name it whatever you want but add the ".jsx" extension to it, then you can just double click on it because it has the #target directive, or you can follow these instructions:

                http://indesignsecrets.com/how-to-install-scripts-in-indesign.php

                • 5. Re: Deleteing assoiated text form conditional text dialiog
                  Vincent-Sweden Level 1

                  If i may ask a very inconsiderate question. The code works for seperate condition. Let's say I have 50 conditions and 25 of them needs to be removed. How can I write the code to remove the text/object for each dimmed conditon.?

                   

                  I'm eager to learn scripting and working on it, but this problem I prefer to have it solved within next weeks then... years.

                   

                  Thank you.

                  • 6. Re: Deleteing assoiated text form conditional text dialiog
                    Trevorׅ Adobe Community Professional

                    Hi Vincent,

                     

                    #target indesign
                    var myDoc = app.activeDocument;
                    app.findGrepPreferences = app.changeGrepPreferences = null;
                    // Change "Condition 1" to name of your condition
                    myConditions = ["Condition 1","Condition 2","Condition 3","Condition 4"];
                    var l = myConditions.length;
                    while (l--)
                        {
                            app.findGrepPreferences.appliedConditions = [myConditions[l]] ;
                            myDoc.changeGrep();
                            app.activeDocument.conditions.item(myConditions[l]).remove();
                        }
                    

                     

                    This presumes that each text only has one condition to it.

                    If this is not the case things are a little bit more complicated

                     

                    Trevor

                    • 7. Re: Deleteing assoiated text form conditional text dialiog
                      Vamitul Level 4

                      hope Trevor won't mind me hijacking this.

                       

                       

                      #target indesign
                      
                      
                      function main() {
                                var myDoc = app.activeDocument;
                                app.findGrepPreferences = app.changeGrepPreferences = null;
                                // Change "Condition x" to name of your conditions, add as many as needed
                                myCondition = ["Condition 1",
                                          "Condition 2",
                                          "Condition 3"];
                                for (var i = 0; i < myCondition.length; i++) {
                                          app.findGrepPreferences.appliedConditions = [myCondition[i]];
                                          app.findGrepPreferences.findWhat = ".+";
                                          myDoc.changeGrep();
                                          app.activeDocument.conditions.item(myCondition).remove();
                                }
                      }app.doScript("main()",undefined,undefined,UndoModes.fastEntireScript,'Delete Condition Set');)
                      
                      

                       

                      try it out, i can't test it now.

                       

                      later edit.. Trevor is FAST!!!

                      • 8. Re: Deleteing assoiated text form conditional text dialiog
                        [Jongware] Most Valuable Participant

                        Welcome to InDesign Scripting!

                         

                        Vincent-Sweden wrote:

                        How can I write the code to remove the text/object for each dimmed conditon.?

                         

                        Dimmed == not visible? Then you can use the following code. Trevor's Replace With Nothing trick does not work when a conditional text is invisible, so this script scans your list for Not Visible conditions, makes them visible, replaces them with no text, and then removes the condition itself.

                         

                        I only tested it on a small text document -- please make sure you test on a copy of yours!

                         

                        #target indesign
                        var myDoc = app.activeDocument;
                        app.findGrepPreferences = app.changeGrepPreferences = null;
                        // Change "Condition 1" to name of your condition
                        myConditionList = app.activeDocument.conditions.everyItem().getElements();
                        
                        for (i=myConditionList.length-1; i>=0; i--)
                        {
                            if (myConditionList[i].visible == false)
                            {
                                myConditionList[i].visible = true;
                                app.findGrepPreferences.appliedConditions = [myConditionList[i].name] ;
                                app.findGrepPreferences.findWhat = ".+";
                                myDoc.changeGrep();
                                app.activeDocument.conditions.item(myConditionList[i].name).remove();
                            }
                        }
                        

                         

                        (Edit) Hi Vamitul, hi Trevor!

                        • 9. Re: Deleteing assoiated text form conditional text dialiog
                          Trevorׅ Adobe Community Professional

                          Hi Vamitul,

                           

                          Don't mind one bit!

                           

                          Notice that I took the out the line

                          app.findGrepPreferences.findWhat = ".+";

                          because it's not needed.

                           

                          I have also found that using fastEntireScript undo mode can be very risky when changing grep preferences and it is better to forgo on the speed and use entireScript undo mode.

                           

                          besides that the script are quite similar

                          doc verses myDoc / for verses while

                          • 10. Re: Deleteing assoiated text form conditional text dialiog
                            Vincent-Sweden Level 1

                            Damn... you are all fast.

                             

                            Welcome Jongware to this thread.

                             

                            Jongware came from this thread few minutes ago.

                             

                            http://forums.adobe.com/message/5247079#5247079

                             

                            Jongware: Invisible YES! =).

                            • 11. Re: Deleteing assoiated text form conditional text dialiog
                              Trevorׅ Adobe Community Professional

                              yep, we just can't keep up with each other

                              • 12. Re: Deleteing assoiated text form conditional text dialiog
                                Vamitul Level 4

                                ok.. let's hijack the thread a bit more

                                please can you tell me more about what problems apear when using fastEntireScript and grep prefrences?

                                I never noticed anything, but now that you mention it i had some very very wierd bugs in the script i'm still working on and that uses tons and tons of greps.

                                 

                                also, if the findWhat is not nedded (true, didn't even look at it), you can then use findTextPreferences, and changeText() for a large speed boost.

                                • 13. Re: Deleteing assoiated text form conditional text dialiog
                                  Vincent-Sweden Level 1

                                  Didn't work... says line 13 error...

                                   

                                  }app.doScript("main()",undefined,undefined,UndoModes.fastEntireScript,'Delete Condition Set');)

                                  • 14. Re: Deleteing assoiated text form conditional text dialiog
                                    Vamitul Level 4

                                    welll now.. see that little winky smily face just at the end?  ; )   just wipe his smile (delete the parantheses) and it should work.

                                    however, i think jongware's solution is the winner here.

                                    • 15. Re: Deleteing assoiated text form conditional text dialiog
                                      Vincent-Sweden Level 1

                                      Vamitul,

                                      Aha... that little bugger... i believe this one is useful as well. Since it target one or several specific conditions. I might have use of it.

                                       

                                      Just tried Jungware solution and it works like a charm. Just like I wanted iy. One click and everything is gone.

                                       

                                      Thank you all!

                                      • 16. Re: Deleteing assoiated text form conditional text dialiog
                                        Trevorׅ Adobe Community Professional

                                        Hi Jongware,

                                         

                                        Isn't this new edit feature useful.  Great for correcting buggy scripts and keep editing them till they work.  I think Jives got sick of my long threads of try this - script version 23.

                                         

                                        Hey you had insider information!, in some places you can get in trouble for that.

                                        [Jongware] wrote:

                                         

                                        Dimmed == not visible? Then you can use the following code. Trevor's Replace With Nothing trick does not work when a conditional text is invisible, so this script scans your list for Not Visible conditions, makes them visible, replaces them with no text, and then removes the condition itself.

                                        ......

                                        ......

                                         

                                        (Edit) Hi Vamitul, hi Trevor!

                                         

                                        Funny Trevor's trick work for me, even on when a conditional text is invisible.

                                        Weird.

                                        with the app.findGrepPreferences.findWhat = ".+"; the line returns are left in.

                                        So one could either change the what to ".+\r?" or according to me just leave out the line.

                                         

                                        Anyway beside the not making visible and the doScript I would get rid of .name and item

                                         

                                        app.doScript("main()",undefined,undefined,UndoModes.entireScript,'Delete Condition Set');
                                        function main()
                                        {
                                        var doc = app.activeDocument,
                                               myCons = doc.conditions.everyItem().getElements(),
                                               l = myCons.length;
                                        app.findGrepPreferences = app.changeGrepPreferences = null;
                                        while (l--) if (!myCons[l].visible) 
                                            {   
                                                app.findGrepPreferences.appliedConditions = [myCons[l]];
                                                doc.changeGrep();
                                                myCons[l].remove();
                                            }
                                        }
                                        

                                        It works BLAZINGLY fast on a few character document

                                         

                                        @Vamitul

                                         

                                        I'm not too sure about the speed differences between grep and text searches but my guess would be if one is searching for nothing i.e. no findWhat then it ain't going to make a big difference I'd be happy to hear if different.

                                         

                                        Regarding the fastEntireScript issue

                                        There are threads on it and both Marc and Harbson their sites have written articalls  on it but I do feel very strongly that besides the issues mentioned there it is buggy on all cs versions including cs6.

                                        As Harbs mentions if statements can be ignored but I have found even .findWhat = "foo" are ignored (on a lot but not every occasion).

                                        I can't produce a list of bugs off my cuff, (or even a list of bugs on my cuff )  you could start a thread on it, I can just say that I made a lot of scripts (on cs5) that don't work with it and do without it.

                                        As a guideline I would suggest using it only for

                                        1) forum script that don't matter too much if they work

                                        2) On scripts which do not contain if statements and need to run very quick and you can see easily if the job was done.

                                        3) On very very thoroughly tested script that won't cost you your job if they fail.

                                         

                                        Never use fastEntireScript undo mode on weapons systems or you could end up ....

                                        • 17. Re: Deleteing assoiated text form conditional text dialiog
                                          Vamitul Level 4

                                          about the grep/text find differences. On a smaller document there is hardy any, but on a large text the speed difference can be huge (tested and retested by yours truly as i work with 1000+ pages documents on a regular basis). The thing is that grep uses a different search engine that plain find text (i think it's a implementation of PCRE), that is a lot more complex and computational intensive. So even for a blank search there is a speed penalty. You don't even need sctipring to test it. Just make a very large document and perform the same find/replace using Find text first, and then Find Grep.

                                           

                                          About the fastEntire part, i can't find Harb's article (can you give a link, please), but i knew Marc's and been using his trick with running a just the intensive functions inside a fastEntrie. So far, on my production script i haven't had much problems. The thing is i have huge scripts that run sometimes for hours on end, so every bit of extra speed can make a huge difference.

                                          And, btw. all my scripts are VERY thoroughly tested. A 80.000 lines script can get more than 2 hours of testing time before it moves to production (unfortunatly it actualy happened).