Copy link to clipboard
Copied
I know nothing about scripting in Illustrator, but am willing and interested to give it a try if this sounds doable. All we want are the names--just a simple list of the names, such as
7009 LL.eps
Rsb shadow design.psd
3_Pt_STA_475_P3.tif
of placed images (in our Illustrator CS5 art) into text that we can either import (from a tab- or comma-delimited text file) or paste into our Filemaker database.
Right now everyone is RETYPING the names of all placed images into the database, with consequent mistakes, missed images, etc. Then when we search our database to find which art uses a certain image...results are not to be trusted.
(If we could cut/paste from either the Links palette or Document Info, that'd be fine... but nope. Not in Illustrator, although we were thrilled to see InDesign CS5 has "Copy Info For Selected Links", which is VERY helpful.) In Illustrator, we can export Document Info to a text file, but artists seem to find that long document too unwieldy, and they revert to typing the names, especially if they only have a couple of placed images... and then we're back to error-laden data no matter how careful they try to be. (Very right-brained folks, you understand.)
Is such a script even possible? If so, where/how might I start? We're on iMacs with the Adobe CS5 suite (and Filemaker 11, if that matters). Thanks.
Copy link to clipboard
Copied
Yes this should be doable. Im only CS2 do you use multi-artboards? This should alert you of the first top level placed items name and full path.
// Just the name
alert(app.activeDocument.placedItems[0].file.name); // Full path to file alert(app.activeDocument.placedItems[0].file.fsName);
If this works for your items then looping and writing to text file should be OK…
Copy link to clipboard
Copied
Great. So my best way to get started, I assume, is check out the Scripting Documentation for Illustrator. Any other tips or tidbits for an absolute newbie? (I've done a bit Filemaker programming so I understand concepts like looping, etc., but know nothing of scripting.)
We don't use multiple artboards, though. Just one design (package) per .ai document.
Copy link to clipboard
Copied
placedItems does not report raster images (I didn't try EPSes). For raster images, you'd need "rasterItems".
This works, for a few placed bitmaps:
alert (app.activeDocument.rasterItems.length);
list = [];
for (i=0; i<app.activeDocument.rasterItems.length; i++)
list.push (app.activeDocument.rasterItems.file.name);
f = app.activeDocument.textFrames.add();
f.contents = list.join("\r");
in that it creates a temporary text frame which gets filled with the image filenames. But getting the text to the clipboard is something else entirely -- I imagined it should be possible to
a. select the text in this temporary frame
b. copy it, using "app.copy()"
c. delete the temporary frame
d. .. and you can go to any other application to paste the list.
Unfortunately, it's not as straightforward as I thought. Simply asking Illy to "f.contents.select()" or "f.textRange.select()" or "f.textSelection = SELECT.ALL" or about anything logical gets rejected. Muppet Mark?
Copy link to clipboard
Copied
I will have to check but 'placedItems' can be a bit dubious… If you place a file but don't check the 'link' check box then it becomes a 'rasterItem' with the box checked its a 'placedItem' so it would be prudent to check both collections I think… Jong, I would NOT use selection at all but just read in the data then write the lot to file. I can't copy() with my version of this app but I don't trust the clipboard when scripting as a basic rule.
Copy link to clipboard
Copied
Jong, I hope this gives you the idea of text selection in Illustrator. I have put an ugly alert() in just to force a screen redraw. Using 'true' adds to pervious selection of text ranges. I can't app.copy() but you may well can.
#target illustrator function selectText() { if (app.documents.length == 0) return; var docRef = app.activeDocument; var x = docRef.textFrames[0].textRanges; for (var i = 0; i < x.length; i++) { docRef.textFrames[0].textRanges.select(); app.redraw(); alert('Foo'); // This forces a redraw } docRef.textFrames[0].textRanges[i-1].deSelect(); app.redraw(); for (var i = 0; i < x.length; i++) { docRef.textFrames[0].textRanges.select(true); app.redraw(); alert('Foo'); // Ditto here } docRef.textFrames[0].textRanges[i-1].deSelect(); app.redraw(); }; selectText();
Copy link to clipboard
Copied
You two are incredible. Thanks so much.
Can't say I followed all of the discussion, but I have 1) a test script to try and 2) places to go to learn more.
Will let you know how the script--and project in general--works out... wish me luck.
Copy link to clipboard
Copied
It's been a while... but I wanted to get back to this. The script is awesome. I've been able to import the results into our Filemaker database as desired. (The import required me to add a line to have it create a folder on the desktop and place the text document inside the folder; I managed to figure out how to do this after a bit of Internet surfing.) This has been an enormous gain in productivity. Not only are users spared the task of typing all the image names into our database; we also know that the names are accurate! It opens the way for additional automation. Wow.
One question for MuppetMark or anyone: Right now the script appends text if it is run on more than one active document. How would I alter the script to have it instead write over the existing text? (Or have it delete old/make a new folder and text document each time?) We don't want users accidentally importing the data from multiple Illustrator documents into a single record of our database. I would like the text document created by the script to contain only the data from one document at a time. Thank you!
Copy link to clipboard
Copied
You should just be able to change log.open('a');
to log.open('w');
write instead of append…
Copy link to clipboard
Copied
That did it! Cool.
I GOTTA learn how to do more of this.
Thank you!!
Copy link to clipboard
Copied
To get you started with Illustrator scripting there are several resources that you should know about.
Firstly the 'ExtendScript Tool Kit' (debugger). This should have been installed as part of the suite and is located in your 'Utilities' Folder.
Drag this app to your dock for easy access. The full paths are…
/Applications/Utilities/Adobe Utilities/ExtendScript Toolkit.app For earlier CS versions.
/Applications/Utilities/Adobe Utilities -CS5/ExtendScript Toolkit CS5/ExtendScript Toolkit.app For CS5.
There is an 'Object Model Viewer' in the newer version of the 'Tool Kit' this will let you browse the applications scripting terms etc.
It's found under the 'Help' menu.
Other good resources are the PDF documentation which you can download from Adobe's site here…
http://www.adobe.com/devnet/illustrator/scripting.html
You may want this one too…
http://www.adobe.com/devnet/creativesuite.html
Jong does some handy iChm browsers too. (Im sure he will post you a link to those).
Copy link to clipboard
Copied
Yup: non programmer-friendly versions of the ESTK's built-in Model Viewer for Illustrator CS4 and CS5 can be found on http://www.jongware.com/idjshelp.html (bring your own CHM viewer).
It's the exact same information as Adobe provides, only in a much more readable and searchable format.
Copy link to clipboard
Copied
Your request was similar to another post that was made only the other day. So I have utilized the same bit of code and made a few changes to suit your needs. It's something for you to test. It should write a tab delimited text file to your desktop 'Illustration-Images.txt' which you can import in to either Excel or FMP. It should write the file name and all the image names (you can change this to file paths if you like). It is made to work with the active document. If you run then change the active document and run again it will append the text file and so on…
#target illustrator function writeDocImages() { if (app.documents.length == 0) return; var docRef = app.activeDocument; row = docRef.name + '\t' recurseLayers(docRef.layers); writeToFile(row); }; writeDocImages(); function recurseLayers(objArray) { for (var i = 0; i < objArray.length; i++) { recurseImages(objArray.rasterItems); recurseImages(objArray.placedItems); if (objArray.layers.length > 0) { recurseLayers(objArray.layers) } if (objArray.groupItems.length > 0) { recurseGroups(objArray.groupItems) } } }; function recurseGroups(objArray) { for (var i = 0; i < objArray.length; i++) { recurseImages(objArray.rasterItems); recurseImages(objArray.placedItems); if (objArray.groupItems.length > 0) { recurseGroups(objArray.groupItems) } } }; function recurseImages(objArray) { for (var i = 0; i < objArray.length; i++) { // This one is for File Name row += objArray.file.name + '\t'; // This one is for File Paths //row += objArray.file.fsName + '\t'; } }; function writeToFile(info) { try { var log = File('~/Desktop/Illustration-Images.txt'); log.open('a'); log.write(info + '\r'); log.close() } catch (e) { alert(e); } };
At this point I have not checked how/if this handles missing links.
Copy link to clipboard
Copied
I am totally illiterate when it comes to scripts. Would either one of you be kind enough to share the actual script with me so I can use it on my projects. I tried to make one myself but I simply dont understand it at all.
Copy link to clipboard
Copied
This ExtendScript Toolkit script gathers image names from the current Adobe Illustrator document and places them in a text file in a created /Users/Shared/Imagenames folder on the local hard drive. My question is whether the script can still be distributed to multiple users when each user has a unique hard drive name.
After happily using this script for over 2 years, we upgraded to CS6 and Mavericks. Formerly, "Macintosh HD" was the common hard drive name for all 7 of our iMac users. Now each hard drive is something like "amy1234". (Our Mac sys admin, when "wiping" the hard drive and installing Mavericks and Adobe software, decided to go the unique route.)
I WAS able to fix the script so it works on MY system (e.g. "quoz4567").
Do I have to hard code the path in each user's copy of the script, or is there a more practical way around this? (Our served Filemaker database, which imports the names, finds the file in Shared regardless of the user because it has a "get desktop path" command and I'm able to create a variable on the fly with the correct path per user.)
I wondered if such magic existed in ExtendScript Toolkit. I'm suspecting the Illustrator script would have to pass data to Applescript and have Applescript make the folder? Or maybe this is all impossible! I looked through "Illustrator-Scripting-Guide" but either it doesn't have that info or I (true, regardless) didn't comprehend what I saw...
I can certainly hardcode per Mac, just curious if the per user approach is doable.
The two parts of the script that reference the path are as follows:
var folderRef = new Folder("quoz4567 iMac/Users/Shared/IMAGENAMES");
folderRef.create();
... and further on near the end of the script...
function writeToFile(info) {
try {
var log = File('quoz4567 iMac/Users/Shared/IMAGENAMES/ILL_ImageNames.txt');
log.open('w');
log.write(info + '\r');
log.close()
... if more info is needed please let me know! Thanks in advance.
Copy link to clipboard
Copied
(Our served Filemaker database, which imports the names, finds the file in Shared regardless of the user because it has a "get desktop path" command and I'm able to create a variable on the fly with the correct path per user.)
we can do this in javascript
var userDesktop = Folder.desktop;
alert(userDesktop);
Copy link to clipboard
Copied
Very cool. Thanks! Where and how do I put this in our script?
(Talkin' to an unexperienced scripter here.)
This is what I tried:
At the beginning added the first var line. Then edited the var folderRef line. (Original script wrote to the Shared folder but I'll happily settle for the desktop.)
var userDesktop = Folder.desktop;
var folderRef = new Folder("userDesktop/IMAGENAMES");
folderRef.create();
Then towards the end I changed this line as follows:
var log = File('userDesktop/IMAGENAMES/ILL_ImageNames.txt');
The script didn't error but it doesn't work either. No IMAGENAMES folder on the desktop and no text file. Can you coach me a bit further; do you need more info?
Copy link to clipboard
Copied
sure, use it like this
var userDesktop = Folder.desktop;
var folderRef = new Folder(userDesktop+"/IMAGENAMES");
folderRef.create();
var log = new File(folderRef+'/ILL_ImageNames.txt');
Original script wrote to the Shared folder but I'll happily settle for the desktop
I don't know where the mac Shared folder is, but you can certainly navigate to it once you have a handle of one known folder (like the desktop). You can get other standard folders if you want, these are available
/Library/Application Support
~/Desktop
~/Documents
/System
Copy link to clipboard
Copied
So close! But I got an error:
Error 2: folderRef is undefined.
Line:12
> folderRef.create();
screen captures of both the beginning of the script and the error are attached.
Any idea why I'm getting this?
Copy link to clipboard
Copied
yeah,
folderREF is not the same as folderRef
Copy link to clipboard
Copied
Oh fer...
Actually, I was pawing around at it while perusing the Adobe Intro to Scripting guide when I realized I'd used caps... fixed it and it worked... Felt stupid.
Then saw your last response and felt REALLY stupid.
In any case (pun intended)... a big thank you from STUPID.
Copy link to clipboard
Copied
hahaha, no problemo
Find more inspiration, events, and resources on the new Adobe Community
Explore Now