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

How to relink from a given name?

Participant ,
Dec 19, 2017 Dec 19, 2017

Copy link to clipboard

Copied

I need to relink only files with a given name, and link to a specific folder.

In the example is the process that I think would help me, I'm starting to delve into the knowledge of scripts for indesign, and I count with the help of the friends to solve this script, any questions will be available.

SCRIPT.jpg

TOPICS
Scripting

Views

1.1K

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
Guru ,
Dec 19, 2017 Dec 19, 2017

Copy link to clipboard

Copied

It's not clear to me from your screenshot: do you want to relink the images whose names are slightly different -- e.g. begin with "SAS_FUN" and end with "_Heg.pdf" -- or all instances of the same image (exact name). If the latter, you can do this without script:

20-12-2017 7-30-14.png

— Kas

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
Participant ,
Dec 20, 2017 Dec 20, 2017

Copy link to clipboard

Copied

My friend Kasyan Servetsky, thanks for the reply in the post, I apologize for not being clearer on the screenshot.

What I need is to filter all files with _Heg.pdf end, and move those links to a certain folder.

I need to do this with all the files I'm getting.

Thanks again for your help.

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
Guide ,
Dec 20, 2017 Dec 20, 2017

Copy link to clipboard

Copied

Instead of using script, if you use PACKAGE option then you can get all the links..then you can delete the unnecessary link files..

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
Participant ,
Dec 20, 2017 Dec 20, 2017

Copy link to clipboard

Copied

Thanks for the tpk1982 answer. I'll try to be more explanatory. I get these files from other companies, and when I get these files here at the company where I work, I need to put some links inside a certain folder, for next year, when the graphic project is updated, the change occurs automatically.

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
Guide ,
Dec 20, 2017 Dec 20, 2017

Copy link to clipboard

Copied

Okay.. try this script.. it will create the folder called "Document Used Links(_Heg.pdf files)" where the Indesign file is saved.....

var mDoc = app.activeDocument, 

path = mDoc.filePath;

var 

  mLinks = mDoc.links.everyItem().getElements(), 

  destFolder = Folder(path + "/Document Used Links(_Heg.pdf files)"), 

  currLinkFName, currFile, 

  len = mLinks.length; 

 

if ( !Folder(destFolder).create() ) exit(); 

 

 

while (len-->0) { 

  currLinkFName = mLinks[len].filePath; 

  if(mLinks[len].name.match("_Heg.pdf")){

  currFile = File( destFolder +"/"+ File(currLinkFName).name ); 

  mLinks[len].copyLink(currFile); 

  }

}

HTH

K

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
Participant ,
Dec 20, 2017 Dec 20, 2017

Copy link to clipboard

Copied

Thanks for the help my friend tpk1982, but he did not move the files into the folder.

Basically I need it to filter and select all _Heg.pdf files and move to another folder.

I'm on a ceaseless search to create these scripts, but I'm sure that everyone here in the forum will come up with a result.

Thank you very much.

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
Guide ,
Dec 20, 2017 Dec 20, 2017

Copy link to clipboard

Copied

sorry, I am still not understood what the exact requirement.. the provided script will copy the _Heg.pdf files into the folder which is used in document..

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
Participant ,
Dec 20, 2017 Dec 20, 2017

Copy link to clipboard

Copied

Sorry for not being so clear. Come on, there is a folder in the network of the publisher that work, that there are some graphic project files, these files the next year will have the layout updated. When the diagrams are made by outside companies, they create a package from the file, and when I open the file sent by them, the graphic design elements are linked with the package links folder. If this is so, next year when we update they will not update automatically, for that, I need to relink these _HEG links to the original network folder. I need to select these links in the panel and re-link to another folder. Thanks to all for your help.

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
Guide ,
Dec 20, 2017 Dec 20, 2017

Copy link to clipboard

Copied

Okay, Please use the below script..

var

  sourceFolder = Folder.selectDialog("Show me the SERVER folder"),

  mLinks = app.activeDocument.links.everyItem().getElements(),

  cLink, cFile;

while ( cLink = mLinks.pop() ) {

  cFile = File(sourceFolder + "/" + cLink.name );

  if ( !cFile.exists ) continue;

  if(cLink.name.match("_Heg.pdf")){

  cLink.relink(cFile);

  }

}

K

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
Guide ,
Dec 20, 2017 Dec 20, 2017

Copy link to clipboard

Copied

if you are not specific with PDF then use the below code..

var 

  sourceFolder = Folder.selectDialog("Show me the SERVER folder"), 

  mLinks = app.activeDocument.links.everyItem().getElements(), 

  cLink, cFile; 

 

while ( cLink = mLinks.pop() ) { 

  cFile = File(sourceFolder + "/" + cLink.name ); 

  if ( !cFile.exists ) continue; 

  if(cLink.name.match("_Heg.")){ 

  cLink.relink(cFile); 

  }

}

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
Participant ,
Dec 20, 2017 Dec 20, 2017

Copy link to clipboard

Copied

LATEST

Thank you my friend, I will test and I will give a return.

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
Guru ,
Dec 20, 2017 Dec 20, 2017

Copy link to clipboard

Copied

Here's a quick & dirty script.

You run it and a pop-up appears where you should type in a RegExp pattern for names.

For example:

20-12-2017 14-41-54.png

which means "ends with _Heg.pdf — ignoring the case", or

20-12-2017 14-40-37.png

which means " begins with SAS_FUN — ignoring the case", or this one

20-12-2017 14-51-29.png

which means " begins with SAS_FUN and ends with _Heg.pdf with any number of characters in between — ignoring the case"

Next time you run the script, it will remember the last entered pattern so you won't have to retype it.

After you click "OK", it will copy the links that match to the folder named "My links" on the desktop. If it doesn't exist yet, it will be created by the script. Of course, you can change it to whatever you prefer. Also, the links will be relinked to the new location.

If something goes wrong, it will give an alert with an message and the line number where it occurred. The code is enclosed in a try-catch block.

Before

20-12-2017 14-41-36.png

After

20-12-2017 14-42-16.png

Here's the script:

var scriptName = "Copy links by RegExp pattern",

doc;

PreCheck();

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

function Main() {

    try {

        var link;

        var folder = new Folder("~/Desktop/My links/"); // where to copy and relink links

        if (!folder.exists) folder.create();

       

        var pattStr = app.extractLabel(scriptName);

        if (pattStr == "") {

            pattStr = "/_Heg.pdf$/i"; // the default value

        }

   

        var patt = prompt("Type in the RegExp pattern here:", pattStr, scriptName);

        if (patt != null) {

            app.insertLabel(scriptName, patt);

            var links = doc.links;

           

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

                link = links;

                if (link.name.match(eval(patt)) != null) {

                    link.copyLink(folder);

                }

            }

        }

    }

    catch(err) {

        alert(err.message + ", line: " + err.line, scriptName, true);

    }

}

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

function PreCheck() {

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

    doc = app.activeDocument;

    if (doc.converted) ErrorExit("The current document has been modified by being converted from older version of InDesign. Please save the document and try again.", true);

    if (!doc.saved) ErrorExit("The current document has not been saved since it was created. Please save the document and try again.", true);

    if (doc.inks.length == 0) ErrorExit("The current document has not links.", true);

    Main();

}

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

function ErrorExit(error, icon) {

    alert(error, scriptName, icon);

    exit();

}

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

Hope it helps!

— Kas

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
Participant ,
Dec 20, 2017 Dec 20, 2017

Copy link to clipboard

Copied

Thank you Kasyan Servetsky I will test.

Thank you for the help, my friend.

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