Adding anchors based on the paragraph in Javascript Style

I've read over the documentation for days and just trying to understand how to add an anchor point to a paragraph in javascript style. That's what I have so far:

main() {} function

myDoc var = app.activeDocument;

var num_pars = myDoc.stories [0].paragraphs.length;

for (i = 0; i < num_pars; i ++) {}

If (myDoc.stories [0].paragraphs.item (i).appliedParagraphStyle.name == "Title") {}

aText = app.activeDocument.stories [0] .paragraphs [0];

aDest = app.activeDocument.hyperlinkTextDestinations.add(aText,{name:aText.contents});)

}

}

}

What I am doing wrong?

I thought about it! Thanks for your help! Here is the final code for anyone who could find that I couldn't find before:

main() {} function

myDoc var = app.activeDocument;

var anchorsAddedCnt = 0;

app.findGrepPreferences.appliedParagraphStyle = "Title";

app.findGrepPreferences.findWhat = "^."

var myTitleResult = myDoc.findGrep ();

for (i = 0; i< mytitleresult.length;="" i++="" )="">

var anchor = myDoc.hyperlinkTextDestinations.add (myTitleResult [i]);

Anchor.Name = "A00.01.00";

Anchor.label = "A00.01.00";

anchorsAddedCnt += 1;

}

Alert ("Added" + anchorsAddedCnt + "anchors");

$.writeln ("Added" + anchorsAddedCnt + "anchors");

}

main();

Tags: InDesign

Similar Questions

  • Graphic object based on the paragraph Style style?

    I just checked the documentation of the API and saw nothing on the point about this.

    Is it possible to write a script that applies a Style object to a jpg image based on the paragraph Style applied to this image jpg online online?

    Hello

    I did the following:

    var curDoc = app.activeDocument;
    
    app.findGrepPreferences = app.changeGrepPreferences = null;
    app.findGrepPreferences.findWhat= "~a";
    var allFounds = curDoc.findGrep();
    
    for (var i = 0; i < allFounds.length; i++) {
      var curFound = allFounds[i];
      if (curFound.allGraphics.length > 0) {
        var pStyleName = curFound.paragraphs[0].appliedParagraphStyle.name;
        if (pStyleName == "paraStyle") {
          var rect = curFound.rectangles[0];
          rect.appliedObjectStyle = curDoc.objectStyles.itemByName("myStyle");
        }
      }
    }
    

    Kai

  • second line to the paragraph indented using styles?

    made anyone know if its possible in Indesign to do the second line of the paragraph indented using styles?

    I'm working on a book and I put the first word of each paragraph to be slightly larger and a different font to the rest of the paragraph. I did it using a style nested with the paragraph style. I also want to do what the second line is indented from the amount of space to the first word on the first line. This isn't problem doing this maunally but I want to find a way to define a style for this so that I can compose the book like this.

    any help is appreciated!

    Looks like you're talking to "drop words".

    On this page: http://in-tools.com/plugin.php?p=24

    In addition to the commercial product, there is a (simpler) free script on the page to create using drop caps.

    Substances

  • CS3: need script to replace spaces with underscores in the paragraph and character style names

    Help! I am very new to scripting.

    I managed to find and tweak existing javascripts to search through all my paragraph styles to disable hyphenation and off balance the jagged lines, but I need help with this one.

    I work on Mac OS 10.4.11 using Indesign CS3.

    I need a script that will search all my paragraph and character styles in my open Active document and replace spaces by underscores.

    Can someone help me with this? It would be greatly appreciated!

    1. I don't know, but I think you can use all the regular GREP inside this function codes. Do not use the quotation marks around of the expression, use slashes! (Why? Just a curiosity of Javascript... maybe a hack that goes back to the gray mist of JS development...)

    This work should - but rather the code above, this is not tested:

    .. Replace (/ [-\ / ()-. _] + / g. '_');

    The GOLD group inbetween the brackets contain all the characters you want to replace with an underscore: the hyphen (this has to be the first character in the group, else it will be interpreted as a range of characters from each side!), space, slash (this one is 'special' inside the function replace JavaScript, so I think he needs to escape with a backslash)! in parentheses, a period (not sure if it should escape - into ordinary GREP, it's the wildcard character for any character, but maybe he loses his magic within a group of GOLD) and finally... the underscore character. Why?

    Well, this replacement string comes with a free bonus. Note the sign after the installment of GOLD +. This means that a whole sequence of these characters is replaced by a simple underscore: "it's / a - / test" will become "This_is_a_test". Adding the underscore line itself to the string of research means that it will also find the whole chain 'space space (stroke underscore)' in 'This style (_)' and, oh magic!, replace it immediately with a single underscore.

    Just FYI, the tiny "g" after the closing slash is abbreviation of 'global', i.e. at the global level, replacing in this string. replace the default values for a replacement only (why? see above...), and adding the 'g' ensures he keeps replacing until it is not find matches more.

    2 see point 1.

    3. uh, yes it's true, but you will need to check very carefully if nothing inside one of these basic models is substituted. You can apply a base style and add substitutions to make look like a subtitle, but that isn't making it a. And to the next paragraph, you can apply a base style and add substitutions to make it look like a paragraph of plain text (etc.). It's a signature of witness to bad formatting...

  • [JS] Copy or move the paragraph and character style style

    Hello
    I try to transfer paragraphs a the document to a block a second document but I have hugs the style of paragraph et style character applied.
    I use this command line:


    o.leBlocLegendes.contents = o.leBlocLegendes.contents + leDocument.stories.firstItem().paragraphs[leConteurPara].contents;
    
    


    How do I do not lose anything?

    Thank you


    Original message

    Hello

    I am trying to transfer of the paragraphs in a document to a block of a second document but I loses all the style of paragraph and style of applied character.

    Plug-in this command line:

    o.leBlocLegendes.contents = o.leBlocLegendes.contents + leDocument.stories.firstItem().paragraphs[leConteurPara].contents;
    

    Comment do pay nothing lose?

    Thank you

    Hi Liphou,

    .silence is indeed a property of type string only disregardingly of styles, anchor frames and other animals.

    You prefer the use of object methods and duplicate stories. However styles can be substituted with the target document. If you can load styles before the duplication of the text.

    var main = function() {
        var doc, st, tempDoc, f, tf;
        if (!app.documents.length
            || app.selection.length!=1
            || !app.selection[0].properties.parentStory) {
            alert("You need to select text or text frame");
            return;
        }
    
        doc = app.activeDocument;
    
        if ( !doc.properties.fullName ) {
            alert("Please save file first !");
            return;
        }
    
        st = app.selection[0].parentStory;
        f = File ( doc.fullName );
        tempDoc = app.documents.add();
        tempDoc. importStyles ( ImportFormat.TEXT_STYLES_FORMAT, f, GlobalClashResolutionStrategy.LOAD_ALL_WITH_OVERWRITE );
    
        tf = tempDoc.textFrames.add();
        st.duplicate(LocationOptions.AT_BEGINNING, tf.insertionPoints[0]);
        tf.fit(FitOptions.FRAME_TO_CONTENT);
    
    }
    
    main();
    

    HTH,

    Loïc

    www.ozalto.com

  • Help about the paragraph and character styles scriptting

    Hi all

    I'm working on a project with many files, I change change on all styles of paragraph with multiple processes

    for ex, change the font for all styles of paragraph on all open documents

              var docs = app.documents;  
                     
              for (var d = docs.length-1; d >= 0; d--) {  
                      var doc=docs[d]; 
                      
    var pstyles = doc.allParagraphStyles;  
    for (var a = 1; a < pstyles.length; a++) {    
                              if (pstyles[a].appliedFont.name=="Arial\tBold")    
                                   pstyles[a].appliedFont = "Arial\tBold Italic";    
                         }
                     }
    

    but I found a text inside frames (the locked position) my find/replace a not to apply to this topic

    so, is there anyway to do this process for all chassis from locked position?

    or at least make the lock of the United Nations to all open documents, but I can only do this for the active doc

    app.activeDocument.pageItems.everyItem (.locked = false)

    Another thing, I tried to change it on all styles of character on the files and I wrote the code with my little knowledge script but it seems does not, any hint please?

              var docs = app.documents;  
                     
              for (var d = docs.length-1; d >= 0; d--) {  
                      var doc=docs[d]; 
                      
    var cstyles = doc.allCharacterStyles;  
    for (var a = 1; a < cstyles.length; a++) {    
                              if (cstyles[a].appliedFont.name=="Arial\tBold")    
                                   cstyles[a].appliedFont = "Arial\tBold Italic";  
                         }
    }
             }  
    

    Thanks in advance

    Maybe your consolidated text block... Try this

    docs var = app.documents.

    for (var docs.length - 1; d = d > = 0; d-) {}

    var doc = docs [d];

    var pgItems = doc.allPageItems;

    for (var a = 0;< pgitems.length;="" a++)="">

    If (pgItems [a] instanceof TextFrame) {}

    While (doc.groups.length > 0)

    doc.groups.everyItem () .ungroup ();

    pgItems [a] .locked = false;      }

    }

    }

  • Change the paragraph by Script Style

    Hello!

    I don't know if this is the right place for this question but since its related to scripting, I'll ask here.

    Is it possible to change the paragraph Styles InDesign with a Script?

    For example, I need set Format1 hyphenation to specific values properties without changing the other properties. For Format2, I need to change other properties such as the Glph scaling.

    Like I need to do this with a lot of files, I suppose that the best way to archive it could be a script.

    Is there someone who had an idea on how to do it?

    Thanks in advance

    Thomas

    You're right, this can be done very effectively with a (relatively) simple script. This is an excerpt from a longer script of mine which covers a changing choice of design of end minutes documents open at once:

    for (i=0; i
    

    For a list of all paragraph properties that you can change, look in the ESTK help or (in a more user-friendly way to read and search) in an online version of these same data: InDesign ExtendScript API (10.0).

  • How to apply an object style based on the paragraph style?

    Having a job where a single page with a frame of 3 columns is repeated many times.

    (He is always alone and behind a title page)

    But this system is not very good if the text follows... Formatting is lost.

    Of course, anchored frames should be a solution but I could prefer to apply a definition of the structure of text (just the 3 columns) with the f/change of menu:

    My page 3 columns that have a style always will be, this definition of the image.

    In anchored frames, insert a return to get on the next page is by default?

    Why you do not use * Span/Split columns * in your paragraph styles?

  • Adding conditional based on the checkbox

    I have a field that adds the values of several other fields in the form.  The question I have is how can I add another 2 If a certain checkbox is visible and active?

    Hello

    You would need an if/else statement that looks at the value of the checkbox.

    This could be in the event to calculate the field which displays the answer:

    var tempAnswer = numericfield1.rawValue + numericfield2.rawValue + numericfield3.rawValue;
    
    if (checkbox.presence == "visible" && checkbox.rawValue == 1)
    {
         tempAnswer = tempAnswer + numericfield4.rawValue + numericfield5.rawValue;
    }
    
    this.rawValue = tempAnswer;
    

    You would need to change the object references, etc, but it should give you a structure to work with. We have examples here, some of which include objects with calculation scripts: http://assure.ly/eEPuCM

    Hope that helps,

    Niall

  • Retrieves the paragraph formatting with style name

    All the

    kindly help me how to extract the name of definition with example.txt formatting:

    FOR EXAMPLE:

    Name of the style: "Body".

    Font = "15".

    head = "" 18"" "

    Aligh = "Left".

    etc...

    Concerning

    Hurix

    Change by Dave Saunders: something prevents the work answer button. I hope that this edition will reactivate it.

    Hi Hurix,

    Welcome.

    Please indicate the question as answered

    Add the properties you need by following the instructions in the 3rd line.

    Trevor

    // Export Specified Details of Documents ParagraphStyles By Trevor
    // http://forums.adobe.com/thread/1445961?tstart=0
    exportParagraphStyleDetails ("appliedFont pointSize spaceAfter spaceBefore"); // add property names separated by a space - The Style Name is included automatically
    // see http://jongware.mit.edu/idcs6js/pc_ParagraphStyle.html for a list of properties you can add
    
    function exportParagraphStyleDetails (props /* A string list of the desired properties */) {
        doc = app.activeDocument,
        ps = doc.paragraphStyles.everyItem().getElements().slice(0),
        l = ps.length,
        c = 0;
        props = props.replace(/\s+/g, " ").split(" ");
        pl = props.length;
            var styleDetails = [];
        while (l--) {
            var  myStyle = ps[l];
            styleDetails[c++] = "******************************************************************\rParagraph Style Name: " + myStyle.name + "\r******************************************************************"
            for (var n = 0; n < pl; n++) {
                styleDetails[c] = props[n] + ": " + myStyle[props[n]].toString();
                if (myStyle[props[n]].hasOwnProperty ("name")) styleDetails[c] = styleDetails[c].replace (/:.+/, ".name: " + myStyle[props[n]].name);
                c++;
            }
        styleDetails[c++] = "\r";
        }
    
        temp = new File (Folder (Folder.temp) + "/" + doc.name + " Paragraph Style Properties " + ("" + new Date).replace(/:/g,"\xB7").replace(/G\S+$/,"")+ ".txt");
        temp.encoding = "UTF-8";
        temp.lineFeed = ($.os[0]=="M") ? "Macintosh" :" Windows";
        temp.open('w');
        temp.write("\uFEFF" + styleDetails.join("\r"));
        temp.close();
        $.sleep(300);
        temp.execute();
    }
    
  • Problem updated to a position of the element using javascript style.top estate version 4.6

    I develop a scrolling of content when the user clicks on an item, the program triggers the event and moves the content, it works perfectly in a device with the 5.0 version of the software, but in devices with software version 4.6 doesn't work

    No trigger that any error just doesn't work

    Here's him sew:

    var pag1 is document.getElementById ('page1');.

    function that removes "px" for the calculation

    function quitapx (str) {}
    return str.replace('px',"")
    }

    function that moves the item (pag1) upwards or downwards

    mueve function (o) {}
    var dir = o.dir;
    posT = Number (quitapx (pag1.style.top))
    If (dir =-1) {}
    If (posT<>
                    PAG1.style.top = posT + 64 + 'px ';
    }
    }
    If (dir = 1) {}
    If (posT > program) {}
                   PAG1.style.top = posT - 64 + 'px '.
    }
    }
    } //mueve1

    clues?

    I already found the problem.

    The first time that the user clicks to move the content, the pag1.style.top property is set to null, in the browser with version 5.0 software ignores and starts running, but in the browser with version 4.6 software detect zero and stop the script.

    the solution I use is

    If (pag1.style.top! == null) {}
    posT = Number (quitapx (pag1.style.top));
    } else {}
    posT = 0;
    }

    And work! Here is a picture.

  • Tables of contents, not the substitution of character styles applied in chapters

    My table of contents uses not the style of input I select words in the paragraphs that have styles of characters that are applied in the chapter, so some letters, more precisely the parameters, displayed in green, which is well in the chapter but not in the table of contents. I can manually fix this in the table of contents by changing the character to any style after the table of contents was generated, but I don't want to do that. I think it has to happen automatically.

    This should do it:

    (?<=\()[\w, \w)]*(?="">

    It searches the text in parentheses without selecting them.

  • When you use the pen tool when I click and create an anchor point and release the mouse button the pen tool emerges from the anchor and allow me to go and select a new anchor point. The right pen tool keeps adding lines that I move the mouse.

    When you use the pen tool when I click and create an anchor point and release the mouse button the pen tool emerges from the anchor and allow me to go and select a new anchor point. The right pen tool keeps adding lines that I move the mouse.  How can I get the pen tool to release the anchor

    Try this.go in the menus. Select cc illustrator > preferences > display selection & anchor > then make sure the box "activate the rubber band for" the pen tool is not selected. Then press OK. It should work.

  • I would like to add bookmarks, based on the name of the original file when combining PDFs using Javascript.

    I am combining hundreds of original 1-page PDF files in dozens of PDF files. I generated the JavaScript to do this. However, I would like to add bookmarks for some pages, based on the name of the name of the file from this page. Here is a sample of my script combining:

    var currDoc = app.openDoc ("C:/report/December 2015 / Insert Plan SD." "") "'PDF');

    currDoc.insertPages ({nPage:-1, cPath: "C:/report/December 2015 / RPM RPM/K001. PDF"});

    currDoc.insertPages ({nPage:-1, cPath: "C:/report/December 2015 / output / K001 ROCHESTER."}) PDF"});

    currDoc.insertPages ({nPage:-1, cPath: "C:/report/December 2015 / Insert Plan.PDF '});

    currDoc.insertPages ({nPage:-1, cPath: "C:/report/December 2015 / RPM/L002 RPE."}) PDF"});

    currDoc.insertPages ({nPage:-1, cPath: "C:/report/December 2015 / output / L002 BOSTON."}) PDF"});

    currDoc.insertPages ({nPage:-1, cPath: "C:/report/December 2015/Maps/10_Map3.PDF"});

    currDoc.insertPages ({nPage:-1, cPath: "C:/report/December 2015/Maps/10_Map2.PDF"});

    currDoc.insertPages ({nPage:-1, cPath: "C:/report/December 2015/Maps/10_Map1.PDF"});

    currDoc.insertPages ({nPage:-1, cPath: "C:/report/December 2015 / Comp Brand/10_KReport1.PDF"});

    currDoc.insertPages ({nPage:-1, cPath: "C:/report/December 2015 / Comp Brand/10_LReport1.PDF"});

    currDoc.saveAs ({cPath: "C:/report/December 2015 / Final / 10 2015 Review.PDF area"});

    currDoc.closeDoc (true);

    Take a look on the Bookmark object and methods associated with it.

  • How can I take an anchored frame and return the paragraph tag used?

    I need to analyze through anchored frames and return the tag of paragraph that it is spotted. I can't find a property which returns the paragraph tag. Anyone have any ideas?

    Try this on the anchored frame selected:

    #target framemaker
    
    var doc = app.ActiveDoc;
    var aFrame = doc.FirstSelectedGraphicInDoc;
    var pgf = aFrame.TextLoc.obj;
    
    alert (pgf.Name);
    

    Rick

Maybe you are looking for