1 2 Previous Next 61 Replies Latest reply on Aug 20, 2007 4:56 AM by (DaveSaunders)

    With CS2, some things have changed

    Level 2
      I have not located a place where changes in scripting between CS and CS2 are reported, so I thought I'd start a topic here with some of the things I know about.

      This is about changes to the object model that are not related to changes in the functionality that have taken place.


      1. User Interaction Control
      2. Table Labels
      3. Parent Text Frame
      4. New Beep Function
      5. Find/Change symbol for End Nested Style Here
      6. Convert to Table
      7. Active Script in doScript
      8. Text selections more specific

      9. Table selections
      10. Indexes
      11. Basic Paragraph style
      12. Enumeration Name Changes
      13. Placed Assets
      14. Previous Text Frame
      15. Version Property
      16. Add Page Reference (Index)


      In describing these in the following messages, I'll use JavaScript terminology, but most of these issues are independent of the language.
        • 1. Re: With CS2, some things have changed
          Level 2
          User Interaction Control

          In CS, one would write:

          app.userInteractionLevel = UserInteractionLevels.neverInteract;
          app.userInteractionLevel = UserInteractionLevels.interactWithAll;

          In CS2, because of the new scriptPreferences property, one must use:

          app.scriptPreferences.userInteractionLevel = UserInteractionLevels.neverInteract;
          app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;

          There is a third preference option now:

          app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAlerts;

          The intention of this mode of operating is that any dialogs would be suppressed with the default settings accepted, but any alerts that your scripting actions caused would still be displayed. I have yet to successfully use this option.
          • 2. Re: With CS2, some things have changed
            Level 2
            Table Labels

            This is more a change in functionality of the product, but if (like me) you had used labels for tables in CS confident that the user wouldn't see them, this is changed in CS2. If you select a whole table in the UI, you'll see the Script Label (if there is one) in the Script Label palette.

            Note also that cells can now have labels. This should help those people who want to automate linkages between parts of tables with parts of spreadsheets. Cell labels too are visible in the UI.

            In the situation where a table consists of just one cell (I use these in my HeadStraddler product), you can see only the table label in the UI. To see the cell label, you'd have to temporarily add a cell to the table.

            The really good news here is that both Cells and Tables have the insertLabel and extractLabel methods, so you can still have labels added by your scripts that aren't visible in the UI.
            • 3. Re: With CS2, some things have changed
              Level 2
              Parent Text Frames

              This change is likely to cause a fair amount of editing. In CS, the text property parentTextFrame sometimes returned a collection making its name rather confusing. Now, it always returns a collection and so its name has been changed to the plural form.

              So, if the only thing you care about is the parent text frame of the first character of some text, you can write:

              myTF = myText.parentTextFrames[0];

              If you want to know if some text spans more than one frame, use:

              if (myText.parentTextFrames.length > 1) ...

              If you want to know if some text is wholly overset, use:

              if (myText.parentTextFrames.length == 0) ...
              • 4. Re: With CS2, some things have changed
                Level 2
                New Beep Function

                I think this is JS only. Whereas before, exit() issued a beep as it exited, it now exits silently. However, there is a new beep() method to create a beep. This means you can issue a beep as you pop-up an alert.

                I've been using this function to manage my exiting from scripts so that they will work with either CS or CS2:

                function errorExit(message) {
                if (app.version != 3) { beep() } // CS2 includes beep() function.
                if (arguments.length > 0) {
                alert(message);
                }
                exit(); // CS exits with a beep; CS2 exits silently.
                }
                • 5. Re: With CS2, some things have changed
                  Level 2
                  Find/Change End Nested Style

                  This is more of a functional change of the application itself. The symbol used by Find/Change for End Nested Style Here is now ^h rather than ^\. I don't think I ever actually used that symbol in a script but had I done so ...
                  • 6. Re: With CS2, some things have changed
                    Level 2
                    Convert to Table

                    I've been grappling with this one most of the day. There is something strange associated with the form of the convert to table method when used with three parameters (as you do when you want the return character to delimit both cells and rows).

                    In CS, my HeadStraddler product uses:

                    myTable = myText.convertToTable("\r","\r",1);

                    to convert the text of the first paragraph of a text frame (less its paragraph marker) to a single-cell table. To get this to work properly in CS2, I have had to use:

                    myTable = myText.convertToTable("\r","\r",1)[0];

                    but this has the look of an unintentional bug, so I'm actually restructuring what I'm doing altogether, taking advantage of the fact that the table is the first thing in the frame, so I've changed the original to:

                    myText.convertToTable("\r","\r",1);
                    myTable = myFrame.characters[0].tables[0];

                    I did this to protect against the bug being fixed and my script needing to be changed again.
                    • 7. Re: With CS2, some things have changed
                      Level 2
                      Active Script in a doScript

                      In CS, if you did this:

                      myTest = "alert(app.activeScript)"
                      app.doScript(myTest);

                      You would see an alert that gives you the path to the base script.

                      In CS2, doScript is handled differently. The attempt to run the script in myTest results in an error message that the script doesn't have an associated script file.

                      This is true even if you use the new versioning feature:

                      if (app.version != 3) {app.scriptPreferences.version = 3.0}
                      myTest = "alert(app.activeScript)"
                      app.doScript(myTest);

                      will still give you the error because of the fundamentally different manner in which scripts are run with CS2.
                      • 8. Re: With CS2, some things have changed
                        Level 2
                        This list is by no means exhaustive, but these are the things I've run into in the past few days.

                        If any of you know of any other topics worthy of adding to this list, please e-mail me (my address is accessible if you click my name) or start another topic and I'll add them in here with the links at top.

                        If you want to discuss or explore any of the topics I've posted, feel free to start a new topic.

                        Dave
                        • 9. Re: With CS2, some things have changed
                          Level 1
                          Hi Dave--

                          Regarding your doScript example--you haven't given it a file to run, you've given it a string. I'm not sure what you mean by "the fundamentally different manner in which scripts are run with CS2"--I don't see it. If doScript for a string returned a file for a string being run using doScript in CS, then it was an error.

                          In addition, if you use doScript to run a script file, then app.activeScript should return the name of that file, not the name of the script in which the doScript statement is used.

                          Thanks,

                          Ole
                          • 10. Re: With CS2, some things have changed
                            Level 1
                            Hi Dave--

                            Regarding the end nested style metacharacter--this is also true in the user interface, so it's not only a scripting change (and, for that matter, we have no control over it). While I disagree with the UI team changing find/change metacharacters without notice, I do check the metacharacters list with each new release, just in case.

                            Thanks,

                            Ole
                            • 11. Re: With CS2, some things have changed
                              Level 2
                              re: doScript

                              In CS, that script I posted in number 7 returns the path of the script that called the doScript in CS2 it doesn't. That's the difference I'm pointing out.

                              The reason is that CS2 runs each script in a separate domain (if you use ESTK to debug a script that uses doScript you'll quickly see what I mean).

                              This change breaks some of my scripts rather badly. Fortunately, as you pointed out elsewhere, I can use scriptArgs to pass this information around.

                              Dave
                              • 12. Re: With CS2, some things have changed
                                Level 2
                                Text Selections

                                Text selections are more specific about what is selected than in CS. While CS would only ever give you Text or InsertionPoint as the kind of selection, CS2 will give you responses like Word or Paragraph.

                                In JavaScript, I use this method to determine if an object is text:
                                Object.prototype.isText = function() {
                                
                                switch(this.constructor.name){
                                  case "InsertionPoint":
                                  case "Character":
                                  case "Word":
                                  case "TextStyleRange":
                                  case "Line":
                                  case "Paragraph":
                                  case "TextColumn":
                                  case "Text":
                                  case "TextFrame":
                                   return true;
                                  default :
                                   return false;
                                }
                                }

                                So, I can write:

                                if (app.selection[0].isText()) {
                                // if we get here, the selection is text

                                etc.

                                Notice that I include TextFrame as text. Perhaps a second method called isStrictlyText() would exclude text frames.

                                Dave
                                • 13. Re: With CS2, some things have changed
                                  Level 2
                                  Table Selection

                                  If you have a whole table selected, then the type of the selection is returned as Table rather than a collection of Cells as before.

                                  Note that if you have a table with header and/or footer rows, selecting all the regular cells is not the same as selecting the whole table.

                                  If you have a row or a column selected, these are still returned as a collection of cells.

                                  Dave
                                  • 14. Re: With CS2, some things have changed
                                    Level 1
                                    Hi,
                                    In CS the Unicode "\u0016"= Table.
                                    Has been changed in CS2?

                                    Thanks.

                                    jxswm
                                    • 15. Re: With CS2, some things have changed
                                      Level 2
                                      I don't know -- but I'd advise against using unicode values to identify tables. Doing that kind of thing falls into the category of reverse engineering, it seems to me, and is not something that can necessarily be relied upon from one release to the next.

                                      Dave
                                      • 16. Re: With CS2, some things have changed
                                        Level 1
                                        In ID 2.0.2 - was't the same ??

                                        robin
                                        • 17. Re: With CS2, some things have changed
                                          Level 2
                                          Maybe, but I'd regard it as an implementation detail and not something to be relied upon. It's safe to rely on it for a particular release, but if they choose to implement tables in an entirely different way, they're free to do so, it seems to me. That a table has a unicode is not documented -- it's something we scripters found out by digging.

                                          Doesn't mean that it will change; just that it might.

                                          Dave
                                          • 18. Re: With CS2, some things have changed
                                            > don't know -- but I'd advise against using unicode values to identify tables. Doing that kind of thing falls into the category of reverse engineering, it seems to me, and is not something that can necessarily be relied upon from one release to the next.

                                            Very true. Relying on undocumented features is a good way to have your scripts break with the next release.

                                            However, since Adobe has no compunction about breaking documented behavior with a new release, it doesn't make much difference, does it?
                                            • 19. Re: With CS2, some things have changed
                                              Peter Kahrel Adobe Community Professional & MVP
                                              Indexes

                                              Scripting indexes has changed a lot. It finally works, and it works well. The property 'subtopic' has gone, instead you iterate the property 'topic' (up to three times). The following lines illustrate:

                                              if( app.activeDocument.indexes.length == 0 )
                                              myIndex = app.activeDocument.indexes.add()
                                              else
                                              myIndex = app.activeDocument.indexes[0]

                                              //create main topic
                                              myIndex.topics.add('dog')
                                              //create subtopics
                                              myIndex.topics.item('dog').topics.add('collie')
                                              myIndex.topics.item('dog').topics.add('setter')
                                              myIndex.topics.item('dog').topics.item('collie').topics.add('border collie')
                                              myIndex.topics.item('dog').topics.item('collie').topics.item('border collie').topics.add('*****')

                                              You can address (sub)topics by asking for topics embedded under topics:

                                              myIndex.topics[0].topics[0].topics[0].topics[0].name

                                              is the first subtopic of the first subtopic of the first subtopic of the first topic.

                                              A new property is allTopics: myIndex.allTopics returns an array of all (sub)topics. This is a flat, one-dimensional, array, i.e. it returns the whole index but without structure.
                                              • 20. Re: With CS2, some things have changed
                                                Level 1
                                                Peter--

                                                Glad you noticed that we fixed indexing! I'd actually somewhat forgotten about it, as it's not a new feature--we just made it work the way it was always supposed to work. (It was originally implemented by WinSoft in France--between their English and my French, some things were lost in translation.)

                                                There's still a lot to do, and there are still some bugs to fix--I'd urge you not to change the sort order for an existing index topic using scripting, as it's pretty fragile. But it's much better--for scripting and for saving to .inx.

                                                I like adding the "flattened" collections--such as allTopics--wherever we can (to avoid having to use iteration/recursion to find things), so it made sense to take care of it while we were working on the plug-in.

                                                Thanks,

                                                Ole
                                                • 21. Re: With CS2, some things have changed
                                                  Level 1
                                                  //----------------------------------------
                                                  A new property is allTopics: myIndex.allTopics returns an array of all (sub)topics. This is a flat, one-dimensional, array, i.e. it returns the whole index but without structure.
                                                  //----------------------------------------
                                                  In CS:
                                                  allTopics = myIndex.topics.everyItem().subtopics.everyItem();

                                                  But if change the topics's one subTopic's sortOrder, the subTopic's index has been changed, it means:
                                                  the before subTopic[x] != after subTopic[x];
                                                  I have spent so much time to solve the problem.
                                                  Is not the same as the in CS2?

                                                  jxswm

                                                  jxswm
                                                  • 22. Re: With CS2, some things have changed
                                                    Hey, wait - "sort order" ?<br /><br />Does it do what one would think it does? I.e. change sort order to that of<br />different alphabets such as German, English, Norwegian etc?<br /><br />Where is that located in the UI? I can't find it<br /><br /><br /><br />On 05-04-28 02.58, in article 3bba0c2a.19@webx.la2eafNXanI,<br />"Olav_Kvern@adobeforums.com" <Olav_Kvern@adobeforums.com> wrote:<br /><br />> There's still a lot to do, and there are still some bugs to fix--I'd urge you<br />> not to change the sort order for an existing index topic using scripting, as<br />> it's pretty fragile. But it's much better--for scripting and for saving to<br />> .inx.