15 Replies Latest reply on Jan 31, 2011 7:05 PM by YahyaCampbell

    [AS] Script Label Items in a Group

    wreyfmonkey Level 1

      Hi all,

       

      I have a group of shapes that, when grouped together in Indesign, form an object.  This grouped object is script labeled "special".  I am trying to script label each of the individual parts of this grouped object "special" so that if users ever mistakenly ungroup the object, I can still manipulate all items with the "special" label...which is effectively my original grouped object.

       

      The catch is that I need to do this labeling with a script because I have thousands and thousands of files I'm working with.  I'd love it if something like this worked (but it doesn't):

       

      tell application "Adobe InDesign CS3"

      set theObject to page item "special" of document 1

      set theShapes to every page item of all page items of theObject

      set label of theShapes to "special"

      end tell

       

      The problem I keep running into is that it seems when an object is grouped, all the objects inside that group become, for all practical purposes, invisible.  The line "set theshapes to every page item of all page items of theObject" returns an empty list "{ }" as though there ARE no items making up the group.

       

      So then I thought I'd take a more tactile approach.  Select it, ungroup it, label it, group it back:

       

      tell application "Adobe InDesign CS3"

      set theObject to page item "special" of document 1

      select theObject

      ungroup selection

      set label of selection to "special"

      group selection

      end tell

       

      The problem with this approach is that after ungrouping the object with a script, there is no longer a selection as there is when doing the same by hand, so trying to set the label of a selection that does not exist produces an error.  Grrrrr.

       

      Friends, I know this can be done, but I need a little outside perspective on this to help me figure this one out.  As always, thanks in advance for your help!

        • 1. Re: [AS] Script Label Items in a Group
          Eric @ MCA Level 3

          At least in CS3, group items are accessible via all page items. Like so:

           

          tell application "Adobe InDesign CS3"
               tell active document
                    repeat with thisItem in all page items of page item "group"
                         set label of thisItem to "groupie"
                    end repeat
               end tell
          end tell

           

          If you label your group item "group", after running this script you will see that all children of the group now have a label of "groupie".

           

          Is that useful?

           

           

          EDIT: There really is nothing as useless as the Jive Editor box is there?

          • 2. Re: [AS] Script Label Items in a Group
            wreyfmonkey Level 1

            Bingo!  That was it, Eric.  The syntax I kept missing was "...in all page items of page item...".  That does exactly what I wanted: it tells every item in a group to have a designated script label.  Well, done and thank you very much!

            • 3. Re: [AS] Script Label Items in a Group
              sstanleyau Level 4

              >set theShapes to every page item of all page items of theObject

              This is a very common mistake, but "all page items" returns a normal list, so you need to ask for "every item", not "every page item". So you could have used:
              set label of every item of all page items of page item "special" of document 1 to "special"

              --

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

              AppleScript Pro Sessions <http://scriptingmatters.com/aspro>

              1 person found this helpful
              • 4. Re: [AS] Script Label Items in a Group
                chris Harges

                I had thought that this thread would save me but I can't for the life of me figure out how to iterate through all the grouped items in a library item I've placed. Here's the section of the script:

                 

                tell application "Adobe InDesign CS4"

                     activate

                     set myDocument to active document

                     set myPage to page 2 of myDocument

                     set active page of layout window 1 to myPage

                     set assetPlacer to place asset asset "3_12:13" of library "Logowear_Lib.indl" on myDocument

                    move assetPlacer to myPage

                     tell myDocument

                          tell myPage

                               set label of (every item of all page items of page item assetPlacer whose label = "CW1") to "TEST!"

                          end tell

                     end tell

                end tell

                 

                The real deal is a little more complicated. I'm basically placing a library item that is a group of text frames and pre-labeled picture frames and then iterating through the picture frames in that group and giving them new labels. I have no trouble making this work with page items using something like the line below, but I can't seem to get at just the items in the group.

                 

                 

                set label of (object reference of every item of all page items of page pageNum of myDocument whose label = oldLabelName) to newLabelName

                • 5. Re: [AS] Script Label Items in a Group
                  sstanleyau Level 4

                  The "place asset" command returns a list, so try changing:

                   

                       set assetPlacer to place asset asset "3_12:13" of library"Logowear_Lib.indl" on myDocument

                  to:

                       set assetPlacer to item 1 of (place asset asset "3_12:13" of library"Logowear_Lib.indl" on myDocument)

                   

                  --

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

                  AppleScript Pro, April 2010, Florida <http://www.applescriptpro.com>

                  • 6. Re: [AS] Script Label Items in a Group
                    chris Harges Level 1

                    Interesting. Still can't make it work.

                     

                    If I don't specify the hierarchy, like so:

                     

                    tell application "Adobe InDesign CS4"

                    activate

                    set myDocument to active document

                    set myPage to page 2 of myDocument

                    set active page of layout window 1 to myPage

                    set assetPlacer to item 1 of (place asset asset "3_12:13" of library "Logowear_Lib.indl" on myDocument)

                    move assetPlacer to myPage

                    set label of (every item of all page items of page item assetPlacer whose label = "CW1") to "TEST!"

                    end tell

                     

                    I get:

                    Adobe InDesign CS4 got an error: Can’t set label of every item of all page items of page item (group id 7414 of page id 4537 of spread id 4538 of document "TNF_S11_Logowear_d1 copy.indd") whose label = "CW1" to "TEST!".

                     

                    If I do specify the item hierarchy like so:

                    tell application "Adobe InDesign CS4"

                    activate

                    set myDocument to active document

                    set myPage to page 2 of myDocument

                    set active page of layout window 1 to myPage

                    set assetPlacer to item 1 of (place asset asset "3_12:13" of library "Logowear_Lib.indl" on myDocument)

                    move assetPlacer to myPage

                    tell myPage

                    set label of (every item of all page items of page item assetPlacer whose label = "CW1") to "TEST!"

                    end tell

                    end tell

                     

                    I get:

                    Adobe InDesign CS4 got an error: Invalid parameter.

                     

                    In either case, whether I specify the library item as an item of a list or just with (set assetPlacer to place asset asset) there's no problem in moving it or to a different spot on the page. The good news is that identifying it as an item finally lets me get its properties. I couldn't figure out before why I could get its object reference but not its properties.

                    • 7. Re: [AS] Script Label Items in a Group
                      chris Harges Level 1

                      OK. Got it working but I'm not sure why. I went back to the bigger script of which the below is a part. And it works fine. I just don't understand why.

                       

                       

                      tell application "Adobe InDesign CS4"

                           activate

                           set myDocument to active document

                           set myPage to page pageNum of myDocument

                           set active page of layout window 1 to myPage

                           if not (exists library "Logowear_Lib.indl") then

                                set theFile to open tagsLib

                           end if

                           set assetPlacer to item 1 of (place asset asset "3_12:13" of library "Logowear_Lib.indl" on myDocument)

                           move assetPlacer to myPage

                           move assetPlacer to myCoordinates

                           set color_code_counter to 5

                           set color_box_counter to 1

                           tell myDocument

                                repeat color_counter times

                                     set theColorCode to item color_code_counter of Style_List

                                     set oldLabelName to ("CW" & color_box_counter)

                                     set newLabelName to my makeImageName(theSap, theColorCode)

                                     set label of (object reference of every item of all page items of page pageNum of myDocument whose label = oldLabelName) to newLabelName

                                     set color_code_counter to (color_code_counter + 2)

                                     set color_box_counter to (color_box_counter + 1)

                                end repeat

                           end tell

                      end tell

                      • 8. Re: [AS] Script Label Items in a Group
                        sstanleyau Level 4

                        This line:

                         

                        set label of (every item of all page items of page item assetPlacer whose label ="CW1") to "TEST!"

                        should be:

                        set label of (every item of all page items of assetPlacer whose label ="CW1") to "TEST!"

                        assetPlacer is already a page item reference.

                         

                        --

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

                        AppleScript Pro, April 2010, Florida <http://www.applescriptpro.com>

                        • 9. Re: [AS] Script Label Items in a Group
                          chris Harges Level 1

                          Hang on. I'm an idiot. The reason why it "worked" is that was referencing every page item ON THE PAGE. Not every page item in the placed library item. When I try to do the latter, I still get an invalid parameter error.

                          • 10. Re: [AS] Script Label Items in a Group
                            chris Harges Level 1

                            THAT'S IT!

                             

                            Thanks so much. I tried so many variations of: every page item, all page items, and page item, that it looks like I left an extra one in before the assetPlacer.

                             

                            Thanks again. I'm exhausted.

                            • 11. Re: [AS] Script Label Items in a Group
                              YahyaCampbell

                              I tried to use this example but am getting an error message that states:

                               

                              "Adobe InDesign CS5 got an error: asset "Generic asset" of library "Library.indl" of page id 186 of spread id 181 of document "Untitled-39" doesn’t understand the place asset message."

                               

                              Any help with this would be appreciated.

                              • 12. Re: [AS] Script Label Items in a Group
                                chris Harges Level 1

                                It's hard to tell without seeing your code but it sounds like InDesign either can't find the library item to place or you're not correctly identifying the spot where you'd like it to go.

                                 

                                If you're referencing the library item and the destination properly, it sounds like some syntax in referencing the newly placed item. That's were I was having trouble, especially referencing items within a group of placed library items.

                                 

                                Can you post your code?

                                • 13. Re: [AS] Script Label Items in a Group
                                  YahyaCampbell Level 1

                                  I realised after I posted that all I needed to do was add the following before the code:

                                   

                                  tell application "Adobe InDesign CS5"

                                   

                                  What does not make sense is this is within a previous statement "tell application "Adobe InDesign CS5""

                                   

                                  Here is the code that I am using:

                                   

                                  tell application "Adobe InDesign CS5"

                                   

                                  set myX to (myProductImageLeft + 40)

                                  set myY to (myProductImageTop)

                                  set assetPlacer to item 1 of (place asset asset (myTheme & myWeight) of library (myTheme & " Library.indl") on myDocument)

                                  move assetPlacer to {myX, myY}

                                  end tell

                                   

                                   

                                  I have a new problem that has come up that maybe you can resolve:

                                   

                                  tell myDocument

                                  set oldLabelName to ("copy")

                                  set newLabelName to (myCellID & "d1")

                                  set label of (object reference of every item of all page items of page 1 of myDocument whose label = oldLabelName) to newLabelName

                                  set thisFrame to (every text frame of every spread whose label is ((myCellID & "d1") as string))

                                  tell the active document

                                  set the contents of thisFrame to myCopy

                                  end tell

                                   

                                  When running this script I get an error message that says:

                                  Can’t set contents of {} to "My Sample Copy".

                                   

                                  Am trying to update content of a text frame that is in a group.

                                   

                                  • 14. Re: [AS] Script Label Items in a Group
                                    chris Harges Level 1

                                    I think the problem is that the label is a property of the item, not of its object reference.

                                     

                                    Instead of you line:

                                    set label of (object reference of every item of all page items of page 1 of myDocument whose label = oldLabelName) tonewLabelName

                                    Try this:

                                    set label of (every item of all page items of page 1 of myDocument whose label = oldLabelName) to newLabelName


                                    • 15. Re: [AS] Script Label Items in a Group
                                      YahyaCampbell Level 1

                                      set label of (object reference of every item of all page items of page 1 of myDocument whose label = oldLabelName) to newLabelName

                                       

                                      This does not appear to be the problem, as if I go and check the script label the name has changed to the new name. The problem comes in further with the error on the line that says.

                                       

                                      set the contents of thisFrame to myCopy

                                       

                                      am not sure if is the line that is now looking for the new label name in order to update content,

                                       

                                      set thisFrame to (every text frame of every spread whose label is ((myCellID & "d1") as string))

                                      or

                                      set thisFrame to (every text frame of every spread whose label is newLabelName)