Highlighted

Restore external page destinations

New Here ,
Nov 18, 2020

Copy link to clipboard

Copied

@uwe Laubender

You where once involved in a thread (https://community.adobe.com/t5/indesign/indesign-cc2018-hyperlink-aktualisieren-per-script/td-p/1056...) for updating Hyperlinks

 

function Main() {
	var hyperlink, destination, destinationFile, oldDestFilePath, newDestFilePath, newDestFile,
	startTime = new Date(),
	count = 0;
	
	for (var i = hyperlinks.length - 1; i >= 0; i--) {
		hyperlink = hyperlinks[i];
		destination = hyperlink.destination;
		
		if (destination instanceof HyperlinkExternalPageDestination) {		
			oldDestFilePath = destination.parent.documentPath.absoluteURI;
			destinationFile = destination.parent.documentPath;
			
			if (!destinationFile.exists) {
				newDestFilePath = oldDestFilePath.replace(set.find, set.replace);
				newDestFile = new File(newDestFilePath);
		
				if (newDestFile.exists) {
					destination.parent.documentPath = newDestFile;
					count++;
				}
			}
		}
	}

	var endTime = new Date();
	var duration = GetDuration(startTime, endTime);
	var report = "Fertig.\n" + count + " hyperlink" + ((count == 1) ? " wurde" : "s wurden") + " repariert.\n(Zeit: " + duration + ")";
	alert(report);
}

 

This script works great if you used fixed page numbers to an external document.

Do you know what to change if the hyperlink to the external document was set to an text anchor?

 

Best regards, Marco

 

 

 

TOPICS
Scripting

Views

82

Likes

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

Restore external page destinations

New Here ,
Nov 18, 2020

Copy link to clipboard

Copied

@uwe Laubender

You where once involved in a thread (https://community.adobe.com/t5/indesign/indesign-cc2018-hyperlink-aktualisieren-per-script/td-p/1056...) for updating Hyperlinks

 

function Main() {
	var hyperlink, destination, destinationFile, oldDestFilePath, newDestFilePath, newDestFile,
	startTime = new Date(),
	count = 0;
	
	for (var i = hyperlinks.length - 1; i >= 0; i--) {
		hyperlink = hyperlinks[i];
		destination = hyperlink.destination;
		
		if (destination instanceof HyperlinkExternalPageDestination) {		
			oldDestFilePath = destination.parent.documentPath.absoluteURI;
			destinationFile = destination.parent.documentPath;
			
			if (!destinationFile.exists) {
				newDestFilePath = oldDestFilePath.replace(set.find, set.replace);
				newDestFile = new File(newDestFilePath);
		
				if (newDestFile.exists) {
					destination.parent.documentPath = newDestFile;
					count++;
				}
			}
		}
	}

	var endTime = new Date();
	var duration = GetDuration(startTime, endTime);
	var report = "Fertig.\n" + count + " hyperlink" + ((count == 1) ? " wurde" : "s wurden") + " repariert.\n(Zeit: " + duration + ")";
	alert(report);
}

 

This script works great if you used fixed page numbers to an external document.

Do you know what to change if the hyperlink to the external document was set to an text anchor?

 

Best regards, Marco

 

 

 

TOPICS
Scripting

Views

83

Likes

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
Nov 18, 2020 0
Adobe Community Professional ,
Nov 18, 2020

Copy link to clipboard

Copied

Hi Marco,

you are writing:

"Do you know what to change if the hyperlink to the external document was set to an text anchor?"

 

What happened to the destination document(s) that the hyperlinks are broken?

Were they renamed? Can you tell the old name of every renamed document?

 

Thanks,
Uwe Laubender

( ACP )

Likes

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
Reply
Loading...
Nov 18, 2020 0
New Here ,
Nov 18, 2020

Copy link to clipboard

Copied

yes, the documents where renamed because of naming convention.

I know every name of the previous document name. I used this script for updating hyperlinks which uses fixed page numbers for external indd documents, which works fine.  (find: old name replace: new name)

But the script does not work if you set the hyperlink to an named text anchor on a external indd, that is my problem here.

 

i looked into the object model, there is an "HyperlinkTextDestination" but there is no "documentPath" property, this is only in "HyperlinkExternalPageDestination" r/w.... don't know if its the right place to look.

 

Thanks, Marco

 

So, maybe 

 

Likes

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
Reply
Loading...
Nov 18, 2020 0
New Here ,
Nov 18, 2020

Copy link to clipboard

Copied

Likes

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
Reply
Loading...
Nov 18, 2020 0
Adobe Community Professional ,
Nov 19, 2020

Copy link to clipboard

Copied

Hi Marco,

best is I'll contact you in private. I'll send you a personal message through the forum.

To make progress on this issue I need access to the documents.

 

Regards,
Uwe Laubender

( ACP )

Likes

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
Reply
Loading...
Nov 19, 2020 0
Adobe Community Professional ,
Nov 23, 2020

Copy link to clipboard

Copied

Hi Marco,

thank you for the test documents. Yes, this is a severe problem. I tested a lot and came to the following conclusions:

 

The case:

There is a project, a bundle of InDesign documents, with hyperlinks.
Some point to hyperlinkTextDestinations inside the same document.
Some point to other documents.

 

If the documents are renamed, version control, whatever, the hyperlinks that point to hyperlinkTextDestinations outside the document will break immediately.


You cannot know from the broken hyperlink of docA.indd what the destination document is if the destination document was renamed: docB.indd to docB1.indd for example. And you cannot know what the desired hyperlinkTextDestination inside that document is that was linked to.

 

You even cannot retrieve that information with ExtendScripting using the DOM. Property destination with a hyperlinkTextDestination of a given hyperlink that points to a renamed document is not accessible anymore! If you try to read out the properties of destination, InDesign will throw an error:
Error number 79121, error message $ID/ExternalDocumentNotFound, in my German InDesign the message written out is: "Das Zieldokument des Hyperlinks kann nicht gefunden werden. Überprüfen Sie den Speicherort des Dokuments im Hyperlinkbedienfeld, bevor Sie diesen Hyperlink wählen."

 

IMPORTANT NOTE THAT POINTS TO A SOLUTION:

Of course somewhere in the document docA.indd with that hyperlink, that information must still be stored, because if you rename the original destination document back from docB1.indd to docB.indd, the hyperlink will work as expected again!

 

That is the key to a possible solution:

[1] Make a duplicate of the renamed destination document.
[2] Rename it back to its original name to unbreak the hyperlink.

[3] Run a script that redirects the hyperlink destinations from docA.indd to the renamed document docB1.indd.

 

Step [1] would be only possible if you know the renaming scheme ( if there is a scheme at all ) or if you know what the name of the destination document was before it was renamed.

 

Note: You mentioned and linked to a script by Kasyan Servetsky: Restore external page destinations.jsx

As the name of this script says it is able to restore page hyperlinkPageDestinations .

 

Your case is different: You deal with broken hyperlinkTextDestinations.

 

Hope, this helps.

 

Regards,
Uwe Laubender

( ACP )

Likes

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
Reply
Loading...
Nov 23, 2020 0