Copy link to clipboard
Copied
Hello,
I was wondering if there is a way to define a variable in ID CS 6, that displays the actual pagesize?
(I have one document with a lot of different pages and sizes.)
Any help is highly appreciated. Maybe a script will work?
Thx a lot
Ronald
Ther's no variable currently that can do that, so I've moved your question int the scripting forum to see if they have any ideas.
Copy link to clipboard
Copied
Ther's no variable currently that can do that, so I've moved your question int the scripting forum to see if they have any ideas.
Copy link to clipboard
Copied
So can someone help me out. What are the steps to get this page size script to work so to form as a text variable to add to to my other text variables. I ultimately want something like this to appear in my slug area of all my documents. I would love it to be able to pull information of the document size and apply it as a text variable so that I don't have to manually input the size for each job. I tried copying and pasting the information to form a new script but it wouldn't work. I don't have any real experience creating scripts in InDesign but honestly don't have the time to review the entire scripting tutuorials our their. Can anybody assist in either creating me a script or show me what I need to do to create and apply one to be a text variable. Thanks
Job: Example Indesign
Size: 8.5x11
Created: 02/12/15
Modified: March 2, 2015 8:34 AM
Output: 02/12/15
Page: 1
Copy link to clipboard
Copied
Hi,
you could work with a eventListener which fills predefined (labeled) textFrames with the pageSize.
For example "afterSave" or 'onIdle' ...
Hans-Gerd Claßen
Copy link to clipboard
Copied
var pages:Pages = app.activeDocument.pages;
for (var i = 0 ; i < pages.length ; i++) {
console.log("the width of page " + i + " is: " + (pages.bounds[3] - pages.bounds[1]));
console.log("the height of page " + i + " is: " + (pages.bounds[2] - pages.bounds[0]));
}
This should give you the width and height of the pages.
Copy link to clipboard
Copied
Hi,
You could try this:
myDoc = app.activeDocument;
myPages = myDoc.pages.everyItem().getElements();
mhV = myDoc.viewPreferences.horizontalMeasurementUnits;
mvV = myDoc.viewPreferences.verticalMeasurementUnits;
myDoc.viewPreferences.horizontalMeasurementUnits = myDoc.viewPreferences.verticalMeasurementUnits = MeasurementUnits.MILLIMETERS;
for (var k = 0; k < myPages.length; k++) {
resString = mySize(myPages
); resFrame = myFrame(myPages
); resFrame.contents = resString;
}
myDoc.viewPreferences.horizontalMeasurementUnits = mhV;
myDoc.viewPreferences.verticalMeasurementUnits = mvV;
function mySize (page) {
var Pbound = page.bounds;
var pH = Pbound[2] - Pbound[0];
var pW= Pbound[3] - Pbound[1];
var res = "H:\t" + (Math.round(pH*100)/100).toString() + " mm\nW:\t" + (Math.round(pW*100)/100).toString() + " mm";
return res;
}
function myFrame (page) {
var mF = page.textFrames.add();
var arrSize = [62,30];
mF.resize(
CoordinateSpaces.INNER_COORDINATES,
AnchorPoint.TOP_LEFT_ANCHOR,
ResizeMethods.REPLACING_CURRENT_DIMENSIONS_WITH,
arrSize
);
mF.texts[0].properties = {pointSize: 10, justification: Justification.LEFT_ALIGN};
mF.texts[0].tabStops.add({alignment: TabStopAlignment.RIGHT_ALIGN, position: 20});
return mF;
}
pages height and width should be shown in top left corner text frame;
enjoy
Copy link to clipboard
Copied
Ah, wonderful! Thank you very much. Thats it.
kind regards
ronald
Copy link to clipboard
Copied
Hi,
with admission of Jump_over (hope so 😉 ) and jusat to play around, a on idle event (or any other ...) could simulate the functionality of the textvariable.
Launched from startUp Scripts-Folder it'll now prompt for set or refresh the textframes ...
Delete it from StartUp-Scripts-Folder and restart ID to stopp the script working
#targetengine "session"
main();
function main()
{
var checkPageSize = app.idleTasks.add({name:"checkPageSize", sleep:50000});
checkPageSize.addEventListener(IdleEvent.ON_IDLE, onIdleCheckPageSize, false);
}
function onIdleCheckPageSize(myIdleEvent){
if(app.documents.length == 0){exit();};
if(!confirm('Add Textframes with Pagesize?')){exit();}
myDoc = app.activeDocument;
myPages = myDoc.pages.everyItem().getElements();
mhV = myDoc.viewPreferences.horizontalMeasurementUnits;
mvV = myDoc.viewPreferences.verticalMeasurementUnits;
myDoc.viewPreferences.horizontalMeasurementUnits = myDoc.viewPreferences.verticalMeasurementUnits = MeasurementUnits.MILLIMETERS;
for (var k = 0; k < myPages.length; k++) {
resString = mySize(myPages
); resFrame = myFrame(myPages
); resFrame.contents = resString;
}
myDoc.viewPreferences.horizontalMeasurementUnits = mhV;
myDoc.viewPreferences.verticalMeasurementUnits = mvV;
}
function mySize (page) {
var Pbound = page.bounds;
var pH = Pbound[2] - Pbound[0];
var pW= Pbound[3] - Pbound[1];
var res = "H:\t" + (Math.round(pH*100)/100).toString() + " mm\nW:\t" + (Math.round(pW*100)/100).toString() + " mm";
return res;
}
function myFrame (page) {
var myAllPageItems = page.allPageItems;
l = myAllPageItems.length;
check = true;
while(l--) {
if(myAllPageItems
.extractLabel('tfLabel') === 'pageSize'){ return myAllPageItems
; check = false;} }
if(check){
var mF = page.textFrames.add();
var arrSize = [62,30];
mF.resize(
CoordinateSpaces.INNER_COORDINATES,
AnchorPoint.TOP_LEFT_ANCHOR,
ResizeMethods.REPLACING_CURRENT_DIMENSIONS_WITH,
arrSize
);
mF.texts[0].properties = {pointSize: 10, justification: Justification.LEFT_ALIGN};
mF.texts[0].tabStops.add({alignment: TabStopAlignment.RIGHT_ALIGN, position: 20});
mF.insertLabel('tfLabel', 'pageSize')
return mF;
}
}
Hans-Gerd Claßen
Copy link to clipboard
Copied
Can i get this script filling out a predefined textbox, using a tag och a script tag on the textbox?
Copy link to clipboard
Copied
Hi,
Only question is which way you predefine a textFrame.
I.e. by applying a specific name (let say "mFrame" using Levels Panel) ==> only change is this line:
var mF = page.textFrames.item("mFrame");
a few next lines with resize and formats look like unnecessary as well
Jarek
Copy link to clipboard
Copied
myDoc = app.activeDocument;
myPages = myDoc.pages.everyItem().getElements();
mhV = myDoc.viewPreferences.horizontalMeasurementUnits;
mvV = myDoc.viewPreferences.verticalMeasurementUnits;
myDoc.viewPreferences.horizontalMeasurementUnits = myDoc.viewPreferences.verticalMeasurementUnits = MeasurementUnits.MILLIMETERS;
for (var k = 0; k < myPages.length; k++) {
resString = mySize(myPages
); resFrame = myFrame(myPages
); resFrame.contents = resString;
}
myDoc.viewPreferences.horizontalMeasurementUnits = mhV;
myDoc.viewPreferences.verticalMeasurementUnits = mvV;
function mySize (page) {
var Pbound = page.bounds;
var pH = Pbound[2] - Pbound[0];
var pW= Pbound[3] - Pbound[1];
var res = "H:\t" + (Math.round(pH*100)/100).toString() + " mm\nW:\t" + (Math.round(pW*100)/100).toString() + " mm";
return res;
}
function myFrame (page) {
var mF = page.textFrames.item("pagesize");
var arrSize = [62,30];
/*
mF.resize(
CoordinateSpaces.INNER_COORDINATES,
AnchorPoint.TOP_LEFT_ANCHOR,
ResizeMethods.REPLACING_CURRENT_DIMENSIONS_WITH,
arrSize
);
mF.texts[0].properties = {pointSize: 10, justification: Justification.LEFT_ALIGN};
mF.texts[0].tabStops.add({alignment: TabStopAlignment.RIGHT_ALIGN, position: 20});
*/
return mF;
}
Okey, i've tried this but get an error from InDesign "Object not valid", Source: resFrame.contents = resString;
Any clues?
Thanks.
Copy link to clipboard
Copied
@Henrik – I did not test it, but you could try the following in your myFrame(page) function:
var mF = page.textFrames.itemByName("pagesize");
Or is this text frame anchored or otherwise nested into other objects?
Uwe
Copy link to clipboard
Copied
Nope, no improvments. Still "Object not valid".
It's not anchored or nested.
I've uploaded my indd here:
http://www.rekylx.se/henrik/InDesign/Check.indd
It's the textframe under "Print size" i'm trying to get automated with pagesize.
Copy link to clipboard
Copied
Hi Henrik,
Are you sure each page in your doc has textFrame named "pagesize"?
No more check needed than look at Level's Panel to ensure that.
Jarek
PS. Your .indd would be more accessible if exported to .idml (version conflict)
Copy link to clipboard
Copied
Hi!
Can't find ant panel named Level's.
Figure it have be renamed in my swedish version of ID.
I've one called Structure, in which i have a textFrame named pagesize under Root.
IDML version:
www.rekylx.se/henrik/InDesign/Check.idml
Message was edited by: Henrik Lideberg (Added screen shot)
Copy link to clipboard
Copied
@Henrik – it's the Layers Panel where you can name or rename objects on the page.
From my German InDesign CS5.5 😉 :
1. Unnamed empty text frame (generic name of object TextFrame in localized version = "<Textrahmen>") selected and visible in Layers Panel.
Value of name property is empty: ""
2. Unnamed NOT EMPTY text frame (generic name changed to some of the contents)
Value of name property is still empty: ""
3. Renaming process in the Layers Panel:
4. Renamed text frame.
Value of name property is "pagesize".
Don't do it the UI way, just select the text frame and execute this line of code:
app.selection[0].name = "pagsize";
Uwe
Copy link to clipboard
Copied
Hi,
I mean the panel with keyboard shortcut F7 (Layer Panel, I wrote wrong name, sorry).
You use "pagesize" as textFrame script label. Script is expecting a textFrame name.
Currently your textFrame has no name. Double click it in Layer Panel and type the name.
Jarek
Copy link to clipboard
Copied
Hi @Jump_Over and @Laubender!
When labeling it through the Layers Panel, it works like a charm.
Thanks a lot!
BR
Henrik