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

    With CS2, some things have changed

    Community Member
      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
          Community Member
          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
            Community Member
            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
              Community Member
              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
                Community Member
                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
                  Community Member
                  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
                    Community Member
                    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
                      Community Member
                      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
                        Community Member
                        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
                          Community Member
                          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
                            Community Member
                            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
                              Community Member
                              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
                                Community Member
                                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
                                  Community Member
                                  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
                                    Community Member
                                    Hi,
                                    In CS the Unicode "\u0016"= Table.
                                    Has been changed in CS2?

                                    Thanks.

                                    jxswm
                                    • 15. Re: With CS2, some things have changed
                                      Community Member
                                      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
                                        Community Member
                                        In ID 2.0.2 - was't the same ??

                                        robin
                                        • 17. Re: With CS2, some things have changed
                                          Community Member
                                          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
                                            Community Member
                                            > 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
                                              pkahrel CommunityMVP
                                              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
                                                Community Member
                                                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
                                                  Community Member
                                                  //----------------------------------------
                                                  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.
                                                    • 23. Re: With CS2, some things have changed
                                                      pkahrel CommunityMVP
                                                      Richard,

                                                      Sort order is here the 'Sort By' panel in the Topic Options dialog, used to set the sort order of individual entries. Sort order for particular languages is still sadly missing.

                                                      jxswm,

                                                      I don't know if it's fixed in CS2, but as Ole mentioned that it's still fragile in CS2, you'd better hang on to your solution.

                                                      Peter
                                                      • 24. Re: With CS2, some things have changed
                                                        Community Member
                                                        Yes!

                                                        The problems in index CJK language Sorting:

                                                        b Common problems:
                                                        <1>. Simple Chinese(Chs): Phonetic--Stroke sorting can be not identifed automately;
                                                        <2>. Traditional Chinese(BIG5): Stroke sorting can be not identifed automately;
                                                        <3>. Korean can not be sorting by KS Code automately;

                                                        So: I using IndexSort Plug-In or Script to sort by:
                                                        (1). Chines Simplified(GBK) Phonetic;
                                                        (2). Chines Simplified(GBK) Stroke;
                                                        (3). Chines Traditional(BIG5) Stroke;
                                                        (4). Hangul(Korea)(KS Code);
                                                        (5). ACII

                                                        In '(5). ACII' Can change sort order to that of
                                                        different alphabets such as German, English, Norwegian etc?

                                                        //-----------------------------------------------
                                                        My meaning is: In CS2 is there a way to sort the order autoly, because I must to run the Plug-In or Script by hand now.

                                                        Thanks.

                                                        jxwswm

                                                        > http://websamba.com/IDscript/



                                                        • 25. Re: With CS2, some things have changed
                                                          Community Member
                                                          Basic Paragraph Style can't be Deleted

                                                          A couple of days ago, I posted a script that started out by deleting all paragraph styles. Even in CS, you had to avoid attempting to delete the "first" paragraph style ("No paragraph style"), but in CS2 you also need to avoid deleting the second one, also.

                                                          By the way, this is quite an annoyance in the UI. If you select all unused and your Basic Paragraph style is not in use and so gets selected (something which is more likely to happen with converted documents than newly created ones), the Delete menu item is greyed out in the Paragraph Style palette menu because you can't delete that style.

                                                          I see that the code I posted the other day:
                                                          myStyles = doc.paragraphStyles;
                                                          
                                                          try {
                                                            for (i = (myStyles.length -1); i > 0; i--) {
                                                              myStyles[i].remove();
                                                            }
                                                          } catch (e) {}

                                                          does in fact work thanks to the try construction, but in CS2, you might as well limit the loop with i > 1, like this:
                                                          myStyles = doc.paragraphStyles;
                                                          
                                                          for (i = (myStyles.length -1); i > 1; i--) {
                                                            myStyles[i].remove();
                                                          }

                                                          Dave
                                                          • 26. Re: With CS2, some things have changed
                                                            Community Member
                                                            Enumeration Name Changes

                                                            SelectionOptions.replace is now SelectionOptions.replaceWith

                                                            For scripts that might need to run with both versions, I do this:
                                                            if (app.version != 3) {
                                                            
                                                            app.select(theStory.paragraphs[n].insertionPoints[-2],SelectionOptions.replaceWith);
                                                            } else {
                                                            app.select(theStory.paragraphs[n].insertionPoints[-2],SelectionOptions.replace);
                                                            }

                                                            Dave
                                                            • 27. Re: With CS2, some things have changed
                                                              Community Member
                                                              Place Asset from Library

                                                              When an asset is placed on a document from a library, in CS it became the selection. In CS2, this is no longer the case, so you cannot rely on the selection to get a reference to what was just placed (something which I've been doing although it wasn't strictly necessary).

                                                              The following code works in both CS and CS2 and so is the preferred way of doing this:

                                                              myObj = myAsset.placeAsset(myDoc)[0];

                                                              The index is needed because an asset might consist of multiple page items, so placeAsset returns an array of references even when there's only one item.

                                                              Dave
                                                              • 28. Re: With CS2, some things have changed
                                                                Community Member
                                                                Place Asset -- Big Fat Hairy Warning

                                                                In CS2, do not attempt to place an asset on a document if you have an active selection in that document. The code in the previous message only works if you do not have a selection. If you have one, strange things happened. You might even conclude that your document is haunted.

                                                                I had this:

                                                                myFrame = app.selection[0];
                                                                myNewFrame = myAsset.placeAsset(myDoc)[0];

                                                                and all kinds of weird things happened. The only thing that made sense of the error messages I received was that somehow myNewFrame == myFrame and indeed, the debugger confirmed this was true.

                                                                Changing the above to:

                                                                myFrame = app.selection[0];
                                                                app.selection = null;
                                                                myNewFrame = myAsset.placeAsset(myDoc)[0];

                                                                got things working.

                                                                Dave
                                                                • 29. Re: With CS2, some things have changed
                                                                  Community Member
                                                                  Can we have this what's changed information for AppleScripter also?

                                                                  TIA
                                                                  • 30. Re: With CS2, some things have changed
                                                                    Community Member
                                                                    Previous text frame

                                                                    Another difference. Suppose you want to link a textframe between two others. In CS you do

                                                                    frame1.previousTextFrame = frame2.previousTextFrame;
                                                                    frame2.previousTextFrame = frame1;

                                                                    This gives an error in CS2, because frame2.previousTextFrame is already frame1, as this confirms:

                                                                    frame1.previousTextFrame = frame2.previousTextFrame;
                                                                    if (frame2.previousTextFrame != frame1){
                                                                    frame2.previousTextFrame = frame1;
                                                                    }

                                                                    Teus de Jong
                                                                    • 31. Re: With CS2, some things have changed
                                                                      Community Member
                                                                      Yikes, I was under the impression that there wouldn't be that many changes but there sure are. I've identified 3412 (!) differences so far, by comparing the scripting libs of CS and CS2 via reflection. This excludes all new types, such as ObjectStyle.

                                                                      One very, very bad thing is that the scripting lib is now even less (by magnitudes) typesafe than it was before, making typesafe scripting in .NET a PITA.

                                                                      Not very inspiring....
                                                                      • 32. Re: With CS2, some things have changed
                                                                        Community Member
                                                                        Working with the selection object is easier. This script works in CS2 but not in CS (in that the selection is re-established in CS2 but not in CS):
                                                                        if (app.selection.length >= 0) {
                                                                        
                                                                        var mySel = app.selection;
                                                                        app.select(null);
                                                                        }
                                                                        app.layoutWindows[0].zoom(ZoomOptions.fitPage);
                                                                        app.layoutWindows[0].zoomPercentage = 191;
                                                                        try {
                                                                        app.select(mySel);
                                                                        } catch (e) {};


                                                                        But in CS, you had to do something like this:
                                                                        if (app.selection.length >= 0) {
                                                                        
                                                                        var mySel = app.selection;
                                                                        app.select(null);
                                                                        }
                                                                        app.layoutWindows[0].zoom(ZoomOptions.fitPage);
                                                                        app.layoutWindows[0].zoomPercentage = 191;
                                                                        try {
                                                                        app.selection = makeArray(mySel);
                                                                        } catch (e) {};

                                                                        function makeArray(theSel) {
                                                                        var myArray = new Array();
                                                                        var theLim = theSel.length;
                                                                        for (j=0; theLim>j; j++) {
                                                                          myArray.push(theSel[j]);
                                                                        }
                                                                        return myArray
                                                                        }

                                                                        Dave
                                                                        • 33. Re: With CS2, some things have changed
                                                                          Community Member
                                                                          E Gunnar Liljas wrote: "Yikes, I was under the impression that there wouldn't be that many changes but there sure are. I've identified 3412 (!) differences so far, by comparing the scripting libs of CS and CS2 via reflection. This excludes all new types, such as ObjectStyle."

                                                                          Again, you can use script versioning to run CS (3.x) version scripts in CS2 (4.x)--see Olav Kvern, "InDesign CS2 Script Versioning" #7, 27 Apr 2005 12:25 pm

                                                                          Thanks,

                                                                          Ole
                                                                          • 34. Re: With CS2, some things have changed
                                                                            Community Member
                                                                            Unfortunately that is not an option when working from .NET
                                                                            • 35. Re: With CS2, some things have changed
                                                                              Community Member
                                                                              Hi E Gunnar Lijas--

                                                                              You should be able to use the CS (3.x) version of the scripting model with VB.NET, as described in the earlier post (publish the terms, then add the reference to your VB.NET project). If that doesn't work, you can alway send a string as VBScript and target the 3.x version of the model.

                                                                              Thanks,

                                                                              Ole
                                                                              • 36. Re: With CS2, some things have changed
                                                                                Community Member
                                                                                OK, that seems to work. However, there still exist a few changes, especially for the ChangePreferences and FindPreferences, where all properties are of type "object" now. They used to be strongly typed.

                                                                                Is this change done in order to make it possible to unset the properties of ChangePreferences and FindPreferences, by using null/Nothing, or it it something else?
                                                                                • 37. Re: With CS2, some things have changed
                                                                                  Community Member
                                                                                  Hi E Gunnar Liljas wrote: "Is this change done in order to make it possible to unset the properties of ChangePreferences and FindPreferences, by using null/Nothing"

                                                                                  Yes. (It was possible in CS, as well.)

                                                                                  Thanks,

                                                                                  Ole
                                                                                  • 38. Re: With CS2, some things have changed
                                                                                    Community Member
                                                                                    It was possible in weakly typed environments, but not in C# et. al.
                                                                                    • 39. Re: With CS2, some things have changed
                                                                                      Community Member
                                                                                      Version property

                                                                                      app.version is a string in CS2 but it is a number in CS, so while:
                                                                                      >if (app.version.split(".")[0] != 4)

                                                                                      works in CS2, it doesn't in CS.

                                                                                      What I've been using to distinguish CS2 from CS is:
                                                                                      >if (app.version != 3)

                                                                                      but if I want to also distinguish CS2 from some future CS3, I need to check for 4, so:
                                                                                      >if (String(app.version).split(".")[0] != 4)

                                                                                      seems to be needed.

                                                                                      Dave
                                                                                      1 2 Previous Next