16 Replies Latest reply on Jun 5, 2008 6:51 AM by (Lee_Fielding)

    [js] CS Scripting not working with CS3

    Level 1
      Hello,

      We had a JavaScript made for us that enabled the user to exchange certain text within a document.
      This script works fine with CS (Ver.3.0.1) but gives a JavaScript Error - #55, Error String: Object does not support the property or method 'findPreferences' with CS3 (Ver.5.0)

      I have tried 'tinkering' around with the scripting - but I have zero experience with JavaScript and have not found a solution.
      Additionally the people that wrote the initial script are not available.

      I have bought several books but they all seem like alien-language to me
      :-(

      Below is the section of origional CS scripting.
      Can anyone point out to me WHY this script does not work with CS3?
      And WHERE I should start looking - changing?

      Thanks in advance for your help and guidence.
      Lee
      --------------------------

      //-------------------------------------------------
      // Exchange the text
      //-------------------------------------------------
      function actProjectData(oneDoc, oneResult){
      app.findPreferences = null; app.changePreferences = null;
      oneDoc.search(undefined, true, true, oneResult[0],{appliedCharacterStyle:oneDoc.characterStyles.item(myProjectTitleCharStyleNa me)}, undefined);
      oneDoc.search(undefined, true, true, oneResult[1],{appliedCharacterStyle:oneDoc.characterStyles.item(myOfferNoCharStyleName)}, undefined);
      oneDoc.search(undefined, true, true, oneResult[2],{appliedCharacterStyle:oneDoc.characterStyles.item(myOfferDateCharStyleName) }, undefined);
      app.findPreferences = null; app.changePreferences = null;
      }
        • 1. Re: [js] CS Scripting not working with CS3
          Peter Kahrel Adobe Community Professional & MVP
          >Can anyone point out to me WHY this script does not work with CS3?
          And WHERE I should start looking - changing?

          Find and change have changed a lot in CS3 scripting. The first thing to change is this:
          >app.findPreferences = null; app.changePreferences = null;

          change to

          >app.findTextPreferences = null; app.changeTextPreferences = null;

          Then in the rest of the script, look for ".search(" and change the format of the search commands. They're not in the code that you posted, so look elsewhere.

          Peter
          • 2. Re: [js] CS Scripting not working with CS3
            Level 1
            Thank you Peter,

            the changing of app.findPreferences & app.changePreferences has eliminated the Error #55.
            A small step for you - a giant leep for me!
            :-)

            I have looked around and 'played' with the ".search(" commands - but did not get any further.
            I have tried using a debugger - but I simply get stopped at the first instance of ".search(" with a new JavaScript Error:
            > Error Number: 24
            Error String: oneDoc.search is not a function

            Unfortunatly I am unable to include/attach the script - which makes this rather frustrating to explain.
            I have uploaded here: http://www.freetimecorner.ch/joomla2/images/stories/pod_v1_1.txt
            if you are interested in seeing the full picture.

            Am I to assume that 'search' is an incorrect function?
            If so - shouldn't it be something along the lines of 'FindChange...'?
            • 3. Re: [js] CS Scripting not working with CS3
              Peter Kahrel Adobe Community Professional & MVP
              >Am I to assume that 'search' is an incorrect function?

              That's right. In your script you may have someting like this:
              >oneDoc.search ("a", true, false, "b")

              but search() doesn't exist anymore. In CS3, you need this:
              app.findTextPreferences.findWhat = "a";
              
              app.changeTextPreferences.changeTo = "b";
              oneDoc.changeText();


              to replace "a" with "b". "true" and "false" set case-sensitivity and whole-word matches, which is done differently in CS3:
              app.findChangeTextOptions.wholeWord = true; // or false
              
              app.findChangeTextOptions.caseSensitive = true;  // or false


              Peter
              • 4. Re: [js] CS Scripting not working with CS3
                Peter Kahrel Adobe Community Professional & MVP
                Come to think of it, maybe it's easier to create a folder "Version 4.0 Scripts" under your scripts folder and place your CS script in there. Maybe that will do the trick. Should have thought of that earlier.

                Peter
                • 5. Re: [js] CS Scripting not working with CS3
                  Level 1
                  > Come to think of it, maybe it's easier to create a folder "Version 4.0 Scripts" under your scripts folder and place your CS script in there. Maybe that will do the trick. Should have thought of that earlier.

                  Tried this, but it didn't seem to do anything... But certainly a 'try' worth.

                  Currently playing around with the:
                  > app.findTextPreferences.findWhat = "a";
                  app.changeTextPreferences.changeTo = "b";

                  oneDoc.changeText();

                  I've got to the point where I have no error messages :-) Now I'm really flying.....
                  Fact is - not all text and also the wrong text is replaced!!!

                  I'm currently playing with the script to try and replace all texts with a given paragraph style with the entered text...
                  Not proving to be simple for me, but I'm learning rather a lot!
                  Now that doesn't sound very clear when I go back and read it!

                  What I want to say is:
                  Each page of the document has the project name, No & Date on it (each having their own paragraph style)
                  so
                  With this script it asks you the Project name, No. and Date and then goes through the whole document and replaces all instants of those texts with specific paragraph styles with the newly 'entered' text.

                  Proving to be a little mountain for me - Thought it would only be a hill!
                  • 6. Re: [js] CS Scripting not working with CS3
                    Peter Kahrel Adobe Community Professional & MVP
                    To look in a particular paragraph style, add this line:
                     app.findTextPreferences.findWhat = "a";
                    
                    app.findTextPreferences.appliedParagraphStyle = "xxxx";
                    app.changeTextPreferences.changeTo = "b";
                    oneDoc.changeText();


                    Peter
                    • 7. Re: [js] CS Scripting not working with CS3
                      Level 1
                      B R I L L I A N T
                      :-)


                      So now I'm coming down the mountain....
                      Peter - you saved me from pulling my last few hairs out!

                      Just one little snag - It does not change the text that is locked into the page!
                      I have to release (Shift+Ctrl) the text element before it will 'see' and 'change' the contents of those too!

                      Is there a way that the 'find' function will also look into fixed text elements?
                      • 8. Re: [js] CS Scripting not working with CS3
                        Kasyan Servetsky Level 5
                        Hi Lee,
                        I'm not sure at all if it woud work, but try this:
                        http://www.businessweekly.h.com.ua/downloads/Pod_v2_1.jsx

                        I don't have a scripting guide for CS in my archive too old version so don't have a clear idea of how your script works. Could you describe in more details what it does and it would be even better if you send me an example document.

                        Kasyan
                        • 9. Re: [js] CS Scripting not working with CS3
                          Kasyan Servetsky Level 5
                          >It does not change the text that is locked into the page!

                          If you mean text on master page use:
                          app.findChangeTextOptions.includeMasterPages = true;
                          • 10. Re: [js] CS Scripting not working with CS3
                            Peter Kahrel Adobe Community Professional & MVP
                            Lee,

                            Do you mean something on a master page? If yes, add this line:
                            >app.findChangeTextOptions.includeMasterPages = true;

                            anywhere before oneDoc.changeText();

                            Peter
                            • 11. Re: [js] CS Scripting not working with CS3
                              Level 1
                              I had tried the 'includeLockedLayersForFind' and 'includeLockedStoriesForFind' - but never thought about the master! Dooooh!

                              :-) :-) :-)

                              Peter - you have just become my hero!
                              Final section of scripting that's good for me:
                              ----------------------------------------------------
                              app.findChangeTextOptions.includeMasterPages = true
                              app.findTextPreferences.appliedCharacterStyle = myProjectTitleCharStyleName;
                              app.changeTextPreferences.changeTo = oneResult[0];
                              oneDoc.changeText();

                              app.findTextPreferences.appliedCharacterStyle = myOfferNoCharStyleName;
                              app.changeTextPreferences.changeTo = oneResult[1];
                              oneDoc.changeText();

                              app.findTextPreferences.appliedCharacterStyle =
                              myOfferDateCharStyleName;
                              app.changeTextPreferences.changeTo = oneResult[2];
                              oneDoc.changeText();
                              -------------------------------------------------------

                              If ever you are in Switzerland, near Zürich - let me know - I owe you a night of free beer!

                              Ladies and Gents....
                              I have just climb a mountain that has been stopping me from advancing for over a week!
                              Four hours talking with Peter and I'm now standing on the other side - as happy as a pig in muck!
                              • 12. Re: [js] CS Scripting not working with CS3
                                Level 1
                                Hello Peter - I do hope you are still around?

                                I am wanting to add a little addition to the script you help me with yesterday.
                                Once I have 'found' the text elements with the given character style, i.e.:
                                > app.findTextPreferences.appliedCharacterStyle = myProjectTitleCharStyleName;

                                I then want to store its current content into a string before I then go and replace it, i.e.:
                                > app.changeTextPreferences.changeTo = oneResult[0];
                                oneDoc.changeText();

                                I have tried something along the lines of (please don't laugh):
                                > var myCurrentProjectTitle = (app.findTextPreferences.appliedCharacterStyle.content = myProjectTitleCharStyleName);

                                ...but as you can guess, it doesn't work (for reasons I don't yet know why).

                                Are you still there to point me in the right direction?
                                It would be greatly appreciated!

                                Lee
                                • 13. Re: [js] CS Scripting not working with CS3
                                  Peter Kahrel Adobe Community Professional & MVP
                                  Try this:
                                  app.findChangeTextOptions.includeMasterPages = true;
                                  
                                  app.findTextPreferences.appliedCharacterStyle = myProjectTitleCharStyleName;
                                  f = oneDoc.findText();
                                  var myCurrentProjectTitle = f[0].contents;


                                  To get to the contents of found items, you need to use findText(), not changeText(). When you say f = oneDoc.findText(), you get all occurrences of text that has the paragraph style applied to it. These are stored in array, here, f. The first object found is f[0], its contents is f[0].contents. This precedes your change action.

                                  Is that what you were after?

                                  Peter
                                  • 14. Re: [js] CS Scripting not working with CS3
                                    Level 1


                                    :-)


                                    Well, the night of beer has increased to two!

                                    BTW - Can you recomend a good book for noobs like me?
                                    I have bought both 'Sams Teach Yourself Java in 21 days' & 'Beginning Programming with Java for Dummies' - Both of which lost me once I got past the Index page ! ! !

                                    Thanks a million.
                                    Lee
                                    • 15. Re: [js] CS Scripting not working with CS3
                                      Peter Kahrel Adobe Community Professional & MVP
                                      You can try the "Adobe guide to scripting": in the ESTK, Help > SDK. Another possibility is http://oreilly.com/catalog/9780596528171/ which is really for CS2 but covers a lot of CS3 as well. The introductory chapter shows how you can explore the object model, and that hasn't changed in principle, nor have the Javascript basics.

                                      Peter

                                      PS: Look forward to all that beer!
                                      • 16. Re: [js] CS Scripting not working with CS3
                                        Level 1
                                        Thanks for the tip...

                                        Beer: No unfortunatly it's not like a good bitter or ale!
                                        The beer around here isn't that good. Have to pop over to Germany for the better stuff!
                                        But it still doesn't touch the likes of a chlled Tetley's with a pack of pork scratchings....

                                        Thanks again.