Back

If your email is not recognized and you believe it should be, please contact us.

  • You must be logged in to reply to this topic.Login

Is there a way to separate things like this Automatically?

Return to Member Forum

  • Author
    Posts
    • #55430
      rydesign
      Member

      Here is the idea. I am working with Tire Sizes and need to separate each group of sizes with a line. Right now I have it set up pretty easy. I just manually scan down through the list and hit a key comand and my (automatic1st line) paragraph style lays down a custom Paragraph Rule above and a little space before. I have to do this for 2600 tires scanning down and finding the break in sizes and inserting a line. Is there a way to automate this? Perhaps with Grep or scripting? any Ideas?

      Grep Seach using? ddd/ddR-dd

      can it find something until it doesn't match the clipboard or something like that. When it doesn't match the clip board that Paragraph is styled with (automatic1st line) paragraph style and the new size is moved to the clipboard.

      Here is an example of what I need

      part number Tire Name Tire Size Price

      xxxxxx Cool Tire 255/55R-15 $$

      xxxxxx ok Tire 255/55R-15 $$

      xxxxxx sweet Tire 255/55R-15 $$

      ____________________________________________(tire size are not the same need line to break it up)

      xxxxxx awesome Tire 255/60R-15 $$

      ____________________________________________ (tire sizes are not the same need line to break it up)

      xxxxxx Lame Tire 225/30R-16 $$

      xxxxxx wicked Tire 225/30R-16 $$

    • #55431
      rydesign
      Member

      I know… I am Lazy.

    • #55432

      Laziness is okay in my book, as it makes you want to look for easier solutions!

      This script sounds like it does what you want. Your initial idea is good, but you cannot (or hardly) use the clipboard inside a javascript. So the script scans for your GREP match string (that was a good one!), and when it finds a paragraph with it, it kicks into action: it stores the found stuff in “lastMatch”, so it can compare the next paragraphs against this same value. If it's the same, the paragraph is skipped, and if the pattern *is* found but not the same, your style (I called it “LineAbove”) is applied. Then this value is used as “lastMatch”, and the loop goes around and around until the end of your text is reached.

      As it is, the LineAbove style is *only* applied when the previous and current paragraphs contain the GREP string, so it will never (I think!) be applied at the very top or very bottom of a table. Note: blank lines also 'break' this pattern, and you might or might not have had that in mind.

      Place your cursor in the first row to check, double-click the script, and stand well back.

      (Oh — sorry, David, this forum's editor can't handle medium-long scripts! No prob. — RY, download it from my site: https://www.jongware.com/binari…..er.jsx.zip — unpack, put into your scripts folder, run as above.)

      (Be sure to first change the style name somewhere near the top to yours, though.)

    • #55435
      rydesign
      Member

      WOW! all I can say is WOW. It works great. Takes a bit of time to chug through things but I imagine it is doing quite a bit of work to come out with EXACTALLY WHAT I WANTED! Thanks again Jong.

    • #55457
      rydesign
      Member

      Just wondering if there is an easy way to combine scripts. I will be running this one and the FindChangeByList script on many occasions. Looking at the structure of the script it looks like I can't just copy this one in to the find change script and have it work.

      Just wondering if there was a way to combine these into one super mega script.

    • #55459

      Sure there is. You can use one script to run other scripts from, with the command 'doScript'.

      You will have to experiment a bit, because sometimes scripts need specific starting circumstances — mine needs the cursor to be in the first line of text to check, and when it's done the cursor is on the last line it checked. Other scripts may need the cursor to be somewhere else, or nowhere, or have a frame selected (and so on) …

      If you find yourself clicking several scripts in a row without doing anything else (that included repositioning the cursor!), you can safely chain them to run in sequence using just one script.

      The framework script should contain this line for each script to run:

      app.docScript (app.activeScript.path+'/yourScriptName.jsx');

      The path stuff is because 'doScript' needs the exact run time path of the script that it's going to run — typically, that'd be the Scripts folder in your personal User data folder. Fortunately, you don't even have to type it in, because the “active” script — the one that is running — can ask “whence it was run from” (the activeScript.path property), and if all your scripts are in the same folder, you only have to tack on the name of the script to run.

    • #55467
      rydesign
      Member

      I keep getting an error that FindChangeByList is undefined.

      is there a certian place I should be putting this… I thought if I inserted it before anything else it would run the find change first and then continue with the rest.

      app.doScript (app.activeScript.path/FindChangeByList.applescript);

      toMatch = “d+/d+R-d+”;
      applyStylename = “LineAbove”;

      currentPar = app.selection[0];
      if (!(currentPar instanceof InsertionPoint))
      {
      alert (“Please place your cursor on the starting line”);
      exit(0);
      }

      do
      {
      do
      {
      currentLine = currentPar.paragraphs[0].contents;
      if (currentLine.match (toMatch))
      break;
      if (currentPar.parentStory.paragraphs.nextItem(currentPar) == null)
      {
      alert (“No match found for “”+toMatch+””!”);
      exit(0);
      }
      currentPar = currentPar.parentStory.paragraphs.nextItem(currentPar);
      } while (1);

      lastMatch = currentLine.match(toMatch);
      do
      {
      do
      {
      if (currentPar.parentStory.paragraphs.nextItem(currentPar) == null)
      {
      alert (“End of text reached”);
      app.select (currentPar.insertionPoints[0]);
      exit(0);
      }
      currentPar = currentPar.parentStory.paragraphs.nextItem(currentPar);
      currentLine = currentPar.paragraphs[0].contents;
      if (currentLine.length < 2) continue;
      testMatch = currentLine.match(toMatch);
      if (!testMatch)
      break;
      if (lastMatch[0] != testMatch[0])
      {
      // currentPar.underline = true;
      currentPar.appliedParagraphStyle = applyStylename;
      lastMatch = testMatch;
      }
      } while (1);
      if (!testMatch)
      break;
      } while (1);
      } while (1);

    • #55472

      You need to add quotes around the actual script name. I'm not totally sure it works with an Applescript either … I only link Javascripts together. (Anyone else? Help?)

      app.doScript (app.activeScript.path+/FindChangeByList.applescript);

      (Besides, you would need to make sure the applescript is in the same folder as the script you are running — because that's what the “app.activeScript.path” path points to!)

    • #55619
      benc.academie
      Participant

      Hi Jongware,

      To make this script more flexible, i've replaced the fisrt two lines with this

      toMatch = “”;
      toMatch = prompt (“Enter your GREP Expression”);
      applyStylename = “”;
      applyStylename = prompt (“Enter the Style name”);

      Now, i don't know what to do with the infos at the top. Since this is an alteration of your original script, should i add an Edit to it or do you want me to leave the heading as it was. It is your script after all. I am new to programming so i don't know the “convention”.

      Thanks

      //DESCRIPTION:Magic Tire Table Changer
      // Jongware, 06-Apr-2010
      // toMatch & applyStylename Prompts added by Benc.academie
      // Warning: contains extremely targeted code;
      // not likely usable for anyone else.

    • #55620

      As far as I'm concerned, you may put your name at the top :-)

      My JS knowledge didn't come from sleeping with a notebook under my pillow — I learned my trixx from others as well, just passing them on.

    • #14371180
      David Blatner
      Keymaster

      Jongware’s site is no more, so I put the newest version he had here: creativepro.com/files/jongware/binaries/tirechanger.jsx.zip

Viewing 10 reply threads
  • You must be logged in to reply to this topic.
Forum Ads