Highlighted

Please Help Fixing the Code

Engaged ,
Jun 14, 2020

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);

TOPICS
Scripting

Views

134

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Please Help Fixing the Code

Engaged ,
Jun 14, 2020

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);

TOPICS
Scripting

Views

135

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Jun 14, 2020 0
Engaged ,
Jun 14, 2020

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

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 14, 2020 0
Adobe Community Professional ,
Jun 15, 2020

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. 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 15, 2020 1
Enthusiast ,
Jun 17, 2020

Copy link to clipboard

Copied

You have to change variable name:
var f = myDoc.findGrep();

vs

var f = new Folder("~/Desktop/" + myPrompt);

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 17, 2020 0