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

Jump to page.paragraph

Return to Member Forum

  • Author
    Posts
    • #61065
      kidpub
      Member

      Anyone know of or have a little script to jump to a specific paragraph on a page? I'd like to have Command-J style functionality but with the addition of a paragraph number. Someting along the lines of 123.4 to jump to para 4 on page 123.

      I've done one or two simple scripts and I don't think his one would be difficult, but I thought I'd ask before reinventing it.

      Thanks!

      Perry

    • #61083
      kidpub
      Member

      Since no one replied, I reinvented it. :^)

      The motivation for the the script is that we receive review comments from our authors as a list or spreadsheet with page and paragraph references (p12, para4, change this to that) and it save a lot of time to be able to jump directly to that specific page when applying the edits. The paragraph is highlighted to make it easy to find on the page. Thanks to Peter Kahrel for a snippet that creates a new text condition.

      //DESCRIPTION: Jumps to a specified paragraph on a page. The location is specified in a dialog box in the form page.paragraph
      //For example, to jump to the fourth paragraph on page 16, use 16.4
      //The specified paragraph is highligthed using conditional text. Tested in InDesign CS5.5.
      //
      //AUTHOR: Perry Donham, pd@kidpub.com, books.kidpub.com
      //Version: 1.0.0

      main();
      function main(){
      var kAppVersion = parseFloat(app.version);

      //This is the color we'll use (it's light green)
      //
      var highlightColor = [200,255,200];

      //Set up the condition
      //
      var highlightCondition = add_condition(app.documents[0], 'Edits', highlightColor);

      //Display the dialog
      //
      var d=app.dialogs.add({name:”Jump To Page.Paragraph:”});
      //Changed from integerEditBoxes to textEditBoxes

      with (d.dialogColumns.add()) {
      var numberBox = textEditboxes.add({minWidth:60});
      }
      var userInteract = app.scriptPreferences.userInteractionLevel;
      app.scriptPreferences.userInteractionLevel = UserInteractionLevels.INTERACT_WITH_ALL;
      var result = d.show();
      app.scriptPreferences.userInteractionLevel = userInteract;
      if(!result){d.destroy();return}

      //Parse out the paragraph and page numbers using split. The form is page.paragraph
      //
      var pagepara = numberBox.editContents;
      var mySplitResult = pagepara.split('.');
      var selectedParagraph = mySplitResult[1];
      var selectedPage = mySplitResult[0];

      //Jump to the page
      //
      if (app.activeDocument.pages.length > selectedPage) {
      var thePage=app.activeDocument.pages[selectedPage – 1];
      app.activeWindow.activePage=thePage;
      }
      else {
      alert(“The document does not have that many pages”);
      return;
      }

      //Get the text frame on the page
      //
      var theFrame = thePage.textFrames[0]; //should be only one

      //Get the paragraph in the frame
      //
      if (theFrame.paragraphs.length > selectedParagraph) {
      var theParagraph = theFrame.paragraphs[selectedParagraph – 1];
      }
      else {
      alert(“The page does not have that many paragraphs”);
      return;
      }

      //Set the condition
      theParagraph.applyConditions([], true);
      theParagraph.applyConditions(highlightCondition);

      //We'll use conditional text to highlight the paragraph, which is only visible in Normal mode
      //
      app.documents[0].layoutWindows[0].screenMode = ScreenModeOptions.previewOff;

      //Drop the dialog
      //
      d.destroy();

      //This is from Peter Kahrel's 'deviations' script at https://www.kahrel.plus.com
      //
      function add_condition (doc, n, c)
      {
      if (doc.conditions.item (n) == null)
      doc.conditions.add ({
      name: n,
      indicatorColor: c,
      indicatorMethod: ConditionIndicatorMethod.useHighlight});
      return doc.conditions.item (n)
      }
      }

    • #61084
      kidpub
      Member

      By the way, please feel free to enhance this…it does only simple bounds checking, for example, and doesn't understand the difference between a chapter title and a body paragraph…they are all just paragraphs to this script.

      Perry

    • #61089
      kidpub
      Member

      One small tweak. I modified the paragraph code so that if no paragraph was input in the dialog (ie 42 rather than 42.6) it jumps to the page, just like Command-J. That way the script can just replace the built-in jump-to-page and I don't have to think about which to use.

      //Get the paragraph in the frame

      //
      if (selectedParagraph != null) {
      if (theFrame.paragraphs.length > selectedParagraph){
      var theParagraph = theFrame.paragraphs[selectedParagraph – 1];
      //Set the condition
      theParagraph.applyConditions([], true);
      theParagraph.applyConditions(highlightCondition);
      }
      else {
      alert(“The page does not have that many paragraphs”);
      return;
      }
      }

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