15 Replies Latest reply: Sep 23, 2012 8:45 AM by caseyctg RSS

    Looking to do something like this...

    caseyctg Community Member

      newDoc.layers.item("GraphBars").pageItems.everyItem().move([ x,y ]);

       

       

      Basically what I am trying to do is grab everything from a layer and move it using x,y coordinates. This doesn't seem to be working... am I missing something?

        • 1. Re: Looking to do something like this...
          pkahrel CommunityMVP

          Works fine here (in CS6). Are you targetting the correct layer? Are there any page items on that layer? If there are, are they unlocked?

           

          Peter

          • 2. Re: Looking to do something like this...
            caseyctg Community Member

            Hi Peter, sorry you are correct, this does work, however I wasn't specific enough in my problem.

             

            I am trying to group all items on that layer and then move the group.

             

            var myGraphBarItems = newDoc.layers.item("GraphBars").pageItems.everyItem();

             

            var myGroup = newDoc.groups.add(myGraphBarItems);

             

            myGroup.move([x,y]);

             

            This didn't work however.

             

            also tried

             

            myArray =[];

            myArray.push(myGraphBarItems);

            var myGroup = newDoc.groups.add(myArray);

            myGroup.move([x,y]);

             

             

            but I receive an error, invalid parameter...

             

            expecting an array but received "((rectangle, rectangle, TextFrame))"

             

            Is this because I am pushing an array of items into an array? Should I be looping through each item and pushing them individually or something?

             


             


            • 3. Re: Looking to do something like this...
              Laubender CommunityMVP

              This cannot work in a document with more than one spread, because a Group object cannot transcend spread boundaries. If you want to group items by layers, you have to do it spread by spread.


              And for that you first have to sort out which item belongs to what layer (spread by spread).

               

              Uwe

              • 4. Re: Looking to do something like this...
                caseyctg Community Member

                I also tried doing this per page though with the same result.

                 

                this is in a for loop, so "i" is a page variable.

                 

                var myGraphBarItems = newDoc.layers.item("GraphBars").pageItems.everyItem();

                myArray =[];

                myArray.push(myGraphBarItems);

                var myGroup = newDoc.pageItems.item(i).groups.add(myArray);

                myGroup.move([x,y]);

                • 5. Re: Looking to do something like this...
                  Laubender CommunityMVP

                  But "myGraphBarItems" are page items throughout the **whole** document.

                   

                  Uwe

                  • 6. Re: Looking to do something like this...
                    caseyctg Community Member

                    Ok, I see what you're saying now.

                     

                    Is there some kind of equivalent such as:

                     

                    var myGraphBarItems = newDoc.pageItems.item(i).layers.item("GraphBars").pageItems.everyItem();

                    • 7. Re: Looking to do something like this...
                      pkahrel CommunityMVP

                      No, there isn't. As Uwe mentioned, you have to work page by page, and on each page, layer by layer.

                       

                      Peter

                      • 8. Re: Looking to do something like this...
                        caseyctg Community Member

                        I guess my next question would be how do you reference layers on pages by name, as opposed to layers within a document by name? 

                         

                        I've created a script that automates bar graphs from .csv merged text frames. So it grabs the values and creates a bar graph based on the values and maximum number. The problem is that I now need to move the whole graphs and not the individual pieces. If I understand you guys correctly, I need to code in a different way.

                         

                        My thought was that when I place these items I place them on a specific layer so that only the graph items are on that layer. I thought I could then take that layer, group the items and then move the group to an x, y coordinate.

                         

                        Would I be better off scraping the page for page items and then check to see if they are on that layer, and if they are then group them?

                         

                        I don't know if my logic is flawed, or if there is an easier way to do it??

                        • 9. Re: Looking to do something like this...
                          pkahrel CommunityMVP

                          Layers aren't connected to pages. You look for page items on certain layers on certain pages.

                           

                          > Would I be better off scraping the page for page items and then check to see if they are on that layer, and if they are then group them?

                           

                          This is the way to go.

                           

                          Peter

                          • 10. Re: Looking to do something like this...
                            caseyctg Community Member

                            I don't have the files here with me, but I'm thinking something like this might work...thoughts?

                             

                            myArray = [];

                            for (var k=0;k<= newDoc.pages.item(i).pageItems.length; k++){

                             

                            if(newDoc.pages.item(i).pageItems.item(k).itemLayer == "GraphBars"){

                             

                            myArray.push(newDoc.pages.item(i).pageItems.item(k) );

                            }

                             

                            }

                             

                            var myGroup = newDoc.pageItems.item(i).groups.add(myArray);

                            myGroup.move([x,y]);


                            • 11. Re: Looking to do something like this...
                              caseyctg Community Member

                              BTW, thank you both for your help so far.

                              • 12. Re: Looking to do something like this...
                                -hans- Community Member

                                Hi,

                                 

                                you may  use your array from the start, may be faster as ... ¿:

                                 

                                 

                                var theDoc = app.activeDocument;
                                var getGraphs = theDoc.layers.item('Ebene 1').pageItems.everyItem().getElements();
                                
                                var pageItemsAndParentPages = [];
                                
                                l = getGraphs.length;
                                
                                while(l--){
                                    tmp = [];
                                    tmp.push(getGraphs[l], getGraphs[l].parentPage.documentOffset);
                                    pageItemsAndParentPages.push(tmp)
                                    }
                                
                                 pageItemsAndParentPages.sort(function(a, b){return a[1] -  b[1]})
                                
                                 l = pageItemsAndParentPages.length;
                                      tmp = [];
                                 for(var i = 0; i < l; i++){
                                    theItem = pageItemsAndParentPages[i];
                                    if(i === l-1){tmp.push(theItem[0]);       theDoc.groups.add(tmp).move([0,0]); continue}
                                   if(theItem[1] === pageItemsAndParentPages[i+1][1]){
                                       tmp.push(theItem[0]);
                                       }else{
                                                  tmp.push(theItem[0]);
                                      theDoc.groups.add(tmp).move([0,0]);
                                            tmp = [];
                                }
                                        }
                                

                                Hope it'll work

                                 

                                Hans-Gerd Claßen

                                • 13. Re: Looking to do something like this...
                                  pkahrel CommunityMVP

                                  caseyctg: Any luck with your latest approach? It looks good to me.

                                   

                                  Peter

                                  • 14. Re: Looking to do something like this...
                                    caseyctg Community Member

                                    I'll be working with the script this weekend and will give it a go. Thanks all. I'll let you know how it works out. I appreciate the guidance. 

                                    • 15. Re: Looking to do something like this...
                                      caseyctg Community Member

                                      This worked perfect, thank you guys.