Copy link to clipboard
Copied
Dear Professionals
Please i need the help for fixing that code, the code is letting user select any text have paragraph style then export all the pages have the same style as jpg, it works fine when i write the path directly but when i let the user to select the path it only export one file!, here is the code :
if (app.documents.length != 0){
var myDoc = app.activeDocument;
MakeJPEGfile();
} else {
alert("Please open a document and try again.");
}
function myPS() {
try {
return myDoc.selection[0].appliedParagraphStyle;
} catch (e) {
alert("Place cursor to text with paragraph style for filenames");
exit();
}
}
function MakeJPEGfile() {
app.jpegExportPreferences.jpegQuality = JPEGOptionsQuality.high;
app.jpegExportPreferences.exportResolution = 300;
app.jpegExportPreferences.jpegExportRange = ExportRangeOrAllPages.exportRange;
app.findGrepPreferences = null;
app.findGrepPreferences.appliedParagraphStyle = myPS();
var f = myDoc.findGrep();
for (var myCounter = 0; myCounter < f.length; myCounter++) {
try {
var curPage = f[myCounter].parentTextFrames[0].parentPage;
if (curPage.appliedSection.name != "") {
curPage.appliedSection.name = "";
}
var objName = f[myCounter].contents.replace(/ /g,"_").toLowerCase();
app.jpegExportPreferences.pageString = curPage.name;
//------------------------------------------------------------------------------
//Select a Folder
//New from M.Hasanin-Select Folder to Save
var myPrompt = prompt("Name your folder to create on the desktop");
var f = new Folder("~/Desktop/" + myPrompt);
if (!f.exists)
f.create();
//End Select Folder
var myFilePath = f + "/" + objName + ".jpg"; //export to a folder of the current document
var myFile = new File(myFilePath);
//------------------------------------------------------------------------------
//var myFilePath = "~/Desktop/" + "/" + objName + ".jpg"; //export to a folder of the current document
//var myFile = new File(myFilePath);
myDoc.exportFile(ExportFormat.jpg, myFile, false);
}
catch(e){}//pasteboard?
}
}
Please help to find where is the Wrong!
You have to change variable name:
var f = myDoc.findGrep();
vs
var f = new Folder("~/Desktop/" + myPrompt);
Copy link to clipboard
Copied
Dear Pros..
Please Help me in Fixing the Code, i Can Export the *.jpg's to Desktop Directly But When Make User Select a folder it Only Export One JPG, I dont Know what is the Wrong? I Spend Hours Trying to Fix the Problem , Here is the Code :
if (app.documents.length != 0){
var myDoc = app.activeDocument;
MakeJPEGfile();
} else {
alert("Please open a document and try again.");
}
function myPS() {
try {
return myDoc.selection[0].appliedParagraphStyle;
} catch (e) {
alert("Place cursor to text with paragraph style for filenames");
exit();
}
}
function MakeJPEGfile() {
app.jpegExportPreferences.jpegQuality = JPEGOptionsQuality.high;
app.jpegExportPreferences.exportResolution = 300;
app.jpegExportPreferences.jpegExportRange = ExportRangeOrAllPages.exportRange;
app.findGrepPreferences = null;
app.findGrepPreferences.appliedParagraphStyle = myPS();
var f = myDoc.findGrep();
for (var myCounter = 0; myCounter < f.length; myCounter++) {
try {
var curPage = f[myCounter].parentTextFrames[0].parentPage;
if (curPage.appliedSection.name != "") {
curPage.appliedSection.name = "";
}
var objName = f[myCounter].contents.replace(/ /g,"_").toLowerCase();
app.jpegExportPreferences.pageString = curPage.name;
//------------------------------------------------------------------------------
//Select a Folder
//New from M.Hasanin-Select Folder to Save
var myPrompt = prompt("Name your folder to create on the desktop");
var f = new Folder("~/Desktop/" + myPrompt);
if (!f.exists)
f.create();
//End Select Folder
//------------------------------------------------------------------------------
//for (var objName = 0; objName < myPS() ; objName++) {
var myFilePath = f.fsName + "/" + objName + ".jpg"; //export to a folder of the current document
//var myFilePath = f.fsName + objName + ".jpg"; //export to a folder of the current document
var myFile = new File(myFilePath);
//}
//------------------------------------------------------------------------------
//var myFilePath = "~/Desktop/" + "/" + objName + ".jpg"; //export to a folder of the current document
//var myFile = new File(myFilePath);
myDoc.exportFile(ExportFormat.jpg, myFile, false);
}
catch(e){}//pasteboard?
}
}
Any Help is Appreciated
Best Regards
Copy link to clipboard
Copied
I'd $.writeln on your last catch statement to find out what the error is. Seems like an error would be happening. One potential cause is that you have two variables named "f" within the same scope: your grep finds and your folder.
Copy link to clipboard
Copied
You have to change variable name:
var f = myDoc.findGrep();
vs
var f = new Folder("~/Desktop/" + myPrompt);