CS5: Hyperlink to anchor text in the character style?

Is it possible to script the following:

A text has several occurrences of the same string, for example "A10". One is marked with a character style "Anchor" and others are marked by a character style "link." The idea is to create anchors text style "Anchor" then find all occurrences of the character 'Link' style and create a hyperlink to the corresponding anchor.

I managed to find a script that creates a character style "Anchor" text anchors Can anyone offer suggestions on how to make script creating the links?

Written by Kasyan Servetsky

March 13, 2011

// http://www.Kasyan.HO.com.UA

/ / e-mail: [email protected]

//======================================================================================== =================================

If (app.documents.length == 0) ErrorExit ("Please open a document and try again.");

const gScriptName = "create anchor text."

const gScriptVersion = "1.0";

gDoc var = app.activeDocument;

If (! gDoc.characterStyles.item("Anchor").isValid) ErrorExit ("Character style \"Anchor\"n'existe No.");

CreateDestinations();

//======================================================== FUNCTIONS  =====================================================

function CreateDestinations() {}

app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.nothing;

app.findGrepPreferences.findWhat = '. '. + » ;

app.findGrepPreferences.appliedCharacterStyle = gDoc.characterStyles.item ("Anchor");

var found = gDoc.findGrep ();

var destCounter = 0;

for (var j = finds.length - 1; j > = 0; j-) {}

var found = found [j];

try {}

If (! gDoc.hyperlinkTextDestinations.itemByName (found.contents) .isValid) {}

var hypTextDest = gDoc.hyperlinkTextDestinations.add (found);

hypTextDest.name = found.contents;

destCounter ++;

}

}

{catch (e)}

}

If (destCounter == 0) {}

Alert ("no anchor text were created.", gScriptName + "-" + gScriptVersion);

}

Else if (destCounter == 1) {}

Alert ("a text anchor is created.", gScriptName + "-" + gScriptVersion);

}

ElseIf (destCounter > 1) {}

Alert (destCounter "text anchors have been created.", gScriptName + "-" + gScriptVersion);

}

}

//---------------------------------------------------------------------------------------- ----------------------------------------------------------------

function ErrorExit (error, icon) {}

warning (error, gScriptName + "-" + gScriptVersion, icon);

Exit();

}

//---------------------------------------------------------------------------------------- ----------------------------------------------------------------

Hello

The path is:

create a hyperlinkTextDestination;

create a hyperlinkTextSources;

Create hyperlinks using a single destination and sources;

so:

// to create hyperlinks alike:    one destination==>many sources
// destination is the 1st occurrence of text with charStyle "anchor" applied
// sources are each occurrences of text with charStyle "link" applied

var mDoc = app.activeDocument;

app.findTextPreferences = app.changeTextPreferences = NothingEnum.nothing;
app.findTextPreferences.appliedCharacterStyle = mDoc.characterStyles.item("anchor");

var
     mAnchor = mDoc.findText()[0],
     mDest;

if (mAnchor) mDest = mDoc.hyperlinkTextDestinations.add(mAnchor,{name: mAnchor.words[0].contents});
else {alert ("no anchor found"); exit(); }

app.findTextPreferences.appliedCharacterStyle = mDoc.characterStyles.item("link");

var
     mSource = mDoc.findText(),
     len = mSource.length,
     currSource, currHyper;

if (!len) {alert ("no link found"); exit(); }

while (len-->0) {
     currSource = mDoc.hyperlinkTextSources.add(mSource[len],{name: "sourceLink_" + len});
     currHyper = mDoc.hyperlinks.add(currSource, mDest, {name: "mHyperlink_" + mDest.name + "_" + len});
     }

app.findTextPreferences = app.changeTextPreferences = NothingEnum.nothing;

Jarek

Tags: InDesign

Similar Questions

  • Need help! -Photoshop - can't change the size of the text in the character Panel

    Then all of a sudden, I am unable to change the size of the text in the character Panel. I select the text in my document, then go in the character Panel and type in let say "55"... but is not type it in Control Panel... it Pat on the current document in the selected type - like ill have a selected phrase and then it will be replaced by 55... It also happens in the areas of kerning value and leader of the group - does anyone know what is happening? Ive handed in market and update photoshop... maybe I hit something that blocks? I've never known my life of complete photoshop user

    I'm on CC 2015.1.2

    But I think that his work now... I just is gone in the Charter Panel and clicked on the 'fractional' in and out 'reset the character' and now it seems to work normally... how strange

  • My paragraph styles have disappeared and are now appearing as the character styles

    Working on a new site because my old site muse become buggy...

    and now, my paragraph styles have disappeared and are now appearing as the character styles

    Screen Shot 2015-10-13 at 5.07.55 PM.png

    Thank you for sending the files. One of the files does not contain any character or paragraph Styles. In the other, I see the character styles named as paragraph styles. All indications from within the file are that they were created as character styles. The file format includes indications of the type of the style as well on everything that they are applied and in the list displayed in the palette. All of these styles are indicated by styles of characters in both places. The attributes that are in the styles are limited to what is allowed in a character style.

    In some places where the styles are applied, they are applied to the blocks of text or widget and replacements parts for paragraph-level attributes (i.e. h1 tag, space before and after, etc.). This leads me to suspect that they have can be created from blocks of text pointer tool selections (or other elements of text in widgets) and it was perhaps accidental that they have created using character Styles where paragraph Styles Panel rather than the Panel?

  • How to write the script to apply the character style?

    Hello

    I'm on a Macbook pro and without a numeric keypad, so I can't assign a shortcut to character styles. I heard a roundabout solution where you can assign a shortcut to a script that applies the character styles. Can anyone write this script?

    My character style is called "features"bold. "

    I am new to scripting, sorry if this is a stupid question.

    See you soon

    Hello

    1. save this code as a file inside your Script Panel folder .jsx

    2. apply a shortcut using the menu Edit: shortcuts...

    Option to choose:

    • suggest you choose an option 'background': 'Text', so you can use several shortcuts that are occupied in other contexts.
    #target indesign
    if (app.selection && app.selection[0].hasOwnProperty ("baselineShift") ) {
      var cName = "Features bold";
      var mCstyle = app.activeDocument.characterStyles.item(cName);
      if (mCstyle.isValid)
           app.selection[0].applyCharacterStyle(mCstyle);
      else
           alert ("CharStyle: " + cName + " not found");
      }
    else
      alert ("Some text supposed to be selected...");
    

    Jarek

  • Apply the character style to the part of the paragraph

    I am inserting text in a block of text with the following code:

    story.insertionPoints [-1] .silence += pgfStr;

    story.insertionPoints [-1] .silence += "\t";

    story.insertionPoints [-1] .silence += refStr;

    story.insertionPoints [-1] .silence += "\r";

    I want to apply the character style to all of the text in refStr (only the part of this paragraph). I know how the syling paragraph applies to the entire paragraph, but not a character style. I should be grateful if you would help. Thank you!

    Hello

    Dan - BTP says:

    ... the size in points and attack can be different on each page...

    You are able to find a rule of these differences?

    ...

    What do depends on what type of rule could be defined

    ...

    The size of reference point that is 1.5 PT lower than the point size of the paragraph, whatever.

    Close to the end of the script, you can code for example:

         //     Your target is "reference" which is a text inbetween tabulator and end of story (or other criteria).
         //     So you could define:
    app.findGrepPreferences = null;      // just for clear it
    app.findGrepPreferences.findWhat = "(?<=\\t).+\\s\\Z";     //     to catch text following tab in last para of story
         //     and after:
    mFound = app.activeDocument.findGrep();
         //     so all desired text objects are in an array "mFound".
         //     you could iterate (backward) through it:
    len = mFound.length;
    while (len-->0)      //     ">0" in case of nothing found
         mFound[len].pointSize -= 1.5;
    
         //     whatever that is - is 1.5 smaller
    

    Jarek

  • Selection of parts and columns, or entire lines and apply the character style

    I am trying to apply character styles to certain parts/whole rows and columns.

    I can change individual cells with the following code...

    table = app.selection[0];
    if (table.hasOwnProperty("baseline")) table = table.parent;
    if (table instanceof Cell) table = table.parent;
    if (table instanceof Column) table = table.parent;
    if (table instanceof Row) table = table.parent;
    if (table instanceof Table)
    
    {
     table.rows[0].cells[6].texts[0].appliedCharacterStyle = "none report";
     }
    

    ... but when I try to select an entire line, I get the error 'Object does not support property or method' texts. "" "When I try one of the following two codes.

    {
     table.rows[0].cells.texts.appliedCharacterStyle = "none report";
     }
    

    {
     table.rows[0].cells.appliedCharacterStyle = "none report";
     }
    

    Anyone know how I can do the following?

    1. Select any row (or column) and apply the character style

    2. Select the last line (regardless of the number of rows in the table) and apply the character style

    3. apply the character style to specific columns (with theexception of the cells of two albums)

    Thank you!

    Hello

    Change this line:

    table.columns[a].cells.itemByRange(2,-1).texts.everyItem().appliedCharacterStyle = "chart orange";
    

    for the first 2 rows in each column

    Jarek

  • Apply the character Style to a few characters in a paragraph

    Hey,.

    Me again - I feel like I'm dumber than a shoe trying to script InDesign

    I have a block of text with several paragraphs, which I am adding one by one.

    When adding these paragraphs, sometimes I need to apply a character style to some of the characters in the paragraph (I have the clues start and end of these characters to the text of the paragraph).

    Using the Guide of the script and the object reference, I cooked up this code below, but not only it doesn't seem to find the character style, she also told me the. itemByRange() is not a function...

    What's wrong?

    var line_styles = [{
        'start': 22,
        'end': 33,
        'style': 'Price - SKU'
    }];
    
    frame.contents += "\r" + line_text;
    frame.parentStory.paragraphs[-1].applyParagraphStyle(style);
    
    for ( var j = 0, k = line_styles.length; j < k; j++ ) {
        var char_style = doc.characterStyles.item(line_styles[j].style);
        frame.parentStory.paragraphs[-1].itemByRange(
            line_styles[j].start,
            line_styles[j].end
        ).applyCharacterStyle(char_style, true);
    }
    

    frame.parentStory.paragraphs[-1].itemByRange(...

    does not compute. "paragraphs [-1]" points to a single paragraph and is not an itemByRange method. You must think of sth like

    frame.parentStory.paragraphs[-1].characters.itemByRange(...

    (Have you used another programming language Javascript front?) A matter of concern for the future: pay attention to your statements 'var '. They do not follow the block scope, as they do in other languages, and therefore persisted in this notation is very likely to bite you back somewhere in the future. Summer, done this, released as well the hair).

  • How can I set small caps in the character style

    I use the opportunity that you people are online:

    I'm trying to define small caps in the character style and it does not work,

    It works in the paragraph style, why is this? and is it possible around it?

    I can see the option in the character Styles: isn't it of menu drop-down available in your dialog box?

  • Table of contents, problems in applying the character style

    Hi all

    This is my first post, I checked if there was already something similar, but I can't find anything so I'm asking here.

    I work with Indesign 9.3 and I created a book of 80 pages and there are 20 + chapters.

    I wanted to create a table of contents, so I made an and I put my paragraph for her style, but I had problems to set the character style (he set only to the number of the page, but not to the number and the name of the chapter).

    When I create my summary style I have no problem to indicate the paragraph style that you want to use (and then it automatically applies it properly when I generate my list).

    The problem I want to solve, is that I need that my table of contents automatically the value of the character style, cause, for the moment, I have to apply it after its generation.

    Sorry for my bad English, I hope you understood

    Concerning

    Filippo

    In this case you must use the character for numers style nested within the paragraph style

    I'm usually two independent sparagraph styles (primary materials) chapters and sections (toc details). In this way, you can add a different same nested character style to stand them.

    Addibn later - style, it is not good idea. After the update of the table of contents, you have lost the

    macpawel

  • Why FM lose the hyperlink works in TOC after the character formats? Or is there a workaround?

    I work in a FrameMaker book.

    Chapter 1 uses heading1 while in the text for Heading1 there is a letter setting out with a character format "sup".

    In the table of contents (TOC), I find the letter outlining perfectly once again, but the hyperlink is no longer.

    Example:

    Hello, this is my < sup > top negative > title 1 title

    In OCD I also find the same text properly, but of the 'up' to the end of the line, the hypertext link no longer works. In FrameMaker or PDF file, I write.

    I tested it with FrameMaker 12 and 13 in the German version and on FrameMaker 7.2 English version.

    Is there a solution?

    Hmmm. I'm guessing that the solution is to fix in Acrobat after you create the final PDF file with the link tool. Here is the operation of text links in FrameMaker:

    • If a Hypertext marker is a paratrooper without a character tag, the whole paragraph is the hotspot.
    • If a hyperlink marker is inside a character in Pará, the hotspot is the limits of the character tag.

    In your situation, the marker will appear at the beginning of the line and the character tag is also across the page and it didn't is not in any way that I know to change.

    Framemaker TOC with hyperlinks incompatible - roundpeg Blog

  • Rotate the text with the character within the text block style

    I would like to apply a paragraph or character style to a certain character in a text frame. I would need to rotate 90 degrees in the framework, separate from the other text. Is this possible?

    Insert the text block in the block of text as an anchor and rotation you need.

  • Center anchor text by the expression

    Hello! This is my first post, so I'm sorry if I've caused a lot of facepalm.

    I wanted to center the anchor point of the text in an expression. What I did:

    X = this.sourceRectAtTime () .width/2;

    Y = this.sourceRectAtTime () .height/2;

    [X, Y]

    It almost does the job... However, there is a small gap. I tried to understand, and it seems that (0,0) of the anchor point does not correspond to the lower left corner, but instead has a small shift, usually less than 5. In addition, this shift seems to change depending on the font and text.

    How can I make an expression that tackling this problem and place the anchor point in the center of the text dead?

    Of course you can use monospaced fonts or design your own and simply add and subtract values, but disappeared completely, you'll always have situations where the visual cenrter has nothing to do with the calculated actual Center. Others you can find info without end about how the various parameters of the fonts and their relationships each n how to calculate them, but it is far from trivial, then I would advise against. In more than 15 years using AE I have never had the need nor the desire to enter into that kind of thing. It is much more important to find good fonts in the first instance, both in technical and aesthetic sense.

    Mylenium

  • Jump to an anchor text to the DPS

    Hello

    I believe that I correctly added an anchor of the text on a page in an article in my DPS folio. However, create a button to access this anchor text does not work when I test in Adobe Content Viewer. Any suggestion as to what I'm doing wrong?

    Thanks in advance.

    Text anchors are not supported in DPS.

  • Is it possible to add text to the cells and apply the character style in the cell

    I work in InDesign on Mac 5.

    I have two tables of formatting with information that will be eventually combined. I implemented the scripts I found on these forums to add the columns needed, merge lines and fill the cells merged with the appropriate color, but can't two remaining tasks.

    1. is it possible to add text to a cell of some?

    2 and it is possible to apply a character style to cells? (different cells than those that I need to add some text)

    I played with this code but do not know if it is even close...

    {

    table. Rows [0]. Cells [0]. InsertText (' CS/PS");

    }

    {

    table. Rows [0]. Cells [0] .appliedCharacterStyle ("bold");

    }

    Here are the scripts that I have combined so far for the table...

    Add column

    myTable = app.selection [0];

    MyColumn = myTable.columns [1];

    for (a = 0; < 1; a ++)

    {

    myTable.columns.add (LocationOptions.AFTER, myColumn);

    }

    Merge lines

    table = app.selection [0];

    If (table.hasOwnProperty ("baseline") table) = table.parent;

    If (instanceof cell table) table = table.parent;

    If (instanceof column table) table = table.parent;

    If (instanceof row table) table = table.parent;

    If (instanceof Table table)

    {

    table. Rows [0]. Cells [0]. Merge (table.rows [0] .cells [1]);

    }

    {

    colours alternating in merged lines

    r = table.rows [1];

    n = app.activeDocument.swatches.item ("orange");

    b = app.activeDocument.swatches.item ("PANTONE 3005 C");

    for (c = 0; c < r.cells.length; c ++)

    {

    If (c & 1)

    r.Cells [c]. Properties = {fillColor:b};

    on the other

    r.Cells [c]. FillColor = n;

    }

    }

    Hello

    1. If you want to add the text, go further in:

    table. Rows [0]. Cells [0] .insertionPoints [0] .silence = ' CS/PS;

    2 similar with application of styles:

    table. Rows [0]. Cells [0] .texts [0] .appliedCharacterStyle = "bold" / / If this style is present in your doc

    Jarek

  • You can change the size of the sample text in the character window in photoshop CC?

    It seems that the ability to increase the size of text in the sample did a demo of cs7 and photoshop CC?

    -Christmas

Maybe you are looking for