Saturday, October 18, 2008
CS4 Change
Now that CS4 is with us, it's time to start a list of changes (as opposed to out-and-out new features) that might affect existing scripts. The first one I ran into affected my WrapNudger product.
The TextWrapPreferences property previously known as textWrapType is now called textWrapMode. This change affected the function I use in WrapNudger to determine whether or not the selection has a text wrap. Here's the revised version of the function which shows how I made the script work with either CS3 (InDesign version 5) or CS4 (InDesign version 6):
The TextWrapPreferences property previously known as textWrapType is now called textWrapMode. This change affected the function I use in WrapNudger to determine whether or not the selection has a text wrap. Here's the revised version of the function which shows how I made the script work with either CS3 (InDesign version 5) or CS4 (InDesign version 6):
function checkSelection() {
if (app.documents.length == 0 ||
app.selection.length == 0) {
alert("Please select an object with a text wrap."); return false;
}
if (Number(app.version.split(".")[0]) > 5) {
if (app.selection.length == 1 &&
(!(app.selection[0].hasOwnProperty("textWrapPreferences")) ||
app.selection[0].textWrapPreferences.textWrapMode == TextWrapModes.none)) {
alert("Selected item must have a text wrap."); return false;
}
} else {
if (app.selection.length == 1 &&
(!(app.selection[0].hasOwnProperty("textWrapPreferences")) ||
app.selection[0].textWrapPreferences.textWrapType == TextWrapTypes.none)) {
alert("Selected item must have a text wrap."); return false;
}
}
return true;
}
if (app.documents.length == 0 ||
app.selection.length == 0) {
alert("Please select an object with a text wrap."); return false;
}
if (Number(app.version.split(".")[0]) > 5) {
if (app.selection.length == 1 &&
(!(app.selection[0].hasOwnProperty("textWrapPreferences")) ||
app.selection[0].textWrapPreferences.textWrapMode == TextWrapModes.none)) {
alert("Selected item must have a text wrap."); return false;
}
} else {
if (app.selection.length == 1 &&
(!(app.selection[0].hasOwnProperty("textWrapPreferences")) ||
app.selection[0].textWrapPreferences.textWrapType == TextWrapTypes.none)) {
alert("Selected item must have a text wrap."); return false;
}
}
return true;
}
Wednesday, October 15, 2008
Story to Layer
I was working on a job this morning (actually in CS4, which is released for download today) when I realized that the text frame I was looking at was on the wrong layer. Indeed, all the frames in my story, except for the first few, were on the wrong layer. This must have been the result of my leaving that wrong layer active when I saved the template. I've now fixed the main script that created this situation, but to solve the issue in the document on which I was working, I wrote this quick script:
The script is contained within an anonymous function which starts out by checking that there is a selection. If there is, it confirms that the selection has a parentStory property, and if so, it moves all the text frames that constitute that story (textContainers in CS3 and CS4) on to the same layer as the first frame of the story.
//DESCRIPTION: Move all text frames of story to same layer
/*
This script assumes that the first frame of the story is on the right layer
*/
(function() {
if (app.documents.length > 0 &&
app.selection.length > 0) {
var aSel = app.selection[0];
if (!aSel.hasOwnProperty("parentStory")) {
alert("Selection has no parent story"); return;
}
var aStory = aSel.parentStory;
var aLayer = aStory.textContainers[0].itemLayer;
for (var j = aStory.textContainers.length - 1; j > 0; j--) {
aStory.textContainers[j].itemLayer = aLayer;
}
}
}())
/*
This script assumes that the first frame of the story is on the right layer
*/
(function() {
if (app.documents.length > 0 &&
app.selection.length > 0) {
var aSel = app.selection[0];
if (!aSel.hasOwnProperty("parentStory")) {
alert("Selection has no parent story"); return;
}
var aStory = aSel.parentStory;
var aLayer = aStory.textContainers[0].itemLayer;
for (var j = aStory.textContainers.length - 1; j > 0; j--) {
aStory.textContainers[j].itemLayer = aLayer;
}
}
}())
The script is contained within an anonymous function which starts out by checking that there is a selection. If there is, it confirms that the selection has a parentStory property, and if so, it moves all the text frames that constitute that story (textContainers in CS3 and CS4) on to the same layer as the first frame of the story.