Copy link to clipboard
Copied
Hi everyone!
I have a document where the leading is not consistent across the paragraphs. I would like to set them all to "14.4.pt" and also add a 2 mm space before each paragraph. For that, I came up with the below the script, but for some reason nothing happens when I run it. Could anyone help me to figure out why?
@Rogerio5C09 -- Look no further than the two lines that @Robert at ID-Tasker suggested, repeated here for convenience:
doc.stories.everyItem().leading = '14.4pt';
doc.stories.everyItem().spaceBefore = '2mm';
This is all you need. But for interests' sake, apart from the comments that you didn't call your function, the function is inefficient because it resets the find/change preferences at every iteration. Get these settings out of the for-loop. o your script would look as follows:
f
...
Copy link to clipboard
Copied
What you enter in the Find what and Change to fields.
Copy link to clipboard
Copied
What you enter in the Find what and Change to fields.
By @Peter Kahrel
But it can be run globally on the whole document?
Or am I missing something?
Copy link to clipboard
Copied
Did you try that?
Copy link to clipboard
Copied
@Peter Kahrel I tried it just now and it worked as I expected, on multiple stories in the document. Are we talking about the same thing?
- Mark
Copy link to clipboard
Copied
Ah, like that. But then you'll have to run it for 17, 18, 19, and 20 pts separately because you have to have something in the Find what field and/or the Find Format panel.
Copy link to clipboard
Copied
Yep exactly! Easily done in 30 seconds. Just a funny observation.
Copy link to clipboard
Copied
Funny indeed! Still, you'd have to hope that those four are the only point sizes used. But I take your point, a good one.
Copy link to clipboard
Copied
How/where do you call your function fixLeading()?
Because you've declared it - but when/where do you run/execute it?
Copy link to clipboard
Copied
@Robert at ID-Tasker I hate when I forget main() at the end of the code!
Copy link to clipboard
Copied
Hi @Rogerio5C09, Robert and Brian noticed this, but I'm not sure if you understood. You have wrapped your code in a function `fixLeading`, with is fine, but nowhere in your code do you *call* the fixLeading function so nothing will happen when you run the code.
Add this line at the end:
fixLeading();
Copy link to clipboard
Copied
@Rogerio5C09 -- Look no further than the two lines that @Robert at ID-Tasker suggested, repeated here for convenience:
doc.stories.everyItem().leading = '14.4pt';
doc.stories.everyItem().spaceBefore = '2mm';
This is all you need. But for interests' sake, apart from the comments that you didn't call your function, the function is inefficient because it resets the find/change preferences at every iteration. Get these settings out of the for-loop. o your script would look as follows:
function fixLeading(){
var doc = app.activeDocument;
var leadingPoints = ["17pt","18pt","19pt","20pt"];
app.findTextPreferences = app.changeTextPreferences = null;
app.changeTextPreferences.leading = "14.4pt";
app.changeTextPreferences.spaceBefore = "2mm";
for (var i = 0; i < leadingPoints.length; i++) {
app.findTextPreferences.leading = leadingPoints[i];
doc.changeText();
}
}
fixLeading();
By the way, why do you look for those four point sizes? Are they the leading values in your document? The two-liner doesn't care about existing leading, it simply sets all text to 14.4pt leading.