-
1. Re: InDesign Script select Page and Layer
jugganaut Nov 23, 2014 5:18 AM (in response to romanobstuder)Have you created your layer?
I had this issue before and as long as there's nothing else on the layer, you could use:
var layerCount = myLayer.pageItems.length;
-
2. Re: InDesign Script select Page and Layer
Jump_Over Nov 23, 2014 7:44 AM (in response to romanobstuder)Hi,
...
I need to select all graphics on a page, but only on a given layer.
...
Since layer.parent is a document (not a page) ==> better way is to set a goal like:
"I need to select all graphics on a LAYER, but only on a given PAGE".
So iterate through thisLayer.allPageItems and check if its parentPage property is equal to thisPage.
Finally do some job with pageItems which passed this filter through.
Jarek
-
3. Re: InDesign Script select Page and Layer
romanobstuder Nov 23, 2014 1:44 PM (in response to Jump_Over)did a bit more coding
I now get all the graphics on a given page, then test every single graphic if it is on my specific layer.
I place all graphics with the correct condition in an array and pass the array on to the next function
Romano
//=============================================================\\
function myAddLabels(myDocument, myLabelType, myLabelHeight, myLabelOffset, myLabelStyleName, mySwatchName, myLayerName){
myStoriesArray = new Array();
if (app.selection.length == 0){ // If nothing is selected apply caption to all graphics in the document
var myConfirmation = confirm("Add captions to all images in the document?", false, "LabelGraphics.jsx" );
if (myConfirmation == true){
var myGraphics = myDocument.allGraphics;
}
}
else{ // If graphics are selected, just add captions to the selected items, as long as they are rectangles(image frames)
var myConfirmation = true;
var mySelections = app.selection;
myGraphics = new Array();
for(i = 0; i < mySelections.length; i++){
if(mySelections[i] == "[object Rectangle]"){ //Check to make sure selection only includes rectangles
myGraphics.push(mySelections[i].allGraphics[0]);
}
else{
//alert("Objects other than graphics were selected!");
//Nothing happens if you don't select at least one graphic
}
}
}
myLabelStyle = myDocument.paragraphStyles.item(myLabelStyleName);
mySwatch = myDocument.swatches.item(mySwatchName);
myLayer = myDocument.layers.item(myLayerName);
if (myConfirmation == true){
for(var myPageCounter = 0; myPageCounter < myDocument.pages.length; myPageCounter ++){
$.writeln("The current page counter = " + myPageCounter);
var myTest = myLayer.allGraphics.lenght;
$.writeln("myTest = " + myTest);
for(var myGraphicsCounterPerPage = 0; myGraphicsCounterPerPage < myDocument.pages[myPageCounter].allGraphics.length; myGraphicsCounterPerPage ++){
$.writeln("===============");
var myAllGraphics = myDocument.pages[myPageCounter].allGraphics;
var myAllGraphicsLength = myAllGraphics.length;
$.writeln("myAllGraphicsLength = " + myAllGraphicsLength);
myGraphics = new Array();
for(i = 0; i < myAllGraphics.length; i++){
if(myAllGraphics[i].itemLayer.name == myLayerName){ //Check to make sure selection only includes rectangles
myGraphics.push(myAllGraphics[i]);
}
else{
//alert("Objects other than graphics were selected!");
//Nothing happens if you don't select at least one graphic
}
}
}
var myLayersCounterPerPage = myDocument.layers.length;
var myGiveMeTheLayersName = myLayer.name;
$.writeln("myLayer = " + myLayer);
$.writeln("myLayerName = " + myLayerName);
$.writeln("myGiveMeTheLayersName = " + myGiveMeTheLayersName);
$.writeln("The current layers counter per page = " + myGraphicsCounterPerPage);
$.writeln("The current graphics counter per page = " + myLayersCounterPerPage);
for(var myGraphicsCounterPerPageA = 0; myGraphicsCounterPerPageA < myGraphics.length; myGraphicsCounterPerPageA ++){
myAddLabel(myDocument, myGraphics[myGraphicsCounterPerPageA], myGraphicsCounterPerPageA, myLabelType, myLabelHeight, myLabelOffset, myLabelStyle, mySwatch, myLayer, myStoriesArray);
}
}
}
}
//=============================================================\\

