Skip to main content
Participating Frequently
June 27, 2019
Question

Placing automatic file path

  • June 27, 2019
  • 6 replies
  • 3991 views

Does anyone know how to place file path/location (that automatically updates itself when file is moved) in illustrator artboard? My work requires to print large amount of illustrator artworks. So occasionally I have this problem in finding the file path of a printed copy.

This topic has been closed for replies.

6 replies

Participating Frequently
July 12, 2019

Hi daitranthanhoa

I pasted the file in text editor(Mac) and saved it in .js. When I load it from illustrator it shows syntax error.

daitranthanhoa
Inspiring
July 12, 2019

i think you must change path of file to your file: C:\\Users\\pc\\Desktop\\f2.ai

Participating Frequently
July 11, 2019

Hi daitranthanhoa

Should I save the entire text in .js or only this part-

var doc=app.activeDocument;

var oplace=doc.placedItems.add();

var f=new File("C:\\Users\\pc\\Desktop\\f2.ai");

oplace.file=f;

daitranthanhoa
Inspiring
July 12, 2019

no, only this part.

daitranthanhoa
Inspiring
July 11, 2019

to place a file:

var doc=app.activeDocument;

var oplace=doc.placedItems.add();

var f=new File("C:\\Users\\pc\\Desktop\\f2.ai");

oplace.file=f;

If file f2.ai in folder of target file , it will auto update when move to other file.

Participating Frequently
July 11, 2019

If anyone could create a plugin for that, our office would be more than willing to pay.

CarlosCanto
Community Expert
Community Expert
July 12, 2019

swaroops89506313  wrote

If anyone could create a plugin for that, our office would be more than willing to pay.

glad to hear

as others mentioned, there's no way to automatically update file paths using scripting. However, if you open the files via scripting, then you can do anything including updating file paths. So if you're willing to give up Illustrator native way of opening files, including double clicking on files or going to the File menu, then the script below can do what you want.

the script creates a floating window that has a button to open files, always use this button and your file paths will get updated. Just make sure you add a text frame place holder for the path and give it a name in the layers panel "file path"

the script will also add this text frame frame for you if the files don't have it, none of your existing files will have it so, it's a bonus. I place the text frame at the top/left corner of the document, you need to style it and place it in the location of your choice.

so to use, just press the Open... button, select one or more files and the script will open and update the text frame

after closing the file, moving it to a different folder and opening again

// script.name = filePathUpdater_swaroops,jsx

// script.description = opens files and updates a text frame with file paths

// script.requirement = a text frame named "file path"

// script.parent = CarlosCanto // 07/12/2019

// script.reference = https://forums.adobe.com/thread/2633801

#target illustrator

#targetengine main

function main () {

    var win = new Window("palette","File Path Updater");

    var btnOk = win.add("button", undefined, "Open...");

    var btnDonate = win.add("button", undefined, "Donate");

    var btnClose = win.add("button", undefined, "Exit");

    win.alignChildren = "fill";

    win.spacing = 8;

    btnOk.onClick = function(){

        var callFunction = openFiles +  '\ropenFiles();';

        btMessaging( 'illustrator', callFunction );

    }

    btnDonate.onClick = function(){

        var callFunction = donate +  '\rdonate();';

        btMessaging( 'illustrator', callFunction );

    }

    btnClose.onClick = function(){

        win.close ();

    }

    win.center();

    win.show();

}

// open files, find "file path" tex frame and update file path. If text frame not found, add it to top/left corner of page

function openFiles() {

    var idoc, filePath, filePathFrame;

   

    var folderStrPref = 'aiscripts.com/filePathUpdater_swaroops/preSelectFolder';

    var preselectFolder = Folder(app.preferences.getStringPreference (folderStrPref));

    if (!preselectFolder.exists) {

        var preselectFolder = new Folder('~/Desktop');

    }

    var sourceFiles = preselectFolder.openDlg('Open Illustrator file...', 'AI: *.ai', true); // select source folder

    if (sourceFiles==null) {   // exit if press cancel in either dialog

        alert('Cancelled by user');

        return;

    } 

    var sourceFolder = sourceFiles[0].parent;

    app.preferences.setStringPreference (folderStrPref, sourceFolder.fsName);

   

    for (var a=0; a<sourceFiles.length; a++) {

        idoc = app.open(sourceFiles);

        filePath = idoc.fullName.fsName;

       

        try {

            filePathFrame = app.activeDocument.textFrames['file path'];

            filePathFrame.contents = filePath;

        }

        catch (e) {

            //$.writeln(e);

            filePathFrame = app.activeDocument.textFrames.add();

            filePathFrame.name = 'file path';

            filePathFrame.contents = filePath;

        }

    }

}

function donate() {

    //alert('entering donate...');

    openURL( 'www.paypal.me/aiscripts' );

   

    function openURL( address ) { 

        var f = File( Folder.desktop + '/aiOpenURL.url' ); 

        f.open( 'w' ); 

        f.write( '[InternetShortcut] URL=http://' + address); 

        f.close(); 

        f.execute(); 

        f.remove();

    };

}

function btMessaging( target, callFunction ) {

    var bt = new BridgeTalk();

    bt.target = target;

    bt.body = callFunction;

   

    bt.onResult = function(result) {

        //alert('onresult: ' + result.body);

    }

    bt.send();

}

main ();

Participating Frequently
July 15, 2019

I'm assuming I don't have to include the numbering isn't?

Srishti Bali
Community Manager
Community Manager
July 5, 2019

Hi Swaroop,

Moving this discussion to Illustrator Scripting​ community so that you can get some more responses from our scripting experts.

Regards,

Srishti

Lumenn
Inspiring
July 8, 2019

I'm not sure if it's doable with a script - you'd propably have to run the script after opening each file, to update it's location.

To update the file on every opening of file, i think it would require a plugin.

Maybe someone else will have an idea.

Monika Gause
Community Expert
Community Expert
June 27, 2019

swaroops89506313  schrieb

(that automatically updates itself when file is moved)

Maybe you can find a script that places the file path into the artwork. But this part won't happen. Only a plugin would be able to do that, but I'm not aware of an  existing one.