6 Replies Latest reply on May 25, 2016 7:43 AM by namechange02.03.2017

    putting the insertionpoint at a note

      if I have identified a note in paragraph in a story, how can I move the "cursor" to that note?

       

      If find the PDF and online help for InDesign JavaScript to helpful sometimes and woefully lacking at other times.

       

      Dave

        • 1. Re: putting the insertionpoint at a note
          vinothr Level 3

          Can you elaborate with what you want to achieve...? What you have in place now and what you want further from it...?

          So I would see if I can help you.

          • 2. Re: putting the insertionpoint at a note
            Level 1

            the user is somewhere in a document. I have a script that prompts them for some unique text in a note, then finds that note. Now I want to position  the user at the point in the document where the note is.

            Does that help?

            • 3. Re: putting the insertionpoint at a note
              Peter Kahrel Adobe Community Professional & MVP

              In a footnote, a text object's parent is the footnote. Footnotes have a property storyOffset, which is the insertionPoint of the note's reference. So: myFound.parent.storyOffset returns the insertion point of the note's reference.

               

              Tip for the future: experiment away. Select something in a note and see what app.selection[0].parent returns. You'd have found 'Footnote'. Then check what properties the footnote object has. Going through the list, the storyOffset property would have made you think (or even shout) 'Aha!'

               

              Peter

              • 4. Re: putting the insertionpoint at a note
                vinothr Level 3

                The following code would search your text and if found:

                1. Will select that note and shows it in Notes panel

                2. Navigates to the page where the story is

                 

                This is my first shot. You can optimize and fine tune as per your need.

                 

                Tested in InDesign CS6  and CC 2014 (windows). Should work on Mac.

                 

                 

                var search = "xyz"; // Your search term

                 

                // Get active document

                var doc = getActiveDoc();

                if(!doc) {

                    exit(0);

                }

                 

                // Find search text in active document

                var note = findNote(doc, search);

                processResult(doc, note);

                 

                 

                // Get active document

                function getActiveDoc() {

                    try{

                        return app.activeDocument;

                    }catch(e) {

                    }

                    return null;

                }

                 

                 

                // Process result of searching note

                function processResult(doc, note) {

                    // Processing note of Story only

                    if(note && note.parent.constructor.name == "Story") {

                        navigateToPage(note.parent);      

                        showNote(doc, note);

                    } else {

                        alert("No results");              

                    }

                }

                 

                 

                // Iterate each note in all doc stories

                function findNote(doc, search) {

                for(var i = 0; i < doc.stories.length; i++) {

                    var story = doc.stories.item(i);

                    for(var j = 0; j <story.notes.length; j++) {

                        try{

                                var contents = story.notes.item(j).texts.item(0).contents;

                                if(contents.indexOf(search) != -1) {

                                    return story.notes.item(j); // return note object

                                }

                            }catch(e) {

                            }

                        }

                    }

                    return null;

                }

                 

                 

                // Show the note in the Notes panel

                function showNote(doc, note) {

                    openNotesPalette();

                    var story = note.parent;

                    var noteIndex = note.storyOffset.index;

                    doc.selection = story.characters.item(noteIndex);

                }

                 

                 

                // navigate to page

                function navigateToPage(story) {

                    try {

                        var tc = story.textContainers[0];

                        app.activeWindow.activePage = tc.parentPage;

                    } catch(e) {

                        alert("Could not select the respective page");

                    }

                }

                 

                 

                // Open Notes panel

                function openNotesPalette() {

                    var menuAction =app.menuActions.itemByID(47903); // 47903  => Window-> Editorial->Notes

                    if(!menuAction.checked)

                        menuAction.invoke();

                }

                • 5. Re: putting the insertionpoint at a note
                  Peter Kahrel Adobe Community Professional & MVP

                  There I was thinking that we were talking about footnotes. But you're probably right, Vino, it's about notes.

                  • 6. Re: putting the insertionpoint at a note
                    Level 1

                    thanx for the comprehensive code. I had the find note logic written and it's equivalent to what you did so that's comforting.

                    It was the coding in the last three functions that I was unable to come up with.

                    I grabbed what you did and it works just like I would like.

                    Very grateful!