• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Looking to do something like this...

Community Beginner ,
Sep 19, 2012 Sep 19, 2012

Copy link to clipboard

Copied

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?

TOPICS
Scripting

Views

2.0K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Enthusiast , Sep 20, 2012 Sep 20, 2012

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, getGraphs.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;

...

Votes

Translate

Translate
Community Expert ,
Sep 19, 2012 Sep 19, 2012

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Sep 20, 2012 Sep 20, 2012

Copy link to clipboard

Copied

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?



Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 20, 2012 Sep 20, 2012

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Sep 20, 2012 Sep 20, 2012

Copy link to clipboard

Copied

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]);

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 20, 2012 Sep 20, 2012

Copy link to clipboard

Copied

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

Uwe

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Sep 20, 2012 Sep 20, 2012

Copy link to clipboard

Copied

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();

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 20, 2012 Sep 20, 2012

Copy link to clipboard

Copied

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

Peter

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Sep 20, 2012 Sep 20, 2012

Copy link to clipboard

Copied

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??

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 20, 2012 Sep 20, 2012

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Sep 20, 2012 Sep 20, 2012

Copy link to clipboard

Copied

BTW, thank you both for your help so far.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Sep 20, 2012 Sep 20, 2012

Copy link to clipboard

Copied

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, getGraphs.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;

    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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Sep 23, 2012 Sep 23, 2012

Copy link to clipboard

Copied

LATEST

This worked perfect, thank you guys.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Sep 20, 2012 Sep 20, 2012

Copy link to clipboard

Copied

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]);


Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 21, 2012 Sep 21, 2012

Copy link to clipboard

Copied

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

Peter

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Sep 21, 2012 Sep 21, 2012

Copy link to clipboard

Copied

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. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines