Skip navigation
Currently Being Moderated

With CS5, some things have changed

Oct 3, 2010 1:50 AM

This discussion is for changes to the scripting DOM which can affect legacy scripts.

 

Please use this discussion for discussing new scripting features in CS5.

 

Please keep in mind that all changes are specific to version 7 DOM. InDesign supports versioning, so you should be able to use legacy scripts in CS5 without issues. Versioning can be done in two ways:

 

1) Place the script in a folder named: "Version 6.0 Scripts" (or 5.0, 4.0, 3.0). The folder must be named exactly as specified.

2) Set the script version preferences at the start of your script. (i.e. app.scriptPreferences.version = 6), but it's highly recommended to reset the scripting version at the end of the script, and even to enclose the script in a try/catch/finally block to ensure that the script preferences are reset correctly.

 

Here's quick links to issues brought up in this thread:

  1. PageItem.parent
  2. PageItem.itemByName()
  3. PageItem.cornerOption and PageItem.cornerRadius
  4. Text values returned as Strings instead of Numbers
  5. PointType.LINE_TYPE was changed to PointType.PLAIN
  6. PasteBoardPreference.minimumSpaceAboveAndBelow was removed.

Harbs

Branched to a new discussion.
 
Replies 1 2 3 Previous Next
  • Currently Being Moderated
    Apr 12, 2010 10:40 AM   in reply to Harbs.

    2) PageItems.itemByName(): With the new layers panel comes a name property for PageItems. In previous versions PageItems.itemByName() would return the page item with the specified label in CS5, it will return the page item with the specified name (which can be set in the Layers Panel). There is no longer a quick-and-easy way to get page items by their label using the 7.0 scripting DOM.

    Does this affect only JS scripts, or all scripting? I do Applescripting and we have A LOT of workflow that depends on item labels. Will this change for Applescripting?

     

    Chris

     
    |
    Mark as:
  • Currently Being Moderated
    May 6, 2010 7:16 AM   in reply to Harbs.

    I'm not so sure that the .parentPage property does away with the need for findPage. I was just working on it right now and came to the conclusion that for a general function, it just changes it a bit:

     

    function findPage(theObj) {
         if (theObj.hasOwnProperty("baseline")) {
              theObj = theObj.parentTextFrames[0];
         }
         while (theObj != null) {
              if (theObj.hasOwnProperty ("parentPage")) return theObj.parentPage;
              var whatIsIt = theObj.constructor;
              switch (whatIsIt) {
                   case Page : return theObj;
                   case Character : theObj = theObj.parentTextFrames[0]; break;
                   case Footnote :; // drop through
                   case Cell : theObj = theObj.insertionPoints[0].parentTextFrames[0]; break;
                   case Note : theObj = theObj.storyOffset; break;
                   case Application : return null;
              }
              if (theObj == null) return null;
              theObj = theObj.parent;
         }
         return theObj
    } // end findPage
    

     

    I believe that this function will work with any version of InDesign because it will behave the same as before in versions that don't support the parentPage property.

     

    Of course, if you know you're dealing with an object that has a parentPage property in CS5, you can just go straight for the property.

     

    Dave

     
    |
    Mark as:
  • Currently Being Moderated
    May 6, 2010 7:19 AM   in reply to SuperMacGuy

    Chris,

     

    I expect that AppleScript users can still take advantage of whose clauses to get at the label (provided they can master the syntax).

     

    In JavaScript, the news is worse than I feared because you can't even use versioning to get around this. All scripts that use item("label") to get at stuff will have to be rewritten.

     

    Dave

     
    |
    Mark as:
  • Currently Being Moderated
    May 6, 2010 7:31 AM   in reply to Dave Saunders

    I believe that this function will work with any version of InDesign because it will behave the same as before in versions that don't support the parentPage property.

     

    I think it won't because of this line:

                   case Character : theObj = theObj.parentTextFrames[0]; break;

     

    In CS1 it's ParentTextFrame - one item - not array/collection.

     

    robin

    www.adobescripts.co.uk

     
    |
    Mark as:
  • Currently Being Moderated
    May 6, 2010 4:14 PM   in reply to SuperMacGuy

    > Will this change for Applescripting?

     

    Yes. To refer by item, you should use something like:

     

    item 1 of all page items whose label is "whatever"

     

    A lot of people have been using this sort of construction anyway, to deal with the possibility of grouping, so they should be largely unaffected.

     

    The other thing to keep in mind is that versioning solves the problem for AppleScript.

     

     

    --

    Shane Stanley <sstanley@myriad-com.com.au>

     
    |
    Mark as:
  • Currently Being Moderated
    May 6, 2010 4:09 PM   in reply to Dave Saunders

    Dave,

     

    Aren't you ignoring items on the pasteboard there?

     

    --

    Shane Stanley <sstanley@myriad-com.com.au>

     

     
    |
    Mark as:
  • Currently Being Moderated
    May 7, 2010 6:09 AM   in reply to Shane Stanley

    Shane,

     

    In the function? Yes -- by definition, they're not on a page. So, they'll return null.

     

    Dave

     
    |
    Mark as:
  • Currently Being Moderated
    May 7, 2010 6:47 AM   in reply to Harbs.

    Harbs,

     

    I think I must be wrong about this because to my immense surprise your code works -- my surprise is caused by the certainty that that's just what I tried when I concluded it didn't work. I just did this:

     

    1. I created a new document in CS5.

    2. I dragged out a text frame and labeled it "Fred".

    3. I duped that twice.

    4. I ran this script:

     

    var myDoc = app.documents[0];
    var myTFs = myDoc.textFrames.item("Fred");
    alert(myTFs == null);
    app.scriptPreferences.version = "6.0"
    var myTFs = myDoc.textFrames.item("Fred").getElements();
    app.scriptPreferences.version = "7.0"
    alert(myTFs.length);
    

     

    There's a caveat here. The end result is an array and not a collection. But presumably the getElements() part is optional. Let me try another experiment. Aha! No it's not optional. This might well explain my confusion. This works:

     

    var myDoc = app.documents[0];
    app.scriptPreferences.version = "6.0"
    var myTFs = myDoc.textFrames.item("Fred");
    alert(myTFs.toSource());
    app.scriptPreferences.version = "7.0";
    

     

    But this doesn't:

     

    var myDoc = app.documents[0];
    app.scriptPreferences.version = "6.0"
    var myTFs = myDoc.textFrames.item("Fred");
    app.scriptPreferences.version = "7.0";
    alert(myTFs.toSource());
    

     

    So, if you create an object reference while working within the CS4 versioning engine it won't work when you move back into the CS5 engine. So, by converting to an array--by using getElements()--which is a core feature, you can pass objects effectively from one engine to the other.

     

    So, if you were converting your collection to an array anyway, then this makes converting the script a whole lot easier than I had feared. On the other hand, if you were using the reference as a collection, then you need to stay within the CS4 versioning engine for it to work. I wonder if you can move in and out of versions ... Yes!

     

    var myDoc = app.documents[0];
    app.scriptPreferences.version = "6.0"
    var myTFs = myDoc.textFrames.item("Fred");
    app.scriptPreferences.version = "7.0";
    // some code so that something happens while we're in this engine
    for (var j = 0; myDoc.textFrames.length > j; j++) {
         myDoc.textFrames[j].fillColor = myDoc.swatches[-1];
    }
    app.scriptPreferences.version = "6.0"
    alert(myTFs.toSource());
    app.scriptPreferences.version = "7.0";
    

     

    Well, this isn't as bad as I feared, but I can see me having to add a lot of versioning statements to scripts I convert from CS4 to CS5

     

    Thanks for pointing me in the right direction Harbs.

     

    Dave

     
    |
    Mark as:
  • Currently Being Moderated
    May 9, 2010 12:41 PM   in reply to Harbs.

    I am not a great scripting hero but i just have one question.

     

    I have a Indesign file wich has a bunch of pages.

    On each page there is a textframe wich is labelled "textcode".

    When i run the script, Indesign exports each page to a pdf giving the name what's in the labelled textframe.

     

     

    The problem is, i think, the line:

    f = File (myFolder + "/" + p[i].textFrames.item ('textcode').contents + ".pdf");

    Wich contains textFrames.item.

     

    Does anybody knows what i have to change to let it work in CS5?

     

     

    Already thanks for everyone who wants to help,

     

    Regards,

     

    Bert

    Holland

     

     

     

    Update: Sorry guys, wasn't reading good. So the problem is solved!

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 3, 2010 2:11 AM   in reply to Harbs.

    Footnote will allow the xml tags in CS5?

     

     

    Arivu..

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 3, 2010 2:25 AM   in reply to sudar1983_14

    No. I don't think so.

     

    One of the pain area for XML works in ID.

     

     

     

     

    sudar1983_14 <forums@adobe.com>

    07/03/10 02:41 PM

    Please respond to

    clearspace-721659546-639966-2-2945664@mail.forums.adobe.com

     

     

    To

    Pankaj Chaturvedi <pankaj.c@thomsondigital.com>

    cc

     

    Subject

    Re: With CS5, some things have changed Re: With CS5, some things have changed

     

     

     

     

     

     

     

    Footnote will allow the xml tags in CS5?

     

     

    Arivu..

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 4, 2010 9:47 PM   in reply to PankChat

    Tagging of Footnote Text is not supported in InDesign CS5. Please find below the screen shot for the same.

     

    Screen shot 2010-07-05 at 10.12.09 AM.png

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 27, 2010 12:59 AM   in reply to Dave Saunders

    Hey Dave,

     

    you forgot to handle placed XML Elements in your findPage function and made a mistake about the Cell case.

     

    With a selected Cell your switch statement selected the parentTextFrame and breaked the switch. After the break it would run into line

              theObj = theObj.parent;

    The parent of pageItem gives you the Spread in InDesign CS5. I've found it wondering why my xml additon does not worked.

     

    I hope i've not introduced new Bugs

     

    function findPage(theObj) {
         if (theObj.hasOwnProperty("baseline")) {
              theObj = theObj.parentTextFrames[0];
         }
         while (theObj != null) {
              if (theObj.hasOwnProperty ("parentPage")) return  theObj.parentPage;
              var whatIsIt = theObj.constructor;
              switch (whatIsIt) {
                   case Page : return theObj;
                   case Character : theObj = theObj.parentTextFrames[0]; break;
                   case Footnote :; // drop through
                   case Cell : theObj = theObj.insertionPoints[0].parentTextFrames[0]; break;
                   case Note : theObj = theObj.storyOffset.parentTextFrames[0]; break;
                   case XMLElement :  if (theObj.insertionPoints[0] != null) { theObj =  theObj.insertionPoints[0].parentTextFrames[0]; break; }
                   case Application : return null;
                   default: theObj = theObj.parent;
              }
              if (theObj == null) return null;
         }
         return theObj
    } // end findPage
     
     
     
     
    

     

     

    regards,

    gregor

     

    UPDATE: made an addition to the Note case  ...

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 21, 2010 8:35 PM   in reply to Harbs.

    I think it's worth noting doc.pages[x]textFrames.item("Label") still works. It's only if you try to get the item from the document object where it doesn't work anymore.

     
    |
    Mark as:
  • Currently Being Moderated
    Oct 14, 2010 10:45 AM   in reply to Harbs.

    I am using a javascript to export a pdf with settings. The script works fine in CS3 and CS4, but not CS5. I get an error from the following line of code for PDF preferences. I am exporting the PDF with OPI. What is the new syntax in CS5 for this setting?

     

    contentToEmbed = PDFContentToEmbed.linkAll;

     
    |
    Mark as:
  • Currently Being Moderated
    Oct 14, 2010 12:01 PM   in reply to GbHerff

    Jongware's CS3 Help document lists the proper form for that command as PDFContentToEmbed.LINK_ALL. Have you tried that.

     

    edit:  Looking at the similar Help files for CS5, this property seems to no longer be supported.

     
    |
    Mark as:
  • Currently Being Moderated
    Oct 15, 2010 7:09 AM   in reply to Larry G. Schneider

    That didn't work. There has to be some javascript command to do this. It is still available in the PDF settings.

     
    |
    Mark as:
  • Currently Being Moderated
    Oct 15, 2010 7:23 AM   in reply to Harbs.

    The error is PDFContentToEmbed is undefined. I don't know of any numeric value. This command tells InDesign to create OPI in the PDF for linked images.

     
    |
    Mark as:
  • Currently Being Moderated
    Oct 15, 2010 8:18 AM   in reply to Harbs.

    The property itself is removed. I scanned the export settings by eye, then used a full text search, but couldn't locate something similar-with-a-slightly-different-name.

     
    |
    Mark as:
  • Currently Being Moderated
    Oct 15, 2010 9:40 AM   in reply to GbHerff

    I figured it out. I found the answer in Jongwares ID CS5 scripting help files. That command has been substituted with the omitBitmap, OmitEPS to look more like the PDF Export setting.

     
    |
    Mark as:
  • Currently Being Moderated
    Oct 28, 2010 1:54 AM   in reply to Harbs.

    Hi everybody,

     

    I'm a vb script developer and I use to access TextFrames with labels, for instance :

     

    set oFrame = myPage.TextFrames.item("bText")

     

    it seems this method no longer exist in CS5... is it a bug ?

     

    Thanks in advance for your answers,

     

    Philippe

     
    |
    Mark as:
  • Currently Being Moderated
    Oct 28, 2010 2:09 AM   in reply to KreunKormann

    This is dealt with earlier in this same thread.

     

    Peter

     
    |
    Mark as:
  • Currently Being Moderated
    Oct 28, 2010 3:03 AM   in reply to Peter Kahrel

    Thanks Peter,

     

    so here is the "traduction" of the code in VB to access a TextFrame with the label :

     

    Public Sub GetItemFromCollection(ByVal label As String, ByRef collection As InDesign.TextFrames, ByRef oTextFrame As InDesign.TextFrame)
         scriptVersion = oInd.ScriptPreferences.Version
         If scriptVersion > 6 Then oInd.ScriptPreferences.Version = 6
         Set oTextFrame = collection.Item(label)
         oInd.ScriptPreferences.Version = scriptVersion
    End Sub

     

    and to call it :

     

    Call GetItemFromCollection("bTexte", oPage.TextFrames, oTexteFrame)

     

    but it was easier before...

     

    Philippe

     
    |
    Mark as:
  • Currently Being Moderated
    Oct 28, 2010 3:08 AM   in reply to Harbs.

    I cant my progress bar working in CS5, it works if i dont trigger it from the menu.

     

    Does anyone have a working script like this?

     

    Here is the script that i made that adds a menu and when you fire the submenu a progress bar should start working in a window, but nothing is happening except when i add an alert, then it fires.

     

    #targetengine "session"
     
    // Create menu item
    var test_menu = app.menus.item('$ID/Main').submenus.add('Test menu');
     
    // Create sub menu action
    var test_sub_menu = app.scriptMenuActions.add('Run progressbar');
     
    // Set on invoke action
    test_sub_menu.eventListeners.add('onInvoke', function() {
         // Create a simple window
         var win = new Window(
              "window { \
                   progressbar: Progressbar { size: [400, 10] } \
              }"
         );
     
         // Center and show the window
         win.center();
         win.show();
         
         // Set max value for the progressbar
         win.progressbar.maxvalue = 5;
         
         // Make a simple loop from 0 to 4
         for(var i = 0; i < 5; i++) {
              // This should happen every second
              win.progressbar.value = i;
              
              // Sleep for a second
              $.sleep(1000);
         }
         
         // Remove the test menus actions
         app.scriptMenuActions.item('Run progressbar').remove();
         
         // Remove the test menu
         app.menus.item('$ID/Main').submenus.item('Test menu').remove();
    });
     
    // Add the sub menu action
    test_menu.menuItems.add(test_sub_menu);
    

     
    |
    Mark as:
  • Currently Being Moderated
    Jan 17, 2011 2:56 AM   in reply to Harbs.

    I just found a difference in the results from allPageItems, in CS5, which I have to code some kind of exception / condition for, in my scripts before upgrading them to CS5:

     

    allPageItems now includes "contained" objects (images and other linked objects, that reside inside rectangles and such) in CS5.

     

    As a simple test, placing an EPS on an empty page in a new document, I run the following code in CS4 and CS5 respectively:

     

    CS5:
    app.activeDocument.pages[0].allPageItems
    Result: [object Rectangle],[object EPS]

     

    CS4:
    app.activeDocument.pages[0].allPageItems
    Result: [object Rectangle]

     

    As you can see, we get the container rectangle only, in CS4, while CS5 is returning the object contained as well.

     

    In a larger result set I get the following objects included in the allPageItems in CS5 (not present in the same call in CS4):

    [object Image]
    [object EPS]
    [object Polygon]
    [object PDF]

     

    -- Andreas

     
    |
    Mark as:
  • Currently Being Moderated
    Jan 17, 2011 3:51 AM   in reply to Andreas Jansson

    In a larger result set I get the following objects included in the allPageItems in CS5 (not present in the same call in CS4):

    [object Image]

    [object EPS]

    [object Polygon]

    [object PDF]

     

    New "feature", ehh ...

     

    But this time - one thing could be good:

     

    ...

    [container]

    [content]

    ...

     

    I think it could be usefull ... there is no way for [content] to be without preceding [container] ...

     

    robin

    www.adobescripts.co.uk

     
    |
    Mark as:
  • Currently Being Moderated
    Jan 25, 2011 8:10 PM   in reply to SuperMacGuy

    I know this is an ancient post but just wondering if you got an answer on how to talk to boxs that have labels in CS5 I am just returning to the workforce and the last scripts I worked on were CS2 and my new company uses CS5. I'll repost my question below if you have any insights that would be great since we seem to have been in the same boat!

     

    I wrote an Applescript at home on my laptop where I only have Adobe CS2 and want to use the same thing at work to show my boss what is possible with Applescript and it is failing at work cause we have Adobe CS5. Specifically placing a picture in InDesign.

    This works in CS2 where I am talking to a named picture box

     

    set picToPlace to "ARTWORK:Close Ups:05-02-04:CUA2222.tif" as alias

    tell application "Adobe InDesign CS2"

    activate

    tell document 1

    place picToPlace on rectangle "photo1"

    fit rectangle "photo1" given proportionally

    end tell

    end tell

     

    But at work when it gets to the {place picToPlace on rectangle "photo1"} line it stops and says something about "cannot get alias" (and gives the whole path to the file I am trying to place.)

     

    Have they changed the wording for placing a pic in a rectangle? in CS5?

     
    |
    Mark as:
1 2 3 Previous Next
Actions

More Like This

  • Retrieving data ...

Bookmarked By (1)