-
Notifications
You must be signed in to change notification settings - Fork 6
Delay And View
fabiantheblind edited this page Oct 26, 2012
·
4 revisions
/*
This script shows some user interaction
It has a delay function and rsets the view prefs
*/
main();
function main (){
// create a doc
var doc = app.documents.add({
documentPreferences:{
pageHeight:200,
pageWidth:200
}
});
var page = doc.pages.item(0); // get the first page
app.activeWindow.activePage = page; // set the active page
app.activeWindow.zoomPercentage = 100; // set the zoom
app.activeWindow.zoom(ZoomOptions.FIT_PAGE);// fit the page
// now lets switch into presentation mode
app.activeWindow.screenMode = ScreenModeOptions.PRESENTATION_PREVIEW;
delay(5); // this is the delay function wait 5 secs
alert("I waited 5 seconds"); // tell it
var user_time = prompt("Enter a Number","10"); // let the user decide how long
delay(parseInt(user_time)); // you have to parse the String into a number
alert("I waited another " + user_time+ " seconds"); // Talk again
app.activeWindow.screenMode = ScreenModeOptions.PREVIEW_TO_PAGE; // reset the view
// these are all the view options
// look here http://jongware.mit.edu/idcs6js/pe_ScreenModeOptions.html
// ScreenModeOptions.PRESENTATION_PREVIEW
// ScreenModeOptions.PREVIEW_OFF
// ScreenModeOptions.PREVIEW_TO_BLEED
// ScreenModeOptions.PREVIEW_TO_PAGE
// ScreenModeOptions.PREVIEW_TO_SLUG
}
// delay function found here
//found here http://www.wer-weiss-was.de/theme157/article1143593.html
function delay(prmSec){
prmSec *= 1000;
var eDate = null;
var eMsec = 0;
var sDate = new Date();
var sMsec = sDate.getTime();
do {
eDate = new Date();
eMsec = eDate.getTime();
} while ((eMsec-sMsec)<prmSec);
}
This example is a bit extended and makes a show
main();
function main(){
var ph= 200;// page heigt
var pw = 200;// page width
var doc = app.documents.add({/*make a doc*/
documentPreferences:{
pageWidth:pw,
pageHeight:ph
}
});
app.activeWindow.screenMode = ScreenModeOptions.PRESENTATION_PREVIEW; // go to prsent mode
var sentences =["This is the first sentence","This is the second","This is the third"];// this is our content
var page = doc.pages[0]; // this is the page
/*
lets make a textframe that will hold our content
when InDesign is running a script it seems impossilbe to
show the content of a textframe. Thats why we need a workaround.
We do as follows:
- create a textframe
- add the content
- style the text
- create a background that hides the frame
- create outlines from the text without removing the original
createOutlines(FALSE == dont remove original)
- than we bring that polygon to the front
so the textframe stays hidden but the outlines show
after 3 seconds we:
- remove the polygon
- add new content the the textframe
- createOutlines without deleting tf
- move them to the front
- show them
and so on...
*/
var tf = page.textFrames.add({
geometricBounds:[ph/2 - 25,12.7,ph/2+25,pw - 12.7],
contents: sentences[0],
textFramePreferences:{
verticalJustification: VerticalJustification.CENTER_ALIGN
}
});
var firstPar = tf.paragraphs.item(0); // get the first paragraph
// set some properties
firstPar.properties = {
pointSize: 10,
justification : Justification.CENTER_ALIGN,
hyphenation : false,
fillColor:doc.swatches[2]
};
scale_till_overflow(firstPar); // scale it up. This is styling only
var poly = tf.createOutlines(false); // if true the original gets deleted returns an Array
/*
cretaOutlines returns an array of polygons
the first one is the one we need
*/
poly[0].strokeWeight = 0; // give him no stroke
/*
add bg to hide tf
everything gets stacked in the doc
so bg created after tf will hide tf
*/
var background_rect = page.rectangles.add({
geometricBounds:[0,0,ph,pw],
fillColor:doc.swatches[3]
});
poly[0].bringToFront(); // bring the polygon to the front
delay(3); // wait
alert("I waited 3 seconds");// warn
poly[0].remove();// remove polygon
tf.contents = sentences[1]; // now set the content of tf again
scale_till_overflow(tf.paragraphs.item(0));// style it again
poly = tf.createOutlines(false);// and make outlines again
poly[0].bringToFront();// bring it to the front
delay(5);// wait
alert("Now I waited 5 seconds");// warn
poly[0].remove();// delete the second polygon we created
tf.contents = sentences[2];// set the text
scale_till_overflow(tf.paragraphs.item(0));// style
poly = tf.createOutlines(false);// and for the last time make a polygon
poly[0].bringToFront(); // show it
delay(1);// wait
alert("Now I waited 1 seconds. bye bye");// warn
poly[0].remove();// remove it
tf.remove();
background_rect.remove();
app.activeWindow.screenMode = ScreenModeOptions.PREVIEW_OFF ;// we are done
doc.close(SaveOptions.NO);
// done
};// end of main
function scale_till_overflow(par){
var ptsz = par.pointSize; // get the actual pointsize
// a while loop
// if the tf is not overlflowing scale up
while(par.parent.overflows == false){
par.pointSize = ptsz;
ptsz++;
}
// now he has overflow so scale down again until the overflow is gon
while(par.parent.overflows == true){
ptsz--;
par.pointSize = ptsz;
}
}
// delay function
// found here http://www.wer-weiss-was.de/theme157/article1143593.html
function delay(prmSec){
prmSec *= 1000;
var eDate = null;
var eMsec = 0;
var sDate = new Date();
var sMsec = sDate.getTime();
do {
eDate = new Date();
eMsec = eDate.getTime();
} while ((eMsec-sMsec)<prmSec);
}
This wiki is maintained by:
fabiantheblind
Collaborators:
- How To Install And Run Scripts
- References And Links
- Tools
- First Session
- Comments
- Extended JavaScript Guide
- Variables And Operations
- Conditionals
- Arrays
- Output And Interaction
- Objects
- Classes
- Loops
- Functions
- Recursive Functions
- The ID Scripting DOM
- ExtendScript
- Inspect Properties
- app
- Documents
- Pages And Margins
- Masterspreads
- Layers
- GeometricBounds and Coordinates
- Text
- Line Feeds And Carrige Returns
- Simple Find And Change Grep
- Simple Find And Change Text
- Text Analysis
- Text Analysis ID FC
- Text Find Locations
- InsertionPoints
- Styles
- Objectstyles
- Rectangles Ovals Polygons
- Matrix
- Outlines Groups Alignment
- Graphic Lines
- Spiro
- Colors And Swatches
- HSL Color Wheel
- Pathfinder
- Fonts
- Transformation Matricies
- Duplicate And Transform
- Includes
- Storing Data In A Target Engine
- Create And Read Files
- Read In JSON From File And Eval
- Delay And View
- ScriptUI Resource Strings