Copy link to clipboard
Copied
Hey, I am using this script I modified slightly from one I found which meets my needs. The objective was to import *.idms files into an InDesign template by a text reference which is an 8 digit string. The script I found does this by marking the string between a pair of @ characters. So, my strings are @Deleted User@ at the end of the script all the slugs for the placed *.imds are deleted. I modified the script so that it understands the file type it is looking for and knows where to locate the files on the internal server, and it runs really well...until it comes across a reference not present in the target folder. At that point, the script fails and I get an error window and none of the slugs are removed; found *idms or not.
What I would like is for the script to do is to ignore the missing file and leave behind the slug for that file (so that I know it's missing and I need to create it or go find it). Secondarily, as sometimes this list of *.idms files can be quite lengthy, is to have a progress bar and/or a display of which file is currently being placed. It's always distressing when the only indicator that something is happening is the never ending beachball of boredom.
This is what I have so far;
#target "InDesign"
//Assumes each library asset is a single group and library assets are named with unique integer values of 8 digits
//each text offer identifier is in its own textframe, which is large enough to hold the library assets.
// reset the Find/Change dialog
app.findGrepPreferences = app.changeGrepPreferences = null;
// formulate a grep search string
app.findGrepPreferences.findWhat = '@.+?@';
// find all occurrence, last one first
f = app.activeDocument.findGrep (true);
for (i = 0; i < f.length; i++)
{
// construct file name
name = f.contents.replace (/@/g, '');
// place the pdf
f.insertionPoints[0].place (File ('DigitalAssets:03 Catalog:Direct:- assets:Product Snippets:' + name + '.idms'));
}
// delete all @??@ codes
app.activeDocument.changeGrep()
Thanks in advance,
Jim
Copy link to clipboard
Copied
You can add a try.. catch block around the Place, code, or first create the File object in a separate line and test if it exists – there is a property for that in the File object.
If missing, store its name into an array (a simple 'badlist.push(yourName)') and at the end, check if this array contains items. If it does, write it to a text file. (For bonus points: you can call "myFile.execute()" if you make it a plain .txt file, and it will magically open in NotePad, TextEdit, or whatever you have set as your default .txt editor.)
Copy link to clipboard
Copied
Thanks Jongware. That got me 90% where I want to be. I just need to delete the slugs for found and placed *.idms files. This is what I have so far, except it doesn't delete those slugs.
#target "InDesign"
//Assumes each library asset is a single group and library assets are named with unique integer values of 8 digits
//each text offer identifier is in its own textframe, which is large enough to hold the library assets.
// reset the Find/Change dialog
app.findGrepPreferences = app.changeGrepPreferences = null;
// formulate a grep search string
app.findGrepPreferences.findWhat = '@.+?@';
// find all occurrence, last one first
f = app.activeDocument.findGrep (true);
for (i = 0; i < f.length; i++)
{
// construct file name
name = f.contents.replace (/@/g, '');
// place the Snippet
try {
f.insertionPoints[0].place (File ('DigitalAssets:03 Catalog:Direct:- assets:Product Snippets:' + name + '.idms'));
} catch (e) { alert( "Snippet for " + name + " not found." ); }
}
// delete non-empty @??@ codes
app.findGrepPreferences.findWhat = "(?<=.)\@\d+\@\r";
app.changeGrepPreferences.changeTo = "";
app.documents[0].changeGrep();
I have tested the final find/replace in InDesign directly and it does work, but within the script itself it doesn't work.
Copy link to clipboard
Copied
Hi,
I would suggest the following:
The first thing in the loop should be a test if the idms file does not exist, then do nothing and loop on with continue.
var idmsFile = File('DigitalAssets:03 Catalog:Direct:- assets:Product Snippets:' + name + '.idms');
if( !idmsFile.exists ){ continue };
Regards,
Uwe