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

GREP to cut text and paste in separate text box?

Return to Member Forum

  • Author
    Posts
    • #33951
      Chris Lane
      Participant

      Is there a way to locate text within a paragraph, such as {Author: Is this term correct}, cut it, and paste into a separate text box outside the page margin. I am able to locate anything that begins with ?Author? within curly brackets and paste an anchored box outside of the page margin at the end of the closing curly bracket but would like a GREP to actually then cut the text and place it inside the anchored text box. I am almost thinking there needs to be a script to achieve that but I am not real familiar with scripting. Maybe somebody already has a script similar to my needs that they would like to share? : )

    • #34068
      redbook
      Member

      I recently asked nearly the same question (see my post “Marginal line numbers extracted from text” at the top of the forum).

      Jongware replied with this nifty script he wrote that does the trick for me. Be sure to make all of the quote marks straight quotes (retype them so they look straight). And you’ll need to paste in your grep expression in line 2 to replace mine: “[d+]”;

      Keep the quotes and the final semicolon, my grep expression starts with the first slash and ends with the close bracket.

      once done, the anchored boxes weren’t quite in the right position, so I searched for all anchored boxes (using “object” in the find menu) with custom positioning, and changed to an object style I had created that positioned them 12 pts into the outside margin, base aligned with the anchor point. If I knew java, I could probably finesse the script to do that as well, but it was easy enough as a separate search.

      good luck!

      app.findGrepPreferences = null;
      app.findGrepPreferences.findWhat = ?[d+]?;
      numberList = app.activeDocument.findGrep(true);

      for (i=0; i<numberList.length; i++)
      {
      tf = numberList[i].textFrames.add({anchoredObjectSettings:{anchoredPosition:AnchorPosition.ANCHORED, anchorXoffset:?1mm?}});
      tf.geometricBounds = [“0mm”,”0mm”,”10mm”, “50mm” ];
      numberList[i].move(LocationOptions.AT_BEGINNING, tf.texts[0]);
      tf.fit (FitOptions.FRAME_TO_CONTENT);
      }

    • #34069

      Ah, so this was the “other” question. Redbook is correct, it seems all that’s needed here is a different GREP search. Use this to locate your curly bracketed remarks:

      app.findGrepPreferences.findWhat = “{.+?}”;

      (don’t forget to straighten the quotes out)

      In this case, for GREP you need to ‘escape’ the curly brackets because they are special command codes. In addition, you do not want “all that you can get” between an opening and closing curly bracket — if there is more than one set in a single paragraph, GREP will happily grab all between the very *first* opening bracket and the very *last* closing one. To prevent this, you add a ‘?’ after the ‘grab-anything’ command ‘.+’; it will now match the shortest possible match instead of the longest possible.

    • #34077
      Chris Lane
      Participant

      Thanks for the response Red and Jong! This is almost what I am looking for except I need the anchored text box to be a fixed width of 6p AND apply an Object style to the anchored box named “Author Query”. The object style I have for the box colorizes it and Fits frame to content for the depth. Any suggestions for that? I probably should have included all that info in my original request for help!

    • #34078
      redbook
      Member

      I also needed to adjust the boxes and positioning, that is the part I did as a search and replace using the “find” menu (find, object, object format options,anchored object options/chose “custom” in the top box). I replaced with my anchored box object style, so all the boxes are exactly the same size, exactly in 12 pts in the margins, etc. All you need to do is specify your custom object style and it should change all the anchored boxes, and place them where you want them and apply the tint.

      I do wish I knew how to put all that into the script, but I don’t. At least it works this way, and even though an extra step, it only takes a minute or so.

      Javascript training . . . on my list of to dos!

    • #34079
      Chris Lane
      Participant

      I did the exact same thing and it does work beautifully and even though a two step process, it is a definite time saver (a little extra time for Java training now!). I think I am getting greedy to do it all in one step but extremely happy with this method.

    • #34100
      redbook
      Member

      I’m happy, too, that we both got the answer we needed!

    • #14324055
      Kelly De Jong
      Participant

      I am trying to do something similar, but with a twist. I am searching for a paragraph style that I want to be cut from text and pasted into an anchored text box as a sidebar. Will this work, just tweaked a bit?

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