[JS] "Story offset" of paragraph

How do you find out the index of a selected paragraph within a story.
app.selection[0].paragraphs[0].index;
For some reason the above returns the index of the first character
within the story.

search forum - was discusion about that in last week or so
or look at this thread:
CS3 Javascript - finding the paragraph which contain the index page reference
http://www.adobeforums.com/webx?128@@.3bbf275d.59b75803
robin
www.adobescripts.com

Similar Messages

  • Count paragraphs in entire story (AS)

    Hi,
    I have long document with all text frame chained.
    I need to count paragraphs of entire story. Count paragraphs not get the text and count paragraphs of text.
    I cannot find the correct syntax.
    Thanks in advance.
    Ste

    Hi Olav,
    thanks for reply. I forgot to tell that I need to point a text frame called with a particular name.
    This text frame is linked to all other text frames that flows on other pages.
    I found the syntax:
    tell application "Adobe InDesign CS4"
    set myDoc to active document
    tell myDoc
    set myTargetFrame to text frame "Ste"
    set numPar to count (paragraphs of parent story of myTargetFrame)
    end tell
    end tell
    That return the total number of paragraphs inside the full story.
    If I add to your script: of text frame "bla bla bla" I receive error.
    Ste

  • Create TOC javascript using paragraph style

    Hi,
    i want to create javascript for TOC in new indesign document or book. but i want to use input style for paragraph styleHi,

    "It didn't work for me" doesn't work for me. Always, always, always, state why it doesn't work for you.
    Did you try to use it, but could not get it to work?
    Or, do you need to do something special that the built-in function does not do?
    It should not be extremely hard to make a javascript version that does (roughly) the same. You could try something like this:
    For every paragraph style you want to include (most likely all sorts of headings),
    Search for all occurrences, and store the text, its page number, and (important!) its story offset in an array.
    You need the text because that's what will appear in the TOC.
    You need the page number because, well, that's what the TOC is for :-)
    Most important: you need the story offset so you can reconstitute the original order of the headings. You can only search for one level of heading at a time, so without sorting, you would get "Heading 1 -- Heading 1 -- Heading 1 -- Heading 2 -- Heading 2 -- Heading 2" (etc.)
    When you have gathered all of the information for your entire book, sort on story offset. (I forgot, it's for a Book, right? You need to store a document id as well, so you can sort throughout multiple documents.) (See Ed.)
    Then write out every text in the right order, followed by its page number.
    The IndexMatic script that Marc points out should already contains lots of the logic described here -- esp. searching and storing page numbers.
    [Ed.] Thinking about it, a Book (multiple documents) should *not* cause any problems, and you don't need to know in which document some text was found. Simply sort the paragraphs on their page number; only when these are the same for more than one paragraph, sort just these on their Story Offset. Logically, there should not be two headers with the same page number in two different documents.

  • Make anchored text frame after it is move in to story

    Hi,
    In my document have 4 stories. and one text frame
    this text frame is make of anchored text frame and it move in story 1
    It is possible ?
    please help me...
    my coding is shown in below
    tell application "Adobe InDesign CC 2014"
            set storyofset to story offset of myElement-------------->myElement is particular xpath
            tell storyofset
                set anchored position of anchored object settings of text frame 1 to anchored
                set horizontal reference point of anchored object settings of text frame 1 to anchor location
                set anchor xoffset of anchored object settings of text frame 1 to 0
                set anchor yoffset of anchored object settings of text frame 1 to 0
                set text column count of text frame preferences of text frame 1 to 1
            end tell
        end tell
    thanks in advance.
    by, John Peter.

    I copied text & paisted it and then draged the 3 photos from the file...then clicked on the photo then clicked the inline boxon tool bar nexed to floating one and that is how I did it
    I do not know what you mean "cut & paist"  how do I get the photo in from my picter folder if I do not drag it to the page in Pages? 
    I went to my photo folder and copied a photo and paisted the photo on the top left part of the page and it went there but there was no text to the right of photo...I could crop the photo to what ever size but no text to the right of photo...
    This is just too big of a mess of a program as it should be easier then this,,,I hav e 300 photos in this project and would have to re-paist them all...that is nuts...
    I see the button to the right of inline and floating that has 6 [lace to have the photo but the text does not float around the photo...
    If this is what your talking about this very little freedom in my page layout as I need it to let me place it where I need it to be and the wrap the text...
    There has to be an easier way to get my books ready for other formats other that Apple's iPad...iBooks Author was way eisier to make ready for iTunes...Love that program!!!
    Want my books for sale on all the other formats and was told by Apple Pages whould do it...
    I must be be out to lunch or the designers at Apple are ???

  • Paragraph number in pages

    Can anyone tell me how to find the paragraph number of the insertion point in a Pages 09 document?
    Thanks

    Maybe like this:
    *tell front document of application "Pages"*
    *set C to character offset of (get selection)*
    *set N to 0*
    *repeat with P in (get character offset of paragraphs)*
    *if P > C then exit repeat*
    *set N to N + 1*
    *end repeat*
    N
    *end tell*

  • How to ADD A Paragraph?

    Can someone please assist with this small script.
    I'm trying to create a text frame with several paragraphs in it (so I could apply different paragraph styles).
    I spent half an hour already looking through Adobe's Scripting manual, and I found all the bells and whistles of paragraps, except how to add more than one paragraph to the text frame
    Here's what I have so far, obviously the paragraphs.item(1).contents line fails. I'm stumped. What I want is products[0].number and products[0].text to be on two separate lines and to be two separate paragraphs so I could style them differently.
    var doc = app.documents.add();
    var text_frame = doc.pages[0].textFrames.add();
    text_frame.geometricBounds = ['6p', '6p', '240pt', '240pt'];
    text_frame.contents = products[0].number + "\n\n" + products[0].text;
    text_frame.parentStory.paragraphs.item(1).contents = 'TEST';
    text_frame.fit(FitOptions.frameToContent);
    var b = text_frame.geometricBounds;

    Zoffix222 wrote:
    My problem is that the string I'm adding as a paragraph might contain "\r" characters anywhere in it. Thus, if I add it without taking care of them, I'll end up with multiple paragraphs instead of one.
    The 's' and '/' are not important, I was implying that I need to look up how to use the global flag in JavaScript
    I'll figure this out tomorrow.
    Thanks for the help.
    I see. You can do somthing like this:
    function addParagraph(myStory, myString){ // adds texts as new paragraph at end of a story
        myString = myString.replace(/\r+/g," "); // replaces one or more \r with a single space.
        myStory.contents = myStory.contents.replace(/\s+$/,"") //removes trailing whitespace in the story
        if (myStory.paragraphs.length > 0){
            myString = "\r"+myString;
        myStory.insertionPoints[-1].contents = myString; // adds the Story to the end of the story.

  • Applescript problems with character offsets and embedded objects in Pages

    https://discussions.apple.com/thread/2550810?start=0&tstart=0
    The above discussion is archived, but I've noticed a problem witht he solution it proposes.
    Essentially, the problem seems to be that the character offset of a selection becomes either inaccessible or out of sync when embedded objects are present in the file.
    The following document can be used to demonstrate:
    http://images.apple.com/support/pages/docs/ePub_Best_Practices_EN.zip
    I've slightly modified the script fromt he previous thread, so here's my own script:
    tell front document of application "Pages"
              set C to character offset of (get selection)
              set N to 0
              repeat with P in (get character offset of paragraphs)
                        if P > C then exit repeat
                        set N to N + 1
      select paragraph (N + 1)
              end repeat
              N
    end tell
    This script is supposed to select the next paragraph in a document, when given a selection. The intention is to call it recursively to get each paragraph of the document in turn.
    At the start of the document, it functions correctly, however when it gets to the embedded pictures, lines and table of contents, things start to break. This wouldn't be so bad, because I could simply ignore paragraphs that contains those embedded objects, but the real problems arise in the normal text below these objects.
    If you place the cursor on the 3rd page of that document, in an ordinary paragraph, for example, this script will simply return the same paragraph over and over. The reason for this is that the character offset of the paragraphs is being thrown off, so the if statement gets hit too early. You can also see this if you look at the character offsets of the word "Introduction" in the heading at the top of the 3rd page. You'll notice that the character offset is duplicated for a couple of letters, and is out of sync with the index of the character itself.
    What I need is a script that will take a selection (of any type), and simply return the correct index of the paragraph containing it every time. It doesn't seem like a difficult thing to do, and since the paragraphs are accessible by index, they should be able to return their index to the user. I have a feeling Apple need to add this functionality to the Pages Applescript dictionary, and they definitely need to fix the bug where the character offsets go out of sync after embedded objects. These are really quite bad problems.

    Hi,
    Pierre L. wrote:
    I have tested it with the document referred to by andyboyd. When the first word (“Introduction”) of the first paragraph of page 3 is selected, your script returns {10}, while it returns {12} when the second word (“to”) of the same paragraph is selected.
    Message was edited by: Pierre L.
    Thanks Pierre.
    Ok, the error is that I mixed the variable N and N1, during the renaming of variables
    return N - 1  must be return N1 - 1 -- return the index
    Here the corrected script :
    set indexList to my getIndexOfLinesInSelection()
    on getIndexOfLinesInSelection()
       script o
          property parOffsetList : {}
          on getIndex(C)
             tell application "Pages" to tell front document
                set parOffsetList to character offset of paragraphs
                set tc to count parOffsetList
                repeat with N from 1 to tc
                   if N = tc then return tc -- it's the last paragraph
                   if (item N of parOffsetList) > C then
                      set N1 to N
                      repeat -- check the  character offset of the selected line
                         if N1 = tc then return tc -- it's the last paragraph
                         select paragraph N1 -- select next paragraph
                         set sel to (get selection)
                         if class of sel is list then
                            repeat with aItem in sel --  this line contains text and object
                               try
                                  if character offset of first character of aItem > C then return N1 - 1 -- return the index
                                  exit repeat -- else  character offset of the selection <= C , exit the repeat
                               end try -- error,aItem is not valid, continue the repeat
                            end repeat
                         else
                            try
                               if (character offset of first character of sel) > C then return N1 - 1 -- return the index
                            end try
                         end if
                         set N1 to N1 + 1
                      end repeat
                   end if
                end repeat
             end tell
          end getIndex
       end script
       tell application "Pages" to tell front document
          set sel to (get selection)
          if class of sel is list then -- selection contains object or  (Non-Continuous selection in the same line or in  différents lines).
             set charOffsetList to {}
             repeat with aItem in sel
                try
                   set end of charOffsetList to (character offset of aItem) -- get character offset of  the  valid item
                end try
             end repeat
          else -- insertion point or  the first line in continous text selection
             set charOffsetList to {character offset of sel}
          end if
          if charOffsetList is {} then return {} --  no valid item in the selection
          set indexList to {}
          repeat with C in charOffsetList
             set r to o's getIndex(C)
             if r is not in indexList then set end of indexList to r
          end repeat
          return indexList
       end tell
    end getIndexOfLinesInSelection

  • Create TOC javascript for indesign book

    Hi friends,
    i am new to indesign javascript. i want to create a javascript for TOC indesign book using paragrph style
    could anyone help me. i am strugling long time.

    "It didn't work for me" doesn't work for me. Always, always, always, state why it doesn't work for you.
    Did you try to use it, but could not get it to work?
    Or, do you need to do something special that the built-in function does not do?
    It should not be extremely hard to make a javascript version that does (roughly) the same. You could try something like this:
    For every paragraph style you want to include (most likely all sorts of headings),
    Search for all occurrences, and store the text, its page number, and (important!) its story offset in an array.
    You need the text because that's what will appear in the TOC.
    You need the page number because, well, that's what the TOC is for :-)
    Most important: you need the story offset so you can reconstitute the original order of the headings. You can only search for one level of heading at a time, so without sorting, you would get "Heading 1 -- Heading 1 -- Heading 1 -- Heading 2 -- Heading 2 -- Heading 2" (etc.)
    When you have gathered all of the information for your entire book, sort on story offset. (I forgot, it's for a Book, right? You need to store a document id as well, so you can sort throughout multiple documents.) (See Ed.)
    Then write out every text in the right order, followed by its page number.
    The IndexMatic script that Marc points out should already contains lots of the logic described here -- esp. searching and storing page numbers.
    [Ed.] Thinking about it, a Book (multiple documents) should *not* cause any problems, and you don't need to know in which document some text was found. Simply sort the paragraphs on their page number; only when these are the same for more than one paragraph, sort just these on their Story Offset. Logically, there should not be two headers with the same page number in two different documents.

  • Table Trouble

    Hi there
    I'm having a problem moving tables in Frame docs. Basically, we have a Frame API client which
    has to delete all the text in an FM or MIF file, before writing out a translated version of the text back
    to the document.
    As this process proceeds, non-textual objects in the document such as tables and anchored frames
    can be expected to move about the document. What I want to do is move tables back into their pre-text deletion position
    after the translated text has been put in place. For the most part it works, but in some documents
    strange problems occur, such as a table being written out 12 times successively, one after the other.
    Another problem that frequently occurs is that because translated text often uses more characters
    than the original, the text ends up wrapping around and below a table, where originally the table
    was below the text.
    Our current approach is to delete the normal text in the document,
    and if we find a table, we wrap the table's
    unique ID, object type, text offset and paragraph handle inside
    a struct, and pop that struct into a vector.
    After all the deletion and re-insertion of text is complete, we iterate through the vector,
    and compare the current location of each table in the vector to it's original location.
    If they differ, we then cut the table from its current position back to its original.
    Im guessing it's a bit more complicated than that to do it right though?
    Any comments or suggestions would be very much appreciated! 

    As an addendum, the code to reposition the tables is shown below:
    int o = 0;
    const int nMoveCount((int)m_aObjectsToMove.size());
    while(o < nMoveCount)
       Anchor a = m_aObjectsToMove[o];
       F_ObjHandleT hAnchor = F_ApiGetUniqueObject(m_hDocument, a.m_nObjectType, a.m_nUID);
       F_TextRangeT textRange;
       textRange.beg = F_ApiGetTextLoc(m_hDocument, hAnchor, FP_TextLoc);
       /* does the anchor' s current location differ
          from the location it was in when pushed into m_aObjectsToMove?
          If not don't move it!
          Problems will arise if anchors are cut from a paragraph which has no other content
          We never have to worry about this because in an empty paragraph an hAnchor tag cannot be moved
          if (textRange.beg.offset != a.m_nOffset)
             textRange.end.objId = textRange.beg.objId;
             textRange.end.offset = textRange.beg.offset+1;
             // Select the object
            if (a.m_nObjectType == FO_Tbl)
                F_ApiMakeTblSelection(m_hDocument, hAnchor, FF_SELECT_WHOLE_TABLE, 0, 0, 0);
                    else F_ApiSetTextRange(FV_SessionId, m_hDocument, FP_TextSelection, &textRange);
            F_ApiCut(m_hDocument, FF_CUT_TBL_CELLS);
            F_TextRangeT newRange;
            newRange.beg.objId = a.m_nPgf;
            newRange.end.objId = a.m_nPgf;
            if (a.m_nOffset > 0)
               newRange.beg.offset = a.m_nOffset-1;
               newRange.end.offset = a.m_nOffset-1;
            else
               newRange.beg.offset = a.m_nOffset;
               newRange.end.offset = a.m_nOffset;
            // Paste the hAnchor into its new position
            F_ApiSetTextRange(FV_SessionId, m_hDocument, FP_TextSelection, &newRange);
            F_ApiPaste(m_hDocument, FF_REPLACE_CELLS);
            o++;

  • Creating a TOC via script on InDesign Server [CS5.5]

    I have been struggling for about two weeks with trying to figure out how to script the creation of a TOC and an index for a book.  I've successfully created the book, and have also been able to create the table of contents, however I cannot place the contents in the book.  From the UI it's simple because it loads up the cursor with the TOC contents.  But in script, it simply provides an array with a single Story object.
    I have no idea how to make the story appear in my document.  Here's my current code:
    var book = app.open("book.indb");
    var doc = app.open("table_of_contents.indd");
    var tocStyle = doc.tocStyles.firstItem();
    var stories = doc.createTOC(tocStyle, true, book, ["1in", "1in"], false, doc.layers.firstItem());
    When I hit that final line, I get the following error:
    Invalid value for parameter 'destinationLayer' of method 'createTOC'. Expected Layer, but received Layer.
    Okay... so, if it's expecting a Layer and I'm providing a Layer - what gives?
    Originally I had figured that I:
    Had to create a TOC document from a template which contains a single text frame that automatically flows from page-to-page (using a master)
    Add the document to the book at the beginning
    Copy the contents of the Story into the TextFrame
    Iterate the Lines collection of the Story, copying the paragraph and character styles for each line
    This works, but it's no longer a TOCStory type.  I would like to maintain the TOCStory type and just have the content flowed into the new document which I add.  This makes sense, logically, but I know that nothing in InDesign is really that logical.  It seems to be a lot of collection manipulations, but I cannot figure out which collections to manipulate.
    The Index.generate() method seems so much more logical because the first argument is where to place the content.  If it were only that simple for the TOC!  If you've had experience doing this, please let me in on the secret...  I don't have access to the menu items so I cannot invoke actions.  Those threads don't seem to apply for InDesign Server (and that makes sense, since it's headless)
    Thanks,
    - Brett

    Hi Brett,
    here is the code that worked for me.
    Michael
    var bk=app.books.add(File("C:/Users/wwadmin/Desktop/testbook.indb"));
    for(i=0; i<5; i++){
    var doc=app.documents.add()
    var page=doc.pages.firstItem()
    var frame=page.textFrames.add({geometricBounds:[0,0,'10in','10in']})
    frame.contents="Hello World!!!!!";
    var style=doc.paragraphStyles.add({name:"Body"});
    frame.paragraphs.firstItem().appliedParagraphStyle=style;
    doc.save(new File("C:/Users/wwadmin/Desktop/doc"+i+".indd"))
    bk.bookContents.add(File("C:/Users/wwadmin/Desktop/doc"+i+".indd"));
    var doc=app.documents.add();
    var page=doc.pages.firstItem();
    style=doc.paragraphStyles.add({name:"Body"})
    tocstyle=doc.tocStyles.add({name:"myStyle"});
    tocstyle.tocStyleEntries.add({formatStyle:style, name:style.name});
    doc.save(new File("C:/Users/wwadmin/Desktop/test.indd"))
    bk.bookContents.add(File("C:/Users/wwadmin/Desktop/test.indd"));
    doc.createTOC(tocstyle, true, bk, undefined, true, doc.layers.firstItem())
    bk.save()
    for(a=app.documents.length-1; a>(-1); a--){
    app.documents[a].save(File(app.documents[a].fullName));
    app.documents[a].close();
    bk.close()

  • Alternate Object Styles?

    I have a document that requires the background colour changes per text frame.
    I was thinking an alternating object style would work best. But I can't figure out how to do it.
    I cannot use tables for this project!
    The layout is generally like this. The Text Frames will be threaded - and they must alternate colours each time a new heading appears.
    Has anyone come across a script like this before?
    1 Header
    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris a malesuada augue. Mauris blandit aliquet magna, sed sollicitudin justo aliquet vel. Sed dignissim dapibus sapien, ut varius tortor ultricies nec. Nam accumsan nulla eu leo ornare sed iaculis risus imperdiet. Donec nec pharetra lectus. Etiam at sollicitudin erat. Phasellus a consectetur magna. Nulla a nibh in mi tempus congue. Ut tempus, lacus id lacinia elementum, turpis urna pellentesque justo, vitae auctor dui arcu vitae eros. Nam eleifend blandit lorem facilisis pulvinar.
    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris a malesuada augue. Mauris blandit aliquet magna, sed sollicitudin justo aliquet vel. Sed dignissim dapibus sapien, ut varius tortor ultricies nec. Nam accumsan nulla eu leo ornare sed iaculis risus imperdiet. Donec nec pharetra lectus. Etiam at sollicitudin erat. Phasellus a consectetur magna. Nulla a nibh in mi tempus congue. Ut tempus, lacus id lacinia elementum, turpis urna pellentesque justo, vitae auctor dui arcu vitae eros. Nam eleifend blandit lorem facilisis pulvinar.
    2 Header
    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris a malesuada augue. Mauris blandit aliquet magna, sed sollicitudin justo aliquet vel. Sed dignissim dapibus sapien, ut varius tortor ultricies nec. Nam accumsan nulla eu leo ornare sed iaculis risus imperdiet. Donec nec pharetra lectus. Etiam at sollicitudin erat. Phasellus a consectetur magna. Nulla a nibh in mi tempus congue. Ut tempus, lacus id lacinia elementum, turpis urna pellentesque justo, vitae auctor dui arcu vitae eros. Nam eleifend blandit lorem facilisis pulvinar.
    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris a malesuada augue. Mauris blandit aliquet magna, sed sollicitudin justo aliquet vel. Sed dignissim dapibus sapien, ut varius tortor ultricies nec. Nam accumsan nulla eu leo ornare sed iaculis risus imperdiet. Donec nec pharetra lectus. Etiam at sollicitudin erat. Phasellus a consectetur magna. Nulla a nibh in mi tempus congue. Ut tempus, lacus id lacinia elementum, turpis urna pellentesque justo, vitae auctor dui arcu vitae eros. Nam eleifend blandit lorem facilisis pulvinar.
    3 Header
    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris a malesuada augue. Mauris blandit aliquet magna, sed sollicitudin justo aliquet vel. Sed dignissim dapibus sapien, ut varius tortor ultricies nec. Nam accumsan nulla eu leo ornare sed iaculis risus imperdiet. Donec nec pharetra lectus. Etiam at sollicitudin erat. Phasellus a consectetur magna. Nulla a nibh in mi tempus congue. Ut tempus, lacus id lacinia elementum, turpis urna pellentesque justo, vitae auctor dui arcu vitae eros. Nam eleifend blandit lorem facilisis pulvinar.
    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris a malesuada augue. Mauris blandit aliquet magna, sed sollicitudin justo aliquet vel. Sed dignissim dapibus sapien, ut varius tortor ultricies nec. Nam accumsan nulla eu leo ornare sed iaculis risus imperdiet. Donec nec pharetra lectus. Etiam at sollicitudin erat. Phasellus a consectetur magna. Nulla a nibh in mi tempus congue. Ut tempus, lacus id lacinia elementum, turpis urna pellentesque justo, vitae auctor dui arcu vitae eros. Nam eleifend blandit lorem facilisis pulvinar.
    4 Header
    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris a malesuada augue. Mauris blandit aliquet magna, sed sollicitudin justo aliquet vel. Sed dignissim dapibus sapien, ut varius tortor ultricies nec. Nam accumsan nulla eu leo ornare sed iaculis risus imperdiet. Donec nec pharetra lectus. Etiam at sollicitudin erat. Phasellus a consectetur magna. Nulla a nibh in mi tempus congue. Ut tempus, lacus id lacinia elementum, turpis urna pellentesque justo, vitae auctor dui arcu vitae eros. Nam eleifend blandit lorem facilisis pulvinar.
    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris a malesuada augue. Mauris blandit aliquet magna, sed sollicitudin justo aliquet vel. Sed dignissim dapibus sapien, ut varius tortor ultricies nec. Nam accumsan nulla eu leo ornare sed iaculis risus imperdiet. Donec nec pharetra lectus. Etiam at sollicitudin erat. Phasellus a consectetur magna. Nulla a nibh in mi tempus congue. Ut tempus, lacus id lacinia elementum, turpis urna pellentesque justo, vitae auctor dui arcu vitae eros. Nam eleifend blandit lorem facilisis pulvinar.

    Okay, here we go. The osList array contains the list of Object Style names -- you can put as many as you want in there, the used styles will be rotated automatically. The variable pstyle contains the name of the toggle paragraph style -- here it's "Heading".
    Click your text cursor inside any of the linked text frames so it knows where to start, then double-click the script to run. Enjoy!
    var osList = [
      "LightBlue",
      "DarkBlue"
    var pstyle = app.activeDocument.paragraphStyles.item("Heading");
    var current_os = 0;
    if (app.documents.length != 0 && app.selection != 0 && app.selection[0].hasOwnProperty("baseline"))
      story = app.selection[0].parentStory;
      // iterate over text containers
      for (i=0; i<story.textContainers.length; i++)
        // test if there is a paragraph style "Heading" in this frame
        styles = story.textContainers[i].paragraphs.everyItem().appliedParagraphStyle;
        for (j=0; j<styles.length; j++)
         if (styles[j] == pstyle)
          current_os = (current_os+1) % osList.length;
          break;
        story.textContainers[i].applyObjectStyle(app.activeDocument.objectStyles.item(osList[current_os]));

  • Get Text with Applied Style

    Hi all,
    I am using InDesign CS3 on OS 10.5. I'm trying to write something in Applescript that can look at a document and give me the text that has a certain applied style.
    For example, if a document contained the text "Hello, world" and had an applied paragraph style called "Greeting," then what I want is to use my script to tell that document something like this:
    tell application "Adobe Indesign CS3"
    set theDoc to document 1
    set theText to get every paragraph of theDoc whose applied paragraph style is "Greeting"
    end tell
    theText
    -->should return: "Hello, world"
    Obviously, I tried that script, but it doesn't work. I get the error "Adobe InDesign CS3 got an error: Cant get every paragraph of document "MyDocument.indd" whose applied paragraph style = "Greeting"."
    I'm not sure if I am just using the wrong commands or what. Any help is greatly appreciated!

    Hi Hayden,
    The trouble is, theDoc doesn't have paragraphs. If you open the InDesign dictionary and look at the document object, you'll see text frames, and you'll see stories, but no paragraphs. To get all of the paragraphs, you'd use something like this:
    set theText to every paragraph of every story
    But getting every paragraph of every story whose applied paragraph style is a specific style is harder to do using a filter ("whose") clause, because it has multiple conditions. Shane can probably do it, but I'm not having much luck. All the same, why bother? InDesign has a perfectly good find text method that will do what you want. Something like this:
    tell application "Adobe InDesign CS3"
    --Clear the find text preferences
    set find text preferences to nothing
    set applied paragraph style of find text preferences to paragraph style "Greeting" of document 1
    tell document 1
    set myFoundItems to find text
    end tell
    end tell
    Thanks,
    Ole

  • Move stories in XML

    Hi,
    I'm a newbie to scripting, and I'm wondering if someone can help me out.  I'm trying to write a script that will cluster two types of XML tags based on the numbers within them.  The tags are called "FigRef", and "FigCaption" respectively. 
    The figure references are disseminated throughout the text of the main stories. The captions are in separate "stories" in InDesign, and they appear at the end of the XML document.   What I want to do with scripting is move each caption story to the paragraph before the reference (see below).  I want the caption before the reference because in the final layout the captions are pushed out to the side with a float in CSS.
    The way I'd like it to appear:
    <story><FigCaption>Figure 1.1 This is the caption for Figure 1.1</FigCaption></story>
    <story>...Now examine <FigRef>Figure 1.1</FigRef>.  You can see that...</story>
    ...the way it is now:
    <story><paragraph>...Now examine <FigRef>Figure 1.1</FigRef>.  You can see that...</paragraph></story>
    <story><paragraph>...some other paragraphs</paragraph></story>
    <story><paragraph>...some other paragraphs</paragraph></story>
    <story><paragraph>...some other paragraphs</paragraph></story>
    <story><FigCaption>Figure 1.1 This is the caption for Figure 1.1</FigCaption></story>
    You can see an example of the final structure that I'd like to end up with from the picture attached.
    Thanks for any help!
    -ThisGuy

    I can make my question even more simple, by starting out with all the elements in the same story.  Can someone suggest a way to move each FigCaption to its corresponding FigRef?
    The way I'd like it to appear:
    <story>
    <paragraph>...some other paragraphs</paragraph>
    <paragraph>...some other paragraphs</paragraph>
    <paragraph>...some other paragraphs</paragraph>
    <FigCaption>Figure 1.1 This is the caption for Figure 1.1</FigCaption>
    <paragraph>...Now examine <FigRef>Figure 1.1</FigRef>.  You can see that...</paragraph>
    <paragraph>...some other paragraphs</paragraph>
    <paragraph>...some other paragraphs</paragraph>
    <paragraph>...some other paragraphs</paragraph>
    </story>
    ...the way it is now:
    <story>
    <paragraph>...some other paragraphs</paragraph>
    <paragraph>...some other paragraphs</paragraph>
    <paragraph>...some other paragraphs</paragraph>
    <paragraph>...Now examine <FigRef>Figure 1.1</FigRef>.  You can see that...</paragraph>
    <paragraph>...some other paragraphs</paragraph>
    <paragraph>...some other paragraphs</paragraph>
    <paragraph>...some other paragraphs</paragraph>
    <FigCaption>Figure 1.1 This is the caption for Figure 1.1</FigCaption>
    </story>

  • ID.CS3: Make Data Merge more useful?

    Data merge is a useful function of Indesign but its scriptability is limited. I've searched this forum and found some scripts that run a pre-linked ID document. I'm trying to script the linking of fields with known text strings.
    Looking at the dictionary I see that the only thing that has read/write is properties.
    My attempt to see what properties I can read/write seems to only point to its own reference.
    Is this part of data merge (assignin fields to text strings) just not scriptable? thanx, sam

    OK, here is my latest attempt to take what Olav's javascript uses and apply it to Applescript. I'm stuck on applying the myNamePlaceholder as notedby  by myNamePlaceholder:
    It yields no placeholder. But I believe I've done it right because I've followed the record generated when I manually make a placeholder and get the data merge text placeholders of document 1. What am I missing?
    thanx, sam
    set myTextFile to ("path:to:working:date.txt") as alias --I'm using a text file that works manually.
    tell application "Adobe InDesign CS3"
    set {find text preferences's find what, find change text options} to {"[Sample Name]", nothing}
    tell document 1
    tell data merge properties
    select data source data source file myTextFile
    set myDataMergeProperties to properties
    end tell
    set allObj to (find text)
    set objCt to count of allObj
    repeat with thisObj from 1 to objCt
    set NameObj to item thisObj of allObj
    set myStory to parent of NameObj
    set myFrame to parent text frames of NameObj
    set NameObjOffset to item -2 of insertion points of NameObj --of myFrame
    set dmFcount to count of every data merge field of data merge 1
    repeat with i from 1 to dmFcount
    if field name of data merge field i of data merge 1 is "FirstName" then set myNamefield to object reference of data merge field i of data merge 1
    end repeat --dmFcount
    set myNamePlaceholder to {story offset:NameObjOffset, field:myNamefield}
    set {myNamePlaceholder} to end of data merge text placeholders
    return properties of data merge text placeholders
    --yields {} if I have no placeholders manually made. If I have manually made a placeholder, it yields only the manually made placeholder. What am I missing?
    tell myStory
    end tell
    end repeat -- iterate over each instance of obj
    end tell --doc1
    end tell --app

  • [JS CS3] Need an array of paragraphs when more than one story

    Hello,
    If I have a document with only one story the following line returns an array of all the paragraphs. I can then iterate through the array to my hearts conent.
    var paraRef = app.activeDocument.stories.everyItem().paragraphs;
    However, if there is more than one story, then, according to the Data Browser, some of the object Paragraphs contain more than one paragraph and some of the object Paragraphs are invalid. The length of paraRef is correct, i.e. it equals the total number of paragraphs in the document, but each member of this array either  "bunched up" or contains nothing.
    How can I write this so that  when I have more than one story I can get an array of all the paragraphs?
    Thanks,
    Tom

    Thanks, Harbs and Dave!
    Before I saw your answers I came up with a (longer) solution:
    var storyRef = app.activeDocument.stories;
    var arrStories = [];
    for(var j = 0; storyRef.length > j; j++){
        arrStories.push(storyRef[j])
        }//end for
    var arrParas2 = [];
    for(var x = 0; arrStories.length > x; x++){
        for(var y = 0; arrStories[x].paragraphs.length > y; y++){
            arrParas2.push(arrStories[x].paragraphs[y]);
            }//end for y
        }//end for x
    But I am curious about something. Your solution and my solution both result in an array of all paragraphs in the document but the data browser shows these arrays in different ways. I am wondering how to intrepret them.
    Your solution does not show the indexed paragraphs, mine does. See the images below.
    Your solution:
    My solution:

Maybe you are looking for

  • Software updates and I tunes cards

    I would like to know why the I tunes cards in Canada cannot be used to purchase apps or updates for the Ipod touch. I am not interested in using my visa online so I paid 25.00 for a card that says for music and more but it doesn't seem to work with a

  • IPhone 4 is not recognized by my computer

    When I plug my iPhone into my computer, I get a pop up message that my computer does not recognize the device.  I tried unplugging it and re-plugging it in with no luck.  Any suggestions? 

  • Trouble with socket?

    Not perplexing enough but anyone have trouble with the recharge socket yet.not impressed so far.playbook. Subject Title edited to reflect new topic.

  • Multiple Browser Tabs(windows)

    Using ContentType = 'application/vnd.adobe.xdp+xml' to retrieve data to populate a livecycle pdf form triggers an additional browser window. What steps can I take to have the browser open the pdf in the same window. 'text.xml' displays in the same wi

  • Why does apple tv stop after 15 minutes

    after mirroring for about 15 minutes my apple tv ap shuts down? Anyone have any ideas. Both my Mac Pro and the Apple tv are new