-
1. Re: Filename automated from text?
Joe.Charles Oct 4, 2010 8:38 AM (in response to mizzmuzikluvr)I think you can do this tagging the boxes with the name of the person using its label property. May be PERSON_NAME.
Then you should iterate over document all pages, looking for the box with the script label, and finally export each one as jpeg:
app.jpegExportPreferences.jpegExportRange=ExportRangeOrAllPages.EXPORT_RANGE;
app.jpegExportPreferences.exportingSpread=false;var personName;
for (var currentPageIndex=0;currentPageIndex<app.activeDocument.pages.length;++currentPageIndex) {
personName="";
for (var currentTextFrameIndex=0;currentTextFrameIndex<app.activeDocument.pages[currentPageIndex]. textFrames.length;++currentTextFrameIndex) {
if (app.activeDocument.pages[currentPageIndex].textFrames[currentTextFrameIndex].label=="PER SON_NAME")
personName=app.activeDocument.pages[currentPageIndex].textFrames[currentTextFrameIndex].c ontents;
}
app.jpegExportPreferences.pageString=String(currentPageIndex+1);
app.activeDocumen.exportFile(ExportFormat.JPG,personName+".JPEG");
}
Hope this helps
-
2. Re: Filename automated from text?
mizzmuzikluvr Oct 12, 2010 10:03 AM (in response to Joe.Charles)I apologize for seeming so dense, but while I understand the scripting function in theory- I don't in practicality. How do I implement this answer? I promise if you explain it slowly, once I get it I will remember it.
Here's What I did.
I used the Label Function to label the text box with the data merge variable <<name>> as PERSON_NAME
From there, I executed the data merge, producing one 50 page document with each page having a unique text in the <<name>> field, which is also the box tagged as PERSON_NAME.
Then, I used ExtendScript Toolkit to copy and paste the script provided, save it in the script folder for indesign.
But when I tried to run it, it kept coming up with offending text errors. So I guess I need more instructions, or perhaps a tested script?
Thank you so much for your patience.
Kayla
-
3. Re: Filename automated from text?
Joe.Charles Oct 14, 2010 6:09 AM (in response to mizzmuzikluvr)Label function? What I understood is that you "tagged" each name box -one per page- as PERSON_NAME using the script label panel. Is that right?
Once you did it, you can recover person name for one page using this function:
function getPersonName(page) {
for (var currentTextFrameIndex=0;currentTextFrameIndex<page.textFrames.length;++currentTextFrameIn dex) { // Iterates over frames
if (page.textFrames[currentTextFrameIndex].label=="PERSON_NAME") // if label is PERSON_NAME..
return page.textFrames[currentTextFrameIndex].contents; // ..returns text frame contents
}
return null; // if not found, returns null
}
getPersonName function iterates over text frames within the given page, looking for the first labeled as PERSON_NAME.
Script main loop will iterate over document pages, exporting each one as jpeg:
var personName;
var currentPage;
app.jpegExportPreferences.jpegExportRange=ExportRangeOrAllPages.EXPORT_RANGE; // Export only given range pages
app.jpegExportPreferences.exportingSpread=false;var pagesList=app.activeDocument.pages;
for (var currentPageIndex=0;currentPageIndex<pagesList.length;++currentPageIndex) { // Iterates over pages list
currentPage=pagesList[currentPageIndex];personName=getPersonName(currentPage);
if (personName!=null) { // If we have a person name -jpeg file name-
app.jpegExportPreferences.pageString=String(currentPageIndex+1); // set up the export range..
app.activeDocumen.exportFile(ExportFormat.JPG,personName+".JPEG"); //.. and save the file
} else {
alert("Page number "+currentPageIndex+" without person name box");
}
}
Hope this help -and work ;-) I didn´t tried it-
Regards
-
4. Re: Filename automated from text?
Joe.Charles Oct 14, 2010 9:31 AM (in response to Joe.Charles)Use notepad -or similar- to create a text file with jsx extension.
Insert above code.
Save into indesign Scripts\Scripts Panel folder
Regards
-
5. Re: Filename automated from text?
mizzmuzikluvr Oct 14, 2010 9:54 AM (in response to Joe.Charles)Thanks, Joe!
Well, it did.... *something*....
Firstly, sorry about the confusion. When you said "tag" the boxes I actually just used the "tag" panel in indesign. But this time I did it Via the Script Label Panel.
I combined the two snippets into one file and ran it.
It said writing Jpeg for each page, took quite some time actually.
Trouble is... I don't know where it was writing them to. I did a spotlight search for .jpeg created within the last day, I did a search for several of the names that it should have exported under, and I've checked the folder that the original indd file is in. I can't find them! So, I'm not sure if it worked. It might have saved them under an incorrect naming scheme, and thats why I can't find them via search.
Thank you so much though! I was so excited when It started running and writing Jpeg!
Kayla
-
6. Re: Filename automated from text?
Joe.Charles Oct 15, 2010 1:41 AM (in response to mizzmuzikluvr)You have to append the desired path before person name:
path+personName+".JPEG"
It might be something like "/c/temp/"
For debuging reasons, add an alert before exporting each page, with the name of the person name:
alert(personName);
regards
As I said, i didn´t tried it ;-)
-
7. Re: Filename automated from text?
mizzmuzikluvr Oct 15, 2010 10:43 AM (in response to Joe.Charles)Alrighty,
I made a couple changes. First off, so we're on the same page, Here's what I'm working with:
function getPersonName(page) {
for (var currentTextFrameIndex=0;currentTextFrameIndex<page.textFrames.length; ++currentTextFrameIndex) { // Iterates over frames
if (page.textFrames[currentTextFrameIndex].label=="PERSON_NAME") // if label is PERSON_NAME..
return page.textFrames[currentTextFrameIndex].contents; // ..returns text frame contents
}
return null; // if not found, returns null
}
var personName;
var currentPage;
app.jpegExportPreferences.jpegExportRange=ExportRangeOrAllPages.EXPORT_RANGE; // Export only given range pages
app.jpegExportPreferences.exportingSpread=false;
var pagesList=app.activeDocument.pages;
for (var currentPageIndex=0;currentPageIndex<pagesList.length;++currentPageIndex) { // Iterates over pages list
currentPage=pagesList[currentPageIndex];
personName=getPersonName(currentPage);
if (personName!=null) { // If we have a person name -jpeg file name-
app.jpegExportPreferences.pageString=String(currentPageIndex+1); // set up the export range..
app.activeDocument.exportFile(ExportFormat.JPG,"/desktop/Flyers/"+personName+".JPEG"); //.. and save the file
} else {
alert("Page number "+currentPageIndex+" without person name box");
alert(personName);
}
}
As suggested, I tried adding a path before the personName+".JPEG", making it (ExportFormat.JPG,"/Desktop/Flyers/"+personName+".JPEG")
That came back with an error, "Cannot find directory /Desktop/Flyers/JohnSmith.jpeg"
So I took that part out, and ran it as I did yersterday, only with the alert(personName); in there. The alert didn't seem to do anything. It started over what it did yesterday, saying it was writing JPEG but I can't find where.
I assume I'm putting in the directory location in the wrong place. But I don't know what the right place is.
Thanks again for your continuing support. =oD
-
8. Re: Filename automated from text?
Larry G. Schneider Oct 15, 2010 11:05 AM (in response to mizzmuzikluvr)Which OS are you using? The path is different for each OS.
-
9. Re: Filename automated from text?
mizzmuzikluvr Oct 18, 2010 9:27 AM (in response to Larry G. Schneider)Oh, I'm using OSX and CS5.
Thanks,
Kayla
-
10. Re: Filename automated from text?
Joe.Charles Oct 18, 2010 9:40 AM (in response to mizzmuzikluvr)You can use any valid path on finder.
Here -> http://wiki.servoy.com/display/test98/File+path+syntax_+MacOSX you can see OSX path syntax
Regards
-
11. Re: Filename automated from text?
mizzmuzikluvr Oct 18, 2010 1:20 PM (in response to mizzmuzikluvr)First of all, Joe,
YOU. ARE. AMAZING.
IT works! Everything exports!
My only question now is how to I change the save as settings? The files are coming across as too big. For now I'm just going to use photoshop or Bridge to batch resize them, but in the future, this setting would be interesting to have.
Thank SO MUCH for helping me with this.
Kayla
-
12. Re: Filename automated from text?
Joe.Charles Oct 19, 2010 1:58 AM (in response to mizzmuzikluvr)Try this:
app.jpegExportPreferences.jpegQuality=desiredQuality;
app.jpegExportPreferences.resolution=desiredResolution;
app.jpegExportPreferences.jpegRenderingStyle=JPEGOptionsFormat.BASELINE_ENCODING;Regards
-
13. Re: Filename automated from text?
mizzmuzikluvr Oct 19, 2010 10:00 AM (in response to Joe.Charles)Joe,
Thanks for the advice, but, once again, I'm not the best at implementing it.
Here's what I have in total:
function getPersonName(page) {
for (var currentTextFrameIndex=0;currentTextFrameIndex<page.textFrames.length; ++currentTextFrameIndex) { // Iterates over frames
if (page.textFrames[currentTextFrameIndex].label=="PERSON_NAME") // if label is PERSON_NAME..
return page.textFrames[currentTextFrameIndex].contents; // ..returns text frame contents
}
return null; // if not found, returns null
}
var personName;
var currentPage;
app.jpegExportPreferences.jpegExportRange=ExportRangeOrAllPages.EXPORT_RANGE; // Export only given range pages
app.jpegExportPreferences.exportingSpread=false;
var pagesList=app.activeDocument.pages;
for (var currentPageIndex=0;currentPageIndex<pagesList.length;++currentPageIndex) { // Iterates over pages list
currentPage=pagesList[currentPageIndex];
personName=getPersonName(currentPage);
if (personName!=null) { // If we have a person name -jpeg file name-
app.jpegExportPreferences.pageString=String(currentPageIndex+1); // set up the export range..
app.jpegExportPreferences.jpegQuality=Maximum;
app.jpegExportPreferences.resolution= X ;
app.jpegExportPreferences.jpegRenderingStyle=JPEGOptionsFormat.BASELINE_ENCODING;
app.activeDocument.exportFile(ExportFormat.JPG,"/Users/kaylasrodawa/Desktop/Flyers/"+pers onName+".JPEG"); //.. and save the file
} else {
alert("Page number "+currentPageIndex+" without person name box");
alert(personName);
}
}
___________
I'm not sure if I added the quality stuff in the right place. Also, I've tried all sorts of values there, High, Maximum, "100", 100 etc etc. And every time it either says "expeted jpegquality enumerator, recieved "X" " or it says , "X undefined."
So, obviously I'm still messing this up somewhere. I'd appreciate any more advice you could give. I know this is a longer commitment than you probably intended to make in the beginning. =D
Kayla
-
14. Re: Filename automated from text?
[Jongware] Oct 19, 2010 10:13 AM (in response to mizzmuzikluvr)The JPEG quality "expects a jpegquality enumerator" because it has to be one of these constants:
JPEGOptionsQuality.LOW
JPEGOptionsQuality.MEDIUM
JPEGOptionsQuality.HIGH
JPEGOptionsQuality.MAXIMUMThe resolution can be any simple number:
"The export resolution. (Range: 1 to 2400)"
(The good news is, you added the rest correctly, as far as I can see.)
-
15. Re: Filename automated from text?
mizzmuzikluvr Oct 19, 2010 1:41 PM (in response to [Jongware])Well, its good to know I did SOMETHING right!
Alright, so I changed it to
app.jpegExportPreferences.jpegQuality=JPEGOptionsQuality.MAXIMUM;
And it seemed to go ok. Then it got caught up on the resolution.
I've tried:
app.jpegExportPreferences.resolution=100;
To which I get the error "Object does not support the property or method 'resolution'
So I tried
app.jpegExportPreferences.resolution=JPEGOptionsResolution.100;
And I get a syntax error with the offending text "100"
I've tried all variations I can think of of "100" etc.
Thanks again for sticking with me. I'm so close!
Kayla
-
16. Re: Filename automated from text?
Marijan Tompa Oct 19, 2010 1:51 PM (in response to mizzmuzikluvr)Try this:
app.jpegExportPreferences.exportResolution = 100;
"resolution" is changed to "exportResolution" from CS4 to CS5 DOM.
--
tomaxxi
-
17. Re: Filename automated from text?
[Jongware] Oct 19, 2010 1:56 PM (in response to Marijan Tompa)So it did ... is this listed in Harbs' List of Random Property Name Changes? <g>
From the CS5 JS Help:
"exportResolution [...] The export resolution expressed as a real number instead of an integer. (Range: 1.0 to 2400.0)"
Oh wow -- all that trouble just so someone could set the resolution to 300.000001 dpi ... Was that an actual Feature Request?
-
18. Re: Filename automated from text?
mizzmuzikluvr Oct 19, 2010 5:58 PM (in response to [Jongware])THAT'S IT!
IT WORKS!
I'm going to paste it here in its entirety in case someone else ever needs it again. Oh, and PS: Even in CS5 it works as resolution 100, rather than 100.0
function getPersonName(page) {
for (var currentTextFrameIndex=0;currentTextFrameIndex<page.textFrames.length; ++currentTextFrameIndex) { // Iterates over frames
if (page.textFrames[currentTextFrameIndex].label=="PERSON_NAME") // if label is PERSON_NAME..
return page.textFrames[currentTextFrameIndex].contents; // ..returns text frame contents
}
return null; // if not found, returns null
}
var personName;
var currentPage;
app.jpegExportPreferences.jpegExportRange=ExportRangeOrAllPages.EXPORT_RANGE; // Export only given range pages
app.jpegExportPreferences.exportingSpread=false;
var pagesList=app.activeDocument.pages;
for (var currentPageIndex=0;currentPageIndex<pagesList.length;++currentPageIndex) { // Iterates over pages list
currentPage=pagesList[currentPageIndex];
personName=getPersonName(currentPage);
if (personName!=null) { // If we have a person name -jpeg file name-
app.jpegExportPreferences.pageString=String(currentPageIndex+1); // set up the export range..
app.jpegExportPreferences.jpegQuality=JPEGOptionsQuality.MAXIMUM;
app.jpegExportPreferences.exportResolution = 100;
app.jpegExportPreferences.jpegRenderingStyle=JPEGOptionsFormat.BASELINE_ENCODING;
app.activeDocument.exportFile(ExportFormat.JPG,"/Users/kaylasrodawa/Desktop/Flyers/"+pers onName+".JPEG"); //.. and save the file
} else {
alert("Page number "+currentPageIndex+" without person name box");
alert(personName);
}
}
Thanks to everyone who contributed, and especially to Joe. =oD It was worth all the trouble, as I will be using this script about a million times.
Thanks again everyone.
Kayla
-
19. Re: Filename automated from text?
Joe.Charles Oct 20, 2010 1:09 AM (in response to mizzmuzikluvr)Hi Kayla
Only one question more. You can set jpeg preferences outside the pages loop; don´t need to set for each page.
I´m happy with that.
Regards
-
20. Re: Filename automated from text?
Paulo.Norambuena Feb 16, 2011 3:15 PM (in response to Joe.Charles)Hi Joe
I wonder if you could help me to adapt this VERY USEFUL script to export pdf file instead of jpg. All I need is to choose the the export preset.
I am trying to do iton my own with no luck. I'm using asomething like this:
app.pdfExportPreferences.pageRange = app.documents[0].pages[p].name; var export_preset = app.pdfExportPresets.item("[Smallest File Size]"); app.documents[0].exportFile( ExportFormat.pdfType, File("/" + pdf_name + ".pdf"),Please help.
Thanks
-
21. Re: Filename automated from text?
Joe.Charles Feb 17, 2011 1:32 AM (in response to Paulo.Norambuena)You need to pass selected exportPreset to the export function:
exportFile(ExportFormat.pdfType, File(pdfName), false,export_preset);
Here you have a complete sample -> http://forums.adobe.com/thread/289666
Regards
-
22. Re: Filename automated from text?
Paulo.Norambuena Mar 15, 2011 12:17 PM (in response to Joe.Charles)ok.
I managed to build up something that I believe does what I need. Could you help me checking it out so that it doesn't do something unexpected. I'm new into scripting and I'm learning on my own so your opinion will be very helpfull.
thanks




