Forum Replies Created
-
AuthorPosts
-
Theunis De Jong
Member.. That “join(“r”)” line near the top should actually read “join(“r”)”, to insert a return between each line. If I call up the Edit Post, I get the entire script on a single line :(
(It's of no effect to the inner workings of the script but I thought you might to try the sample as-is.)
Theunis De Jong
Member.. It's actually quite simple. This quickie fills a text frame (your cursor has to be in it) with all file names, from a certain starting folder, including files in sub(-sub-sub-sub)-folders. I would've posted it sooner, were it not that I (stupidly) tried it out on a folder that contained several thousands of files and folders … (It made me think I made a mistake somewhere…)
I also use another property of the 'getFiles' function: it can accept a simple text string, which is a file/folder mask such as “*.indd” or “*”, but it may also accept a function that somehow determines if a file or folder should be included. See the JS Help for details — in this case, all I do is check whether it is a file or a folder, and process only the ones I need.
For demonstration purposes, the entire folder structure gets saved into an array, so you can tell it works — you won't need any of the 'myResult' stuff.
It also demonstrates a crucial point on working with recursive functions: all variables inside that function need to be 'local', that is, declared using 'var xxx'. If not, its previous contents are overwritten by the function when it calls itself again!
result = processFolder (Folder(“/SomeFolder”));
app.selection[0].contents = result.join (“r”);
exit(0);function processFolder (startingPoint)
{
var tempFileList, tempFolderList, count;// only for debugging:
var myResult = [];
myResult.push (“rStarting with “+startingPoint.fsName);tempFileList = startingPoint.getFiles( function(x) { return x instanceof File; } );
// tempFileList now contains just files.
for (count=0; count<tempFileList.length; count++)
{
myResult.push (tempFileList[count].fsName);
processFile (tempFileList[count]);
}tempFolderList = startingPoint.getFiles( function(x) { return x instanceof Folder; } );
// tempFolderList contains just folders.
for (count=0; count<tempFolderList.length; count++)
{
myResult = myResult.concat(processFolder (tempFolderList[count]));
}
return myResult;
}function processFile (filename)
{
// .. do whatever you need to here.
}Theunis De Jong
MemberThe getFiles command returns anything that matches the mask you provide. In my example, I limited it to “”*.indd” to get only InDesign files, but — after some deliberating — I decided to add an explicit check because it may also return a Folder named “my files.indd”. (Don't laugh. Of course, me personally would never name a folder something like that, but you'd be amazed.)
This 'explicit check' is right below the for..loop:
if (myList[list] instanceof Folder)
continue;.. so the entire rest of the loop will be skipped ('continue') if the item under consideration is a folder. To make it scan for just folders, you need to make two crucial changes:
1. Change the pattern of 'getFiles' to (“*”), or omit it entirely — its default is in fact “*”. This will make it pick up any and all files and folders.
2. Change the line after the for.. command to
if (myList[list] instanceof File)
continue;
so the commands below it will only be processed when 'myList[list]' is a folder.
.. Or do i need to write a loop that goes into the folder and scans until it's done?
Well … it depends on what you are planning to do. If you want to 'process' all InDesign files in a certain folder and all the ones in subfolders, possibly nested, you need a recursive routine. If you look up “Recursive” in any good dictionary, it'll read “see Recursive” — that sums it up, I guess.
A good way would be:
1. Don't use the for..loop I gave as an example, but instead define two functions: processFile and processFolder.
2. Start your script with 'processFolder'.
3. Have this function scan for all files, and call the function 'processFile' for each.
4. Then have it scan for folders, and call the function 'processFolder' for each.
You see, hopefully, that #4 is the recursive part: if there is a folder inside your main (starting) folder, the function will call itself and process the files in there. If there is a folder in that, it will call itself and process the files in that one. Et cetera ad infinitum, or until all files & folders are processed — whatever comes first.
Tip: If part of your 'processFile' involves saving the file under a new name, take care not to process these in turn! That might lead to an endless loop, not quite ad infinitum but merely ad full hard disk.
Theunis De Jong
MemberSure. The getFiles command returns all files in a folder, possibly filtered by a mask. Do your Thing inside the loop; the rest ought to go all by itself.
You might want to try your processing first on only a few files, before letting it rip into several thousands.
Note that the final line ensures the file always gets overwritten. If you don't always want to do that, set a flag if it's to be saved, and use SaveOptions.NO when not. And, of course, you can create a new file and write to that instead.
myList = Folder(Folder.myDocuments.fsName+”/someSubFolder”).getFiles(“*.indd”);
alert (myList.join(“; “));for (list=0; list<myList.length; list++)
{
// Skip folders that accidentally can creep in
if (myList[list] instanceof Folder)
continue;
// Make sure dialogs are not interfering
app.scriptPreferences.userInteractionLevel = UserInteractionLevels.NEVER_INTERACT;
try {
currDoc = app.open (myList[list]);
} catch (e)
{
// This happens on files for newer versions. Skip.
alert ('Could not open “'+myList[list]+'”..?');
continue;
}
// .. we want to see the 'real' errors
app.scriptPreferences.userInteractionLevel = UserInteractionLevels.INTERACT_WITH_ALL;
// .. do something
alert (currDoc.pages.length);
currDoc.close(SaveOptions.NO); // SaveOptions.YES);
}November 2, 2010 at 4:46 pm in reply to: Any Way to Synchronize a Book to Turn On/Off Layers? #57557Theunis De Jong
MemberYou mean, you'd want add all of the layers in each document added to all other documents?
November 2, 2010 at 4:00 pm in reply to: Any Way to Synchronize a Book to Turn On/Off Layers? #57555Theunis De Jong
MemberCaryn, wouldn't that lead to lots of documents with no layers selected at all?
Theunis De Jong
MemberAs a matter of fact you can do it with a single command, which is very useful because it's also one single Undo! (You don't have to feel bad about seeing this command for the first time — it dwells into the “advanced” realm of scripting.)
app.activeDocument.stories.everyItem().tables.everyItem().rows.everyItem().properties = {autoGrow:true, minimumHeight:”1p”};
There!
(You might want to note that this does not change the actual row height. I tested it on some manually enlarged rows, and it happily sets the minimum height but doesn't change the actual height when it's larger than that.)
Theunis De Jong
Member“Style-sheet”? It's called “autoGrow” in the JS Help.
Use like this:
app.activeDocument.stories.everyItem().tables.everyItem().rows.everyItem().autoGrow = false; // or 'true', whatever you need.
This one-line script will set all table rows to 'exact' height. That height, in turn, can be set with a similar line:
app.activeDocument.stories.everyItem().tables.everyItem().rows.everyItem().minimumHeight = “5mm”;
I should note I'm typing off top/head — these lines are Not Tested.
Theunis De Jong
MemberYou need one master page per tab. (The only alternative is drawing each of them on each page…)
The very best way to set this up is:
1. Create a Master Master spread. Put all of your tabs on this one, so you can align them and globally change whatever you want.
2. For each new chapter, create a separate Master spread and base it on the Master Master spread.
3. Cmd+Shift+Click on each of the unwanted tabs to delete them, per new chapter master. Leave the one you need alone.
Now, when you update your Master Master, all of the other masters will automatically update as well.
October 31, 2010 at 2:50 pm in reply to: how to keep the same resolution of the document while exporting into pdf #57539Theunis De Jong
MemberNo.
“100%” is 100% — according to the application you view it in. InDesign doesn't 'know' the size of your screen — or rather, the size of its window on that same screen. I think it just assumes 72 pixels per inch — it may also be 96, or something entirely else.
Similarly, a PDF doesn't have a “pixel size” either. Per PDF specification, all measurements in a PDF are in points. Some PDF viewers may allow the user to set their own dpi value for their own screen (if I remember correctly, recent Acrobats have that), but not every user will have done that.
PDF is just not designed to be “viewable at 100%” — on a screen; it's purely designed for output.
Theunis De Jong
Memberso if I use a invisible character like a hard or soft return it will serve as an “end character”?
Yep — and Adobe even thoughtfully included one, specifically for this case. It's called “End Nested Style”.
Theunis De Jong
MemberThanks for calling our attention to this, DLawhfMan!
I re-posted it in … the official Adobe InDesign forum … :(
Theunis De Jong
MemberReminiscent of the ol' “What Happend to Cmd+H” discussion on the Mac!
For Windows, Alt+Spacebar always has had a function; this is from Microsoft's Windows 7 Shortcut Key list:
“ALT+SPACEBAR
Open the shortcut menu for the active window”
I'm not sure why Windows would issue a *ping* when it actually should display the Window menu. In any case, it's Adobe's fault (!) for trying to work around system-defined shortcut keys — again.
Theunis De Jong
MemberIt really mainly depends on what your coupons look like. If your design uses lots of Illustrator effects, you'd make them in Illy. If it's just the odd text placed here or there, you might as well create them entirely in InDesign.
It's also possible to make it a hybrid: do the graphic intensive work in Illustrator and leave out all variable data. Place in InDesign, draw a text frame over it, put your variable data into that.
… the ability to assign a global expiration date for all coupons within a given book. (I haven't explored that yet, but I think it's possible)
Absolutely — look up “Text Variables” in the InDesign Help. It's a breeze.
Oh — and on
.. access to an outer stroke on text in InDesign, (which doesn't seem to exist in Illustrator) ..
.. well … it's as straightforward as in InDesign. Select text; select “stroke” rather than “fill”, then change the color …
Theunis De Jong
Member.. the no break setting's a load of crap when the Adobe Paragraph Composer is turned on.
Can you expand on that? Perhaps your URLs are too long to fit comfortably on a single line. The Paragraph Composer should try to work around it by distributing the excess space all over the entire paragraph, where the Single-line Composer just gives up, spaces out that one line beyond belief, then merrily continues with the rest of the text.
-
AuthorPosts
