• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Fixing leading by script

Contributor ,
Dec 05, 2024 Dec 05, 2024

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? 

function fixLeading(){

var doc = app.activeDocument;

var leadingPoints = ["17pt","18pt","19pt","20pt"];
   
for (var i = 0; i < leadingPoints.length; i++) {
    app.findTextPreferences = app.changeTextPreferences = null;
    app.findTextPreferences.leading = leadingPoints[i];
    app.changeTextPreferences.leading = "14.4pt";
    app.changeTextPreferences.spaceBefore = "2mm";
    doc.changeText();
    }

}
TOPICS
How to , Scripting

Views

664

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 3 Correct answers

Community Expert , Dec 05, 2024 Dec 05, 2024

@Rogerio5C09 

 

This should work: 

 

doc.stories.everyItem().leading = "14.4pt"; 

 

 

Votes

Translate

Translate
Community Expert , Dec 05, 2024 Dec 05, 2024
quote

And the spacing before? 🙂


By @James Gifford—NitroPress

 

doc.stories.everyItem().spaceBefore = "2mm"; 

Votes

Translate

Translate
Community Expert , Dec 05, 2024 Dec 05, 2024

@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
...

Votes

Translate

Translate
Community Expert ,
Dec 05, 2024 Dec 05, 2024

Copy link to clipboard

Copied

This is a simple matter of adjusting the paragraph style/s. A script is genuinely not needed if you have any skill with ID layout at all.

 

This also appears to "fix" the problem as text overrides, not style changes, which is very, very poor practice.

 

An even poorer practice is to use scripts etc. as hacks to get around very basic proper methods. 


┋┊ InDesign to Kindle (& EPUB): A Professional Guide, v3.1 ┊ (Amazon) ┊┋

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Dec 05, 2024 Dec 05, 2024

Copy link to clipboard

Copied

Hi @James Gifford—NitroPress, I totally agree with you, however believe me or not, the document was provided without paragraph styles, which makes things a bit more challenging 😞

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 05, 2024 Dec 05, 2024

Copy link to clipboard

Copied

@Rogerio5C09

 

If you can share your file with me - and let me know key properties by which you want to create styles - like FontFamily+FontStyle+PointSize, etc. - then I can style your file for you.

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Dec 05, 2024 Dec 05, 2024

Copy link to clipboard

Copied

Hi @Robert at ID-Tasker, unfortunately I'm not alowed to share the file. I could style it myself, but the document is quite big and we have a hard deadline, that's why I'm looking for a band-aid-solution to fix the issue.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 05, 2024 Dec 05, 2024

Copy link to clipboard

Copied

Select all text. Set your leading and spacing values. (Should be) done.

 

There's also — IMHO — a time to throw a badly prepared project back at the creator, or make sure they are compensating you for fixing its faults.


┋┊ InDesign to Kindle (& EPUB): A Professional Guide, v3.1 ┊ (Amazon) ┊┋

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Dec 05, 2024 Dec 05, 2024

Copy link to clipboard

Copied

Sorry, but that does not solve the issue. I'm talking about a huge doc with several pages and not a single text frame/story connected across the pages. Could anyone else please have a look on my code? Should the array be written differently? What I Am missing? Any help would be greatly appreciated 🙂

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 05, 2024 Dec 05, 2024

Copy link to clipboard

Copied

GIGO. Sorry you're stuck with it.

 

Not sure even a script will get you to a useful end, here.


┋┊ InDesign to Kindle (& EPUB): A Professional Guide, v3.1 ┊ (Amazon) ┊┋

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 05, 2024 Dec 05, 2024

Copy link to clipboard

Copied

@Rogerio5C09 

 

This should work: 

 

doc.stories.everyItem().leading = "14.4pt"; 

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 05, 2024 Dec 05, 2024

Copy link to clipboard

Copied

And the spacing before? 🙂


┋┊ InDesign to Kindle (& EPUB): A Professional Guide, v3.1 ┊ (Amazon) ┊┋

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 05, 2024 Dec 05, 2024

Copy link to clipboard

Copied

quote

And the spacing before? 🙂


By @James Gifford—NitroPress

 

doc.stories.everyItem().spaceBefore = "2mm"; 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 05, 2024 Dec 05, 2024

Copy link to clipboard

Copied

Just to be clear, I'm not being negative or dismissing here except on the basis that some documents are so badly constructed that effort spent trying to "fix them up" is far less useful than fixing the faults in the first place  — or, whenever possible, making the original creator or author do it. I realize that's not always possible, especially if you're just an employee being told what to accomplish, but even for a paying client, there's a limit to how much wasted time you should invest. The right approach  — IMVHO — is to tell the client just how much work is really needed and let them decide if they want to fix it themselves, pay you a reasonable rate to do it (and reap the benefits of a much "sturdier" document)... or go find some other provider who will waste his/her time.

 

That's the best advice/help I can summon for what appears to be a real mess of a project. I try to do better when it's possible.


┋┊ InDesign to Kindle (& EPUB): A Professional Guide, v3.1 ┊ (Amazon) ┊┋

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 05, 2024 Dec 05, 2024

Copy link to clipboard

Copied

@James Gifford—NitroPress I disagree that using scripts is an even poorer practice to get around issues. A skilled scripter could probably very easily fix the leading / spaceBefore issues while also generating correct/ varied paragraph styles with very little effort once they've seen the doc. But even without a robust fix, sometimes hacks are necessary. The design field is crowded. It's very easy to say "make the client do it or pay you to do it", but that client could just as very easily go to Fiverr to find a hack to fix it manually. I have dealt with many poorly constructed documents in my time, and sometimes the correct solution is to hack your way through it. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 05, 2024 Dec 05, 2024

Copy link to clipboard

Copied

Of the approaches to fix a badly formatted document, using a script to apply band-aid hacks pretty much has to come at the bottom.

 

That's not to say better-conceived scripts would not be of use to actually fix the faults, such as apply styles to paragraphs, remove or replace bad spot formatting, join text frames and the like.

 

But whitewash is whitewash.

 

(And no, competition is not, in itself, an excuse to cut one more corner than the next guy. Places like Fiverr and Upwork are nothing but clipped corners, and nobody wins. It's like doing crappy car repair because you're lowballing prices and the customer doesn't know any better.)


┋┊ InDesign to Kindle (& EPUB): A Professional Guide, v3.1 ┊ (Amazon) ┊┋

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 05, 2024 Dec 05, 2024

Copy link to clipboard

Copied

Wasting time hacking it manually is way worse than two lines of code to hack it in seconds. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 05, 2024 Dec 05, 2024

Copy link to clipboard

Copied

An excuse to cut corners is, as @Rogerio5C09 stated, a very tight deadline. Having spent a decade in newspaper production, I know exactly when hacks are necessary., and scripts are an excellent way to execute them. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 05, 2024 Dec 05, 2024

Copy link to clipboard

Copied

Sorry, I only have about 40 years across the spectrum of design and production. And I have come to stand on the side of professionalism over expedience almost without exception  — especially when the situation is a POS document put together by someone who didn't know what they were doing, and then expect gold-plated results without paying for the amount of effort required to get it there.

 

You've surely seen the tattered photocopy poster in every print shop: "You want it good, fast and cheap? Pick two and call me back!"

 

At a more concrete level, yes, I suppose these two short scripts will accomplish... something. But the overall description of the document is that it's a hacked, broken mess and you can only layer band-aids so deep, no matter how expedient you want to be or how much you want to coddle the poor client.


┋┊ InDesign to Kindle (& EPUB): A Professional Guide, v3.1 ┊ (Amazon) ┊┋

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 05, 2024 Dec 05, 2024

Copy link to clipboard

Copied

Get back to me when you've worked election night with 12 remote newspaper sites and 7 remote production facilities with similar deadlines and reporters filing garbagely styled stories from the field. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 05, 2024 Dec 05, 2024

Copy link to clipboard

Copied

Which has absolutely nothing to do with the subject at hand. But that said, I doubt you'd argue that at the root of all your election night efforts was something closer to professionalism - skill, experience, judgment - than random panic, right?

 

Noting that the OP has now spent most of a day screwing around trying to get enough help to make a ChatGPT band-and script get his project any closer to deadline... that's all too often how these short cuts and clipped corners go. Days later, the overall problem still isn't fixed well enough to go to print or whatever.

 

Shortcuts are fine in their place, but when you have a completely broken document, spending all day trying to scotch-tape it together is not time well spent. And at some point, someone has to own (up to) that broken doc, not shove it off on the next guy and yell about deadlines and cost issues.


┋┊ InDesign to Kindle (& EPUB): A Professional Guide, v3.1 ┊ (Amazon) ┊┋

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 05, 2024 Dec 05, 2024

Copy link to clipboard

Copied

I'm done debating the point. Who says OP didn't grab Robert's code, fix the issue (which it does), meet their deadline, and move on to the next task. Also think OP has spent time learning to script and is still learning, rather than using ChatGPT. And it's a valuable skill to have, and we are happy to help them along their journey. 

 

Meanwhile, elitists occasionally enter this niche section of the forums and harp about the "right" way to do things, without any scripting knowledge. I have no clue why your response was marked correct; as OP stated it was unhelpful, which it is. Neither was continuing this longwinded parley with me, but here we are. 

 

Just to be clear, I'm not being negative or dismissive here. Take care. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 05, 2024 Dec 05, 2024

Copy link to clipboard

Copied

You could adjust the Basic Text Frame object style, which I assume all text frames have, with a paragraph style with the correct leading and space after adjustments. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 05, 2024 Dec 05, 2024

Copy link to clipboard

Copied

@James Gifford—NitroPress and @brian_p_dts, at this point I am compelled to say—with wry amusement—that complete functionality of that the scripting options mentioned here could be done manually with the normal find text dialog in about 30 seconds. So there's that.

- Mark

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 05, 2024 Dec 05, 2024

Copy link to clipboard

Copied

An excellent point and one that was in the back of my mind haha. I don't believe our friend finds that suitable enough, however. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 06, 2024 Dec 06, 2024

Copy link to clipboard

Copied

Well, not quite, Mark: the manual method runs against stories, and the OP mentioned that his document has many stories, so he'd have to run that query many times.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 06, 2024 Dec 06, 2024

Copy link to clipboard

Copied

@Peter Kahrel

 

Which query?

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines