8 Replies Latest reply on Oct 22, 2008 5:19 AM by MT.Freelance

    CS2: Script to Apply a paragraph style and next style?

    MT.Freelance Level 4
      I am stuck on CS2 for a project that is bound to drive me insane. It is a list of addresses, separated by county and city. I have a series of styles grouped for the Addresses such as

      STORE (name style)
      Address Line 1 (next style)
      Address Line 2 (next style 2)
      Phone (next style 3, returns to name style next)

      Although I can add a KB Shortcut to the Name Style, it will not activate the "Apply 'Name Style' and then next style" option. Nor, it seems, can I apply a KB shortcut to that style option.

      So, I select the group under the city, CTRL+Click on the style, and apply next style. Rinse and repeat for each city group of addresses. 200 entries down... 60,000 to go...

      Is there a way (and is there anyone willing) to script this so that I could apply a KB shortcut to the script to apply the style with next style to the selected text?

      This would probably be easier with CS3 and GREP, but that isn't an option for me right now.

      Thanks

      -mt
        • 1. Re: CS2: Script to Apply a paragraph style and next style?
          [Jongware] Most Valuable Participant
          Although not hard to script (*), wouldn't it still be easier to just select the entire text, and <br />i then<br />select "Style then Next Style"? It'd repeat automatically, if your styles are set up properly.<br /><br />You mention a city and county, and you can add these to your styles as Next Style as well. If they happen to be the same, just duplicate it under another name, so you can alter its Next Style setup as well.<br /><br />(*) Ten minutes' work gave me this<br /><br /><pre>a = app.selection[0].appliedParagraphStyle;<br /><br />for (i=1; i<app.selection[0].paragraphs.length; i++)<br /><br />{<br /><br />     a = a.nextStyle;<br /><br />     app.selection[0].paragraphs[i].appliedParagraphStyle = a;<br /><br />}</pre><br />-- and that took so long because I forgot to set a proper [Next Style].<br /><br />(Rest assured: GREP, although mighty, is not <br />i almighty<br /> and can't do wonders. Under CS3 it works pretty much the same.)
          • 2. Re: CS2: Script to Apply a paragraph style and next style?
            MT.Freelance Level 4
            I could set up the next styles to include the county and city IF there was a consistant progression of
            County
            City
            Store
            Address
            Phone
            County
            City
            etc.

            However, that is not the case.

            Some entries have one city in a county. Others have multiple.
            Some cities have one store. Others have dozens.

            Example:

            County
            City
            Store
            Address
            Phone
            County
            City
            Store
            Address
            Phone
            Store
            Address
            Phone
            Store
            Address
            Phone
            County
            City
            Store
            Address
            Phone
            City
            Store
            Address
            Phone
            City
            Store
            Address
            Phone
            etc.
            • 3. Re: CS2: Script to Apply a paragraph style and next style?
              MT.Freelance Level 4
              Works well enough.

              Thanks!

              -mt
              • 4. Re: CS2: Script to Apply a paragraph style and next style?
                [Jongware] Most Valuable Participant
                Good -- I was thinking on how City and County related to the rest, and one of the options was how you now describe it.

                The script could be enhanced to automatically start anew at every new county (and the Next Style for that is always a city, innit?),
                b iff
                there is a way to identify these. How do you know where to start for a county, in a list of tens of thousands? Do you know all of'em by name?
                • 5. Re: CS2: Script to Apply a paragraph style and next style?
                  Level 1
                  you dont need a script if you are getting the addresses in EXCEL format...I had to create a pretty big directory a while back and found a simple way to do it without scripts....let me know if you're still interested
                  • 6. Re: CS2: Script to Apply a paragraph style and next style?
                    MT.Freelance Level 4
                    I've received one MASSIVE XLS file. I don't want this in a big table, although that might have made life easier for applying styles (by column for instance).
                    I've split that up by state and pulled it into NeoOffice Base database
                    I've generated text reports from the state lists and the raw text goes something like this:

                    State Name
                    Virginia
                    Network Type
                    Retail
                    County
                    Virginia Beach
                    City
                    Virginia Beach
                    Store
                    Address_Street
                    Virginia Beach
                    VA
                    12345
                    (999)-555-1234
                    Store
                    Address_Street
                    Virginia Beach
                    VA
                    12345
                    (999)-555-1234
                    (etc)

                    I go through a series of 'Find/Change to remove the Return ^p between each line as needed. Example: I search for "^pVA^p" and replace with ", VA^>" This cleans up all the city/state/zip to one line

                    Virginia Beach, VA 12345

                    I do similar things with the State Name, County, City, etc. so that I end up with a record looking like this

                    State Name ^t Virginia
                    Network Type ^t Retail
                    County ^t Virginia Beach
                    City ^t Virginia Beach
                    Store
                    Address_Street
                    Virginia Beach, VA 12345
                    (999)-555-1234
                    Store
                    Address_Street
                    Virginia Beach, VA 12345
                    (999)-555-1234
                    Store
                    Address_Street
                    Virginia Beach, VA 12345
                    (999)-555-1234

                    I can then use the prefix on the entries for state, county, & city to do a find/change and apply the appropriate style.

                    In any case, I did work out a convoluted find/change solution:
                    I add 3 lines before each of the state, network, county and city. So, each falls into the four line Store Name - address - address - phone next style loop.
                    Next, I select the entire contents, apply the Style with Next style.
                    Then, I find/change to remove the three blank lines (find ^p^p^p Replace blank)
                    Next, search out each of the state, network, county, city prefix and apply the correct style.
                    Finally, search out each of the state, network, county, city prefix and delete them.

                    Works lots better than selecting a city, and applying a style, then selecting another city, repeat 4ever... begin.

                    ^_^

                    If you DO decide to script it out automatically, that would be cool, but I have a passable process now and managed to crank through 8 regions in the time it took me to do 1 the harder way.

                    This explanation glossed over some of the nit-pick things that have to be taken care of for the Find Change to find what I want and ignore what I don't, but that is the basics.

                    Kevin, I'd be interested in hearing what you did, as this is likely to be a project again in the future.

                    Thanks to you both.

                    -mt
                    • 7. Re: CS2: Script to Apply a paragraph style and next style?
                      Level 1
                      if you work on Windows - you can test my SerialReplace tool:
                      http://www.adobescripts.com/modules/mydownloads/singlefile.php?cid=9&lid=66

                      you can create set of rules for Search/Replace and use it next time by une button click :)

                      robin

                      --
                      www.adobescripts.com
                      • 8. Re: CS2: Script to Apply a paragraph style and next style?
                        MT.Freelance Level 4
                        Thank you. However, I'm working on a Mac.

                        ^_^

                        -mt