🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: adobe.scripting.indesign
7 messages
7 total messages Started by Rasmus_Olsen Fri, 30 Jan 2009 13:02
Update link - js assistance
#1551
Author: Rasmus_Olsen
Date: Fri, 30 Jan 2009 13:02
15 lines
875 bytes
Hi folks,



 
for (var i = 0; i < app.activeDocument.links.length; i++){   app.activeDocument.links[i].update();  } 



This returns an object ([object Link]). I have tried using the following: app.activeDocument.links.item(i).update(), but I still get the object 'Link'. A little guidance is needed :-)

Thanks.

Regards,
Rasmus
Re: Update link - js assistance
#1552
Author: Rasmus_Olsen
Date: Fri, 30 Jan 2009 13:06
1 lines
668 bytes
BTW Im using this to prevent automated export of docs with missing links with a try/catch.
Re: Update link - js assistance
#1554
Author: Kasyan_Servetsky
Date: Fri, 30 Jan 2009 13:24
17 lines
1039 bytes
Hi Rasmus,

When you update links, iterate backwards, because updating a link changes links collection.

Kasyan


 
function UpdateAllOutdatedLinks(){
   var myLinks = myDocument.links;
   for(var myCounter = myDocument.links.length-1; myCounter >= 0; myCounter--){
      var myLink = myDocument.links[myCounter];
      if (myLink.status == LinkStatus.linkOutOfDate){
         myLink.update();
      }
   }
}
Re: Update link - js assistance
#1555
Author: Rasmus_Olsen
Date: Fri, 30 Jan 2009 14:00
8 lines
855 bytes
Hi Kasyan,

I would never have figured that out on my own - thanks!

It appears that myDocument.links.everyItem().update() also gives me the exception catch when links are missing. Is there any downfalls to this approach in your opinion?

Regards,
Rasmus
Re: Update link - js assistance
#1556
Author: Kasyan_Servetsky
Date: Fri, 30 Jan 2009 15:04
43 lines
1724 bytes
I use this function to check for modified/missing/embedded links. It finds and shows such links.


 
var myDoc = app.activeDocument;
checkLinkNormal();

function checkLinkNormal(){
   for(var myCounter = 0; myCounter < myDoc.links.length; myCounter++){
   var myLink = myDoc.links[myCounter];
      if (myLink.status != LinkStatus.normal){
         if (myLink.status == LinkStatus.linkOutOfDate){
            myLink.show();
            alert ("This link is modified.");
            }
         else if (myLink.status == LinkStatus.linkMissing){
            myLink.show();
            alert("This link is modified.");
            }
         else if (myLink.status == LinkStatus.linkEmbedded){
            myLink.show();
            alert ("This link is embeded.");
         }
         exit();
      }
   }
}

If we use your approach, we just get an error that some link, someware in the document is missing:


 
var myDoc = app.activeDocument;
try {
   myDoc.links.everyItem().update();
}
catch(e) {
   err(e);
}
function err(e){
   alert(e);
   exit();
}
Re: Update link - js assistance
#1652
Author: Rasmus_Olsen
Date: Mon, 02 Feb 2009 07:53
4 lines
688 bytes
Dear Kasyan, thanks for taking time to reply. I've learned a lot from your replies :-)

Best regards,
Rasmus
Re: Update link - js assistance
#1654
Author: Rasmus_Olsen
Date: Mon, 02 Feb 2009 10:47
31 lines
2146 bytes
Kasyan,

I've used your script to alert out a sort of link report - se script below. Can myLog variable be written to a txtfile with same path as current document using InDesign API? I've looked in the Core Javascript Core Objectmodel viewer under the File classes but got lost in the code.. :-)



 
var myDoc = app.activeDocument; 
checkLinkNormal(); 
function checkLinkNormal() { 
	var myLog1 = new String; 
	var myLog2 = new String; 
	var myLog3 = new String; 
	for(var myCounter = 0; myCounter < myDoc.links.length; myCounter++) {  		var myLink = myDoc.links[myCounter];  		if(myLink.status != LinkStatus.normal) {  			if(myLink.status == LinkStatus.linkOutOfDate) {  				myLog1 += 'Link #'+myCounter+' name: '+myLink.name+'.\n';  				myLink.update();  			}  			else if(myLink.status == LinkStatus.linkMissing) {  				myLog2 += 'Link #'+myCounter+' name: '+myLink.name+' Link #'+myCounter+' path: '+myLink.filePath+'.\n';  			}  			else if(myLink.status == LinkStatus.linkEmbedded) {  				myLog3 += 'Embedded links: \nLink name: '+myLink.name+'.\n';				  			}  		}  	}  	if(myLog1.length > 0) { 
		alert('Links updated: \n'+myLog1); 
	} 
	if(myLog2.length > 0) { 
		alert('Missing links: \n'+myLog2); 
	} 
	if(myLog3.length > 0) { 
		alert('Embedded links: \n'+myLog3); 
	} 
} 




BTW Isn't there an easier method to posting script with formatting preserved? I've googled a "script poster" with no luck.

Best regards,
Rasmus
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads