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?
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?
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]);
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??
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]);
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
North America
Europe, Middle East and Africa
Asia Pacific