• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Scripting Hyperlinks to character style with same name

New Here ,
Jul 16, 2018 Jul 16, 2018

Copy link to clipboard

Copied

Hi, I have a book with many doc with many comment numbers (4000). I have to link the number in the index with the numeber in the doc. The number in the doc have unique character style. I could also convert the comment numbers in the text anchor.

Doc1:

1 Lorem ipsum dolor sit amet, consectetur adipisci elit.

2  Ut enim ad minim veniam, quis nostrum exercitationem. ..

Doc2:

3 Quis aute iure reprehenderit in voluptate velit...

Index:

Title1: 1, 3

Title2: 2

TOPICS
Scripting

Views

428

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 17, 2018 Jul 17, 2018

Copy link to clipboard

Copied

I found this script, but I have problems.

1:  The script does not search in all open documents

2: It does not search the whole number, but parts of it - es. link 199 to 19 and 9 and 199

Chi mi può aiutare?

if (app.documents.length > 0) {

for (j = 0; j < app.documents.length; j++) {

var myDoc = app.documents;

main();

}

alert("Done");

} else {

alert("Please open a document");

}

function main() {

app.findTextPreferences = NothingEnum.nothing;

app.changeTextPreferences = NothingEnum.nothing;

app.findTextPreferences.appliedCharacterStyle = "Link";

app.findChangeTextOptions.caseSensitive = false;

app.findChangeTextOptions.includeFootnotes = false;

app.findChangeTextOptions.includeHiddenLayers = false;

app.findChangeTextOptions.includeLockedLayersForFind = false;

app.findChangeTextOptions.includeLockedStoriesForFind = false;

app.findChangeTextOptions.includeMasterPages = false;

app.findChangeTextOptions.wholeWord = false;

var myFoundItems = myDoc.findText();

for (i = 0; i < myFoundItems.length; i++) {

for (p = 0; p < myDoc.hyperlinkTextDestinations.length; p++) {

if (myDoc.hyperlinkTextDestinations

.name.indexOf(myFoundItems.contents, 0) == 0) {

var myHyperlinkDestination = myDoc.hyperlinkTextDestinations

;

MakeHyperlink(myFoundItems, myHyperlinkDestination);

}

}

}

}

function MakeHyperlink(myFoundItem, myHyperlinkDestination){

try {

var myHyperlinkTextSource = myDoc.hyperlinkTextSources.add(myFoundItem);

var myHyperlink = myDoc.hyperlinks.add(myHyperlinkTextSource, myHyperlinkDestination);

myHyperlink.visible = false;

myHyperlink.name = myFoundItem.contents;

}

catch(myError){

}

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 17, 2018 Jul 17, 2018

Copy link to clipboard

Copied

Hi Frank,

the script is running a loop on all open documents.

Why do you think it's not running on all open documents?

Hm, maybe it will help if you change line 4 to:

runScript( myDoc );

and line 12 to:

function runScript( myDoc ) {

Suggestion: Insert code to line 26:

$.writeln( myDoc.id +" : "+myDoc.fullName );

When running the script you should now see if myDoc is always the same document when inspecting the JavaScript Console of the ESTK (ExtendScript Toolkit App).

As I see from the code the script is looking for text with an applied character style named "Link". Does all your text you want to find has this character style applied?

Note also the restrictions in the findChangeTextOptions. The script will e.g. not see into text of footnotes…

When in doubt ask the author of the script.

Best,
Uwe

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 18, 2018 Jul 18, 2018

Copy link to clipboard

Copied

Thank you for your help, but nothing has changed.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 18, 2018 Jul 18, 2018

Copy link to clipboard

Copied

Hi Frank,

what did the JavaScript Console say after running the script from the ESTK with my suggested changes?

Copy/paste the contents and format it as plain code.

Regards,
Uwe

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 18, 2018 Jul 18, 2018

Copy link to clipboard

Copied

JavaScript Console:

1 : ~/Desktop/Doc1-test.indd

2 : ~/Desktop/Index-test.indd

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 18, 2018 Jul 18, 2018

Copy link to clipboard

Copied

Ok. So the loop through the open documents is working.

Regards,
Uwe

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 18, 2018 Jul 18, 2018

Copy link to clipboard

Copied

LATEST

Yes, but does not link the numbers in the index file with that in the doc1.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines