6 Replies Latest reply on Jun 16, 2010 11:19 AM by JeffLambert

    Can't make label change work in CS5

    JeffLambert Level 1

      Ok, so I've read the what's change in CS5 thread about the page items, but I can't figure out how to make it work. I've been out of the loop for a while so bare with me:-)

       

      Here's the script:

      --Changes the Slug Number and date on the active spread

      tell application "Adobe InDesign CS5"

      --this line is to make it work on the active layer only

      set myLayer to active layer of layout window 1 of document 1

      set myPage to active spread of layout window 1 of document 1

      try

      set mySlugframe_list to (all page items whose label is "MySlugFrame") -- was   -> text frame "mySlugFrame" of myPage

      repeat with j from 1 to count of mySlugframe_list

      set mySlugframe to item j of mySlugframe_list

      try

      set mynumber to (((text of cells "6:2" thru "6:2" of table 1 of mySlugframe) as string) as number)

      set mynumberText to (mynumber + 1) as string

       

      --remove the if statement if you need it to be on all layers

      if mySlugframe's item layer = myLayer then

      set text of cells "6:2" thru "6:2" of table 1 of mySlugframe to mynumberText

      set text of cell id 16 of table 1 of mySlugframe to "2010-06-10" --handler not shown to put the actual date here

      end if

      end try

      end repeat

      end try

      end tell

      The part that doesn't work is the set mySlugframe line. Item 1 of all page items whose label is "MySlugFrame" gets me something, but I want a list so I can change different things in it. Ideally, I would convert the cells I want to address with labels so it would be easier, but now just making this work would be good.
      TIA
      Jeff

        • 1. Re: Can't make label change work in CS5
          sstanleyau Level 4

          Try:

           

          every item of all page items whose label is "MySlugFrame"

          • 2. Re: Can't make label change work in CS5
            JeffLambert Level 1

            Hi Shane,

             

            It doesn't work, I get en error message saying, Can't get every item of all page items whose label = "MySlugFrame"

             

            I've tried to remove "all" from the code to see if it would work but to no avail.

             

            I found the doc and the example script ScriptLabel, though, I'll have a look at it and try to figure it out. In the mean time, if you have a solution for me, please feel free to help:-)

             

            Jeff

            • 3. Re: Can't make label change work in CS5
              SuperMacGuy Level 2

              Hi Jeff,

              does your script have a "tell document 1" statement? You need that (maybe you omitted it for brevity).

              • 4. Re: Can't make label change work in CS5
                JeffLambert Level 1

                Hi Chris,

                 

                I'm still struggling with lists and how to use them properly. I've haven't touch scripting for a while and I'm just trying to migrate my CS4 script to CS5 but that change in page item structure messed up that script really bad. I found that I could do a if.. then statement like this...

                 

                if label of page item i of myPage is "MySlugFrame" then

                 

                but I can't get to my cell in my table after that. Conditional statements are another beast I have to master.

                 

                The thing is, once I identify MySlugFrame, all there is in the frame is a table, then some cells, of which, 2 of them have also labels I could point to. I just have no clue of how to do it. What worked before doesn't anymore, or have just been lucky all along;-)

                 

                Thanks.

                Jeff

                • 5. Re: Can't make label change work in CS5
                  sstanleyau Level 4

                  It was missing "of document 1".

                  • 6. Re: Can't make label change work in CS5
                    JeffLambert Level 1

                    ok, so I feel SOOOOO stupid right now... I was wondering where to put that "of document 1" and I finally found it. So for anybody interested, here's the script.

                     

                    set theDay to make_two_digit(day of (current date))

                    set theMonth to make_two_digit(month of (current date) as number)

                    set theYear to year of (current date)

                    set theDate to theYear & "-" & theMonth & "-" & theDay as string

                    global theDate

                    tell application "Adobe InDesign CS5"

                    --this line is to make it work on the active layer only

                    tell document 1

                    set myLayer to active layer of layout window 1

                    set myPage to active spread of layout window 1

                    --try

                    set mySlugframe_list to text frame 1 whose label is "MySlugFrame"

                    repeat with j from 1 to count of mySlugframe_list

                    set mySlugframe to item j of mySlugframe_list

                    try

                    set mynumber to (((text of cells "6:2" thru "6:2" of table 1 of mySlugframe) as string) as number)

                    set mynumberText to (mynumber + 1) as string

                     

                    --remove the if statement if you need it to be on all layers

                    if mySlugframe's item layer = myLayer then

                    set text of cells "6:2" thru "6:2" of table 1 of mySlugframe to mynumberText

                    set text of cell id 16 of table 1 of mySlugframe to theDate

                    end if

                    end try

                    end repeat

                    --end try

                    end tell

                    end tell

                     

                     

                    on make_two_digit(the_number)

                    if the_number is less than 10 then

                    set the_result to "0" & the_number as string

                    else

                    set the_result to the_number as string

                    end if

                    end make_two_digit

                     

                    I'm gonna try to make a call to the cell by label also, just to see if I can figure this one out:-)

                     

                    THANKS!!!

                    Jeff