| User | Post |
|
9:16 am October 15, 2011
| Kasyan Servetsky
| | Kiev, Ukraine | |
| Member | posts 65 |
|
|
Hi Ivan,
It doesn't work because you made too many mistakes in your code.
#target indesign var i, link, newFile, doc = app.activeDocument, links = doc.links, newPath = "/c/temp/newproject/";
for (i = links.length-1; i >= 0; i–) { link = links[i]; newFile = new File(newPath + link.name); if (newFile.exists) link.relink(newFile); try { link.update(); } catch(err) {} }
BTW if you want to use Windows path names, you should escape backslashes:
newPath = 'c:\temp\newproject\';
I prefer URI path names:
newPath = "/c/temp/newproject/";
Hope this helps.
Kasyan
P.S. I don't hang out on Adobe forums any more because they blocked access from my country. If you have more questions to me about scripting links (it's quite a tricky business), feel free to ask them here.
|
|
|
9:29 am October 15, 2011
| Kasyan Servetsky
| | Kiev, Ukraine | |
| Member | posts 65 |
|
|
In my previous post, forum software ate up double backslashes. It should be:
newPath = 'c: backslash backslash temp backslash backslash newproject backslash backslash ';
|
|
|
4:01 pm October 15, 2011
| Jongware
| | | |
| Member | posts 764 |
|
|
Kasyan, it's okay to use forward slashes in an InDesign script – even under Windows.
|
|
|
11:11 pm October 15, 2011
| Kasyan Servetsky
| | Kiev, Ukraine | |
| Member | posts 65 |
|
|
Yes, it is. Forward slashes work as well:
newPath = "c:/temp/newproject/";
What I mean is that backslash is the escape character, so we must use a double backslash to indicate it. In the original post I see single backslashes:
myNewPath = 'c:tempnewproject'
Probably, initallly they were there, but the forum software removed them.
|
|
|
11:20 pm October 15, 2011
| Kasyan Servetsky
| | Kiev, Ukraine | |
| Member | posts 65 |
|
|
Oops! It removed them again. I guess, on this forum, we should type two backslashes for one, and four for two.
|
|
|
8:37 am October 17, 2011
| Kasyan Servetsky
| | Kiev, Ukraine | |
| Member | posts 65 |
|
|
#target indesign Main();
function Main() { // the following 4 lines declare variables // usually I declare all vars at the beginning of the function // when you declare a variable with var, you limit its scope to the function // (making them local), // otherwise the scope is global which may cause you problems // a rule-of-thumb is to use global vars only you really need them var i, link, newFile, doc = app.activeDocument, // set variable doc to the front most document links = doc.links, // set variable links to collection of all links newPath = "/c/temp/newproject/"; // path to the folder for (i = links.length-1; i >= 0; i–) { // loop through all links backwards // from the last to the first item // it's very important when you modify or remove items from collection // to process them back to front, never use in such cases direct loop like so: // for (i = 0; i < links.length; i++) { link = links[i]; // set variable link to the current link newFile = new File(newPath + link.name); // create file object if (newFile.exists) link.relink(newFile); // relink only if the file exists try { // if memory serves me right, unlike CS3, // CS4 doesn't need update() command after using relink() // if you use it , it would cause an error // I use try-catch block to make the script compatible with CS3 and above // In other words, if an error occurs here, skip it over and go on link.update(); } catch(err) {} } }
The links placed more than once are far more difficult to deal with — in short, they should be processed separately.
I can give you a few examples of how I do this:
Resize images for Power Switch (see the SetLink100percent function — this is the latest algorithm I made)
Relink Images and Apply "Rich Black" Color for Power Switch (see the RelinkLink function)
Resize images
|
|
|
1:18 am October 23, 2011
| Kasyan Servetsky
| | Kiev, Ukraine | |
| Member | posts 65 |
|
|
Hi Bill,
I just checked the InDesign CS2 Scripting Reference and yes, theoretically it should work. However, I can't check this in practice — don't have CS2 any more.
Regards, Kasyan
|
|