Automatically set paragraph style sheet

Learn / Forums / General InDesign Topics / Automatically set paragraph style sheet

Viewing 10 reply threads
  • Author
    Posts
    • #86957
      Scott Croft
      Member

      Hi All

      I’ve got a bit of a question, I have a job which I do three times a year, it’s a diary of events.

      For this I use three style sheets, Date Heading, Body Entry and a third which is for the last line of body text (Body Last) which puts a ruled line under the last entry for that day.

      At present I set everything to the Body Entry style (as it forms the bulk of the text) then I go through manually set the stylesheet for the last lines and the date lines.

      Is there a way I could automate some of this process? In an ideal world I’d be able to do a find and replace and the days of the week and get Indesign to set the style sheet for that line to Date Heading and the previous line to Body Last, is that possible?

    • #86961

      I would assume, that you could automate everything here, so please provide a example (as screenshot with show invisibles turned on or better as idml > before after)

      best
      Kai

      • #86965
        Scott Croft
        Member

        Just put together an example file from the one I’ve been working on, had to remove sensitive details etc so it will look a little odd where Ive split things across pages but it works with the full version of the text. :)

        I’ve dropped the text into a text box and set to default text for the ‘before’ text.

        Here is the file google drive (hopefully the link will work)

        https://drive.google.com/file/d/0B8ZcRQvOFxrVMjlKV0dDdnhWU2s/view?usp=sharing

        Any help would be hugely appreciated!!

    • #86962
      Matt Isaac
      Participant

      If you are typing the diary as you work, one way you could do this is by applying the body style as the next style for the date header. Then create a character style with only an underline and set that as a grep style in the body to text: ^.+\z. If you do it this way, you will want to put in a right indent tab (Shift+Tab) at the end of the last line. Though I’m sure Kai will have a better solution when you provide before/after screenshots. :)

      This won’t work if your last paragraph is more than one line.

    • #86968
      Ari Singer
      Member

      Try this:

      var myDoc = app.activeDocument;
      app.findGrepPreferences = app.changeGrepPreferences= null;
      app.findGrepPreferences.findWhat = "$";
      app.findGrepPreferences.appliedParagraphStyle = myDoc.paragraphStyles.item("Day entries");
      var story = myDoc.findGrep()[0].parentStory;
      var found = story.findGrep(true);
      for (var i =0; i < found.length; i++) {
      	var para1 = found[i].paragraphs.firstItem();
      	var para2 = para1.paragraphs[-1].insertionPoints[-1].paragraphs[0];
      	if (para2.appliedParagraphStyle == myDoc.paragraphStyles.item("Date Headings"))
      		para1.appliedParagraphStyle = myDoc.paragraphStyles.item("Day entries LAST");
      	}
      
      
      

      This works by finding any paragraph that has the regular paragraph entry applied, but that the paragraph after that has the new date paragraph style applied.

    • #86985

      Ari, your script doesn’t work with his testfile, even if I remove the textflow on the page, I get several errors?

      • #86989
        Ari Singer
        Member

        Funny, because it works by me. Maybe this is better:

        var myDoc = app.activeDocument;
        app.findGrepPreferences = app.changeGrepPreferences= null;
        app.findGrepPreferences.findWhat = "$";
        app.findGrepPreferences.appliedParagraphStyle = myDoc.paragraphStyles.item("Day entries");
        var found = myDoc.findGrep();
        for (var i =0; i < found.length; i++) {
        	try {
        	var para1 = found[i].paragraphs.firstItem();
        	var para2 = para1.paragraphs[-1].insertionPoints[-1].paragraphs[0];
        	if (para2.appliedParagraphStyle == myDoc.paragraphStyles.item("Date Headings"))
        		para1.appliedParagraphStyle = myDoc.paragraphStyles.item("Day entries LAST");
        		} catch(_){};
        	}
        
    • #86992

      Ari, the new version doesn’t step up and down the omv anymore :), but it does nothing in the test doc. So it would be helpful, if the op give an information, if it works for him.

      To do it manually:
      1. Select the text and apply ‘day entries’ to everything
      2. Find what: ^\d{1,2}\u , Change to: nothing + applied style ‘Date headings’
      3. Find what: (?s).(?!.) + applied style ‘Day entries’ , Change to: nothing + applied style ‘Day entries Last’

      Kai

    • #87111
      Scott Croft
      Member

      Hi All

      Thanks for the help, I posted the thread then was off ill for a couple of days then on holiday and forgot all about it. I’m back at work now and have given both methods a try. The script doesn’t seem to do anything? I’ve put it into my script folder and tried running it but nothing happens? Am I doing something wrong?

      Kai: the manual method works perfectly thank you!! It will save me so much time next time I put one of these diaries together! Might you be able to explain what each of the find bits are actually doing/ looking for as I don’t really understand it and I would like to get my head round it so in future I might have a bit more of a clue.

      Also, a bit cheeky, but is there also a way to use a find/change to find where I have the week numbers next to the Monday entries to make them the correct character style (week number) but to also have it change for the number that follows the word week?

      Thanks again.

    • #87112

      Aris Skript assumes, that you apply ‘Day entries’ and ‘Date headings’ by hand. I’ve no idea, why he collect first insertionPoints and did it this way …

      What I did manually:
      1. This is clear.

      2. Find the beginning of a paragraph, followed by a number, that consists of 2 digits, followed by a uppercase letter. This will find 22 Monday’, but also ’99Chicken wings’. Since I didn’t find those chicken wings-problems in your document, I decide to do it the easy way. Otherwise the search must be more specific.

      3. (?s) choose the so called ‘Single line mode’ and affected the scope of the wildcard ‘.’ So in this special case, it finds a character with applied style ‘Day entries’, if the next character has not this style applied. So it finds the last line and give us the chance to apply another style.

      To your last question:
      Sure, this could be done by F/C or could be part of a grepstyle: (?i)week\x20\d+$
      Will find caseless week(WEEK), followed by an space, followed by any number at the end of a paragraph.

      best
      Kai

    • #87123
      Scott Croft
      Member

      Thank you so much for your help and the explanation of how it works, I think I understand it. I would like to get myself more familiar with all the grep stuff as it seems insanely powerful if you know what you’re doing with it!!

      The steps for the manual processing will save me a huge amount of time every time I have to put together one of these diaries!! :)

    • #87282

      Wait, there is even more ;-)

      I really like those tasks, since a simple script could combine everything together. The script will not check, if your para styles are valid. It assumes, that the cursor is blinking in your story.

      if (app.documents.length == 0 || app.selection.length != 1 || /InsertionPoint/.test(app.selection[0].constructor.name) == false) {  
        alert ('Click in your story!');  
        exit();  
      }
      
      var curStory = app.selection[0].parentStory;
      curStory.paragraphs.everyItem().appliedParagraphStyle = "Day entries";
      
      var changeList = [
        [ "^\\d{1,2}\\u", NothingEnum.NOTHING, "Date Headings" ],
        [ "(?s).(?!.)", "Day entries", "Day entries LAST" ]
      ]; 
      
      app.findGrepPreferences = app.changeGrepPreferences = null;
      
      
      for ( var j = 0; j < changeList.length; j++ ) {
        var curSearch = changeList[j];
        app.findGrepPreferences.findWhat = curSearch[0];
        app.findGrepPreferences.appliedParagraphStyle = curSearch[1];
        app.changeGrepPreferences.appliedParagraphStyle = curSearch[2];
        curStory.changeGrep();  
      } 
       
      app.findGrepPreferences = app.changeGrepPreferences = null;
      

      One last comment: You should avoid ‘indent to here’ for all your entries (sometimes multiple?), since you can easily do it with a positive and negative indent.

      Kai

    • #87297
      Scott Croft
      Member

      OMG!!! That is seriously amazing, thank you so, so, so much!! :)

      This will make a job which is normally a massive, massive chore into something which will take just a few minutes!

      I really must have a look into scripting and see if I can get my head around it because it is clearly a potential huge time saver!

      That’s a good point re the indent to here markers, I put those in quickly when I did a find and replace on the raw text I get from the database (which has a symbol instead of tab markers as it can’t export tab markers), Didn’t even occur to me to use indents and first line indents to achieve the same thing, though I have used exactly those in similar situations in the past.

Viewing 10 reply threads
  • You must be logged in to reply to this topic.
>
Notice: We use cookies on our websites to give you a great online experience. If you keep browsing, we'll assume you're ok with this. For more information, see our privacy policy. By closing this banner, you agree to the use of cookies.I AGREENo