Copy link to clipboard
Copied
Hi there, I'm hoping this is a quick question. I've had a look on google but to no avail.
This script run in open document only to search and plug images below 300dpi.
Is it possible to run this script in Book File?
- //DESCRIPTION:Report Bad Resolutions for a New Year
- // No Guarantees, Ltd. Use at your own risk.
- // Jongware, 05-Feb-2010
- // Minimum dpi allowed:
- var minimumValue = 300;
- // Alert when x/y scaling is off by this much percents:
- var percentageScaling = 1;
- var lowResList = new Array;
- for (aGraphic=0; aGraphic<app.activeDocument.allGraphics.length; aGraphic++)
- {
- oneGraphic = app.activeDocument.allGraphics[aGraphic];
- try {
- xres = oneGraphic.effectivePpi[0];
- yres = oneGraphic.effectivePpi[1];
- if (xres < minimumValue || yres < minimumValue)
- lowResList.push (oneGraphic);
- else
- {
- if (xres < yres)
- scaling = 100*yres/xres;
- else
- scaling = 100*xres/yres;
- if (scaling > 100+percentageScaling)
- lowResList.push (oneGraphic);
- }
- } catch (_) {}
- }
- if (lowResList.length > 0)
- {
- doc = app.documents.add();
- frame = doc.textFrames.add({geometricBounds:[0,0,doc.documentPreferences.pageHeight, doc.documentPreferences.pageWidth]});
- txt = '';
- for (i=0; i<lowResList.length; i++)
- {
- pg = ultimateParent (lowResList);
- txt = txt+"File: "+lowResList.itemLink.name;
- if (pg.parent instanceof(MasterSpread))
- txt = txt+' on Master spread '+pg.name;
- else
- if (pg instanceof(Spread))
- {
- txt = txt+' on clipboard of pg '+pg.pages[0].name;
- for (j=1; j<pg.pages.length; j++)
- txt += '-'+pg.pages
.name; - } else
- txt = txt+' on pg '+pg.name;
- txt = txt+' has xres: '+lowResList.effectivePpi[0]+', yres: '+lowResList.effectivePpi[1]+'\n';
- }
- frame.contents = txt;
- } else
- alert ("No images have a resolution less than "+minimumValue+" dpi");
- function ultimateParent(obj)
- {
- while (1)
- {
- obj = obj.parent;
- if (obj.constructor.name == "Page")
- break;
- if (obj.constructor.name == "Character")
- obj = obj.parentTextFrames[0];
- if (obj.constructor.name == "Spread" || obj.constructor.name == "MasterSpread")
- break;
- }
- return obj;
- }
Copy link to clipboard
Copied
Below is a sample demonstration script written for AppleScript that does what you are looking for. It produces a list of the names of graphics where effective PPI is less than 299 or greater than 301 for both the x and y parameters. This can give you some ideas for your ExtendScript.
tell application "Adobe InDesign CC 2018"
set bookCount to count of books
if bookCount = 0 then
set fileRef to choose file
set bookRef to open bookFile
else
set bookRef to book 1
end if
set badList to {}
set bookFiles to book contents of bookRef
with timeout of 500 seconds
repeat with i from 1 to length of bookFiles
set thisDoc to item i of bookFiles
set docStatus to status of thisDoc
if docStatus is not "document is open" then
set docPath to full name of thisDoc
set docRef to open file docPath
else
set docName to name of thisDoc
set docRef to document docName
end if
tell docRef
set graphicList to all graphics
end tell
repeat with j from 1 to length of graphicList
set thisGraphic to item j of graphicList
set thisPPi to effective ppi of thisGraphic
set thisTest to 0
if item 1 of thisPPi < 299 or item 2 of thisPPi > 301 then
set thisTest to thisTest + 1
end if
if item 2 of thisPPi < 209 or item 2 of thisPPi > 301 then
set thisTest to thisTest + 1
end if
if thisTest > 0 then
set end of badList to name of item link of thisGraphic
end if
end repeat
end repeat
end timeout
end tell
Copy link to clipboard
Copied
Thanks Hopkins... but I'm not good in translating/reading AppleScript
Copy link to clipboard
Copied
Hi,
You should be able to get the bookContents and then loop through each entry, making sure it is open in InDesign then run your code on it.
// assuming only one book open.
var myBook = app.books[0];
var allInddFiles = myBook.bookContents;
for ( var i = 0; i < allInddFiles.length; i++)
{
var curDoc = app.open ( allInddFiles.fullName )
// your code here, with changes to cope with using the curDoc variable from above
// close your doc when you are finished
curDoc.close ( SaveOptions.NO);
}
Hope this helps
Malcolm
Copy link to clipboard
Copied
Hi Malcolm,
I've tried your suggestion but the outcome will open every document create list then closed then open another one create list then close again until the last indesign in a book. Is there a way that it will run first throughout the book then create only one list of images.
Many thanks.
-ryu
Copy link to clipboard
Copied
Hi Ryu,
My code doesn't handle the creation of the list document at all, but if you want all images to be listed in one document, create that document before you start the loop and always write to it in the code.
//Something like
var doc = app.documents.add();
for ( var i = 0; i < allInddFiles.length; i++)
{
var curDoc = app.open ( allInddFiles.fullName )
//DESCRIPTION:Report Bad Resolutions for a New Year
// No Guarantees, Ltd. Use at your own risk.
// Jongware, 05-Feb-2010
// Minimum dpi allowed:
var minimumValue = 300;
// Alert when x/y scaling is off by this much percents:
var percentageScaling = 1;
var lowResList = new Array;
for (aGraphic=0; aGraphic<app.activeDocument.allGraphics.length; aGraphic++)
{
oneGraphic = app.activeDocument.allGraphics[aGraphic];
try {
xres = oneGraphic.effectivePpi[0];
yres = oneGraphic.effectivePpi[1];
if (xres < minimumValue || yres < minimumValue)
lowResList.push (oneGraphic);
else
{
if (xres < yres)
scaling = 100*yres/xres;
else
scaling = 100*xres/yres;
if (scaling > 100+percentageScaling)
lowResList.push (oneGraphic);
}
} catch (_) {}
}
if (lowResList.length > 0)
{
frame = doc.textFrames.add({geometricBounds:[0,0,doc.documentPreferences.pageHeight, doc.documentPreferences.pageWidth]});
txt = '';
for (i=0; i<lowResList.length; i++)
{
pg = ultimateParent (lowResList);
txt = txt+"File: "+lowResList.itemLink.name;
if (pg.parent instanceof(MasterSpread))
txt = txt+' on Master spread '+pg.name;
else
if (pg instanceof(Spread))
{
txt = txt+' on clipboard of pg '+pg.pages[0].name;
for (j=1; j<pg.pages.length; j++)
txt += '-'+pg.pages
.name; } else
txt = txt+' on pg '+pg.name;
txt = txt+' has xres: '+lowResList.effectivePpi[0]+', yres: '+lowResList.effectivePpi[1]+'\n';
}
frame.contents = txt;
} else
alert ("No images have a resolution less than "+minimumValue+" dpi");
function ultimateParent(obj)
{
while (1)
{
obj = obj.parent;
if (obj.constructor.name == "Page")
break;
if (obj.constructor.name == "Character")
obj = obj.parentTextFrames[0];
if (obj.constructor.name == "Spread" || obj.constructor.name == "MasterSpread")
break;
}
return obj;
}
curDoc.close ( SaveOptions.NO);
}
Hope this helps
Malcolm
Copy link to clipboard
Copied
Sorry, but I already had an AppleScript. Here is the script translated for JavaScript. It's coarse, I know but pretty much line for line. That way you can see how easy it is to translate from AppleScript to JavaScript and vice-versa. Script is not thoroughly tested either.
var appRef = app;
var bookCount = appRef.books.count();
if (bookCount == 0) {
var fileRef = File.openDialog("Select inDesign book file");
var bookRef = appRef.open(File(fileRef));
} else {
var bookRef = appRef.books.item(0);
}
var badList = [];
var bookFiles = bookRef.bookContents;
for (var i = 1; i < bookFiles.length; i++) {
var docRef = bookFiles;
var docStatus = docRef.status;
if (docStatus == BookContentStatus.DOCUMENT_IS_OPEN) {
var docName = bookFiles.name;
docRef = appRef.documents.itemByName(docName);
} else {
var docPath = docRef.fullName;
docRef = appRef.open(File(docPath));
}
var graphicList = docRef.allGraphics;
for (var j = 0; j < graphicList.length; j++) {
var thisTest = 0;
var thisGraphic = graphicList
var thisPpi = thisGraphic.effectivePpi;
if (thisPpi[0]< 299 || thisPpi[0]> 301) {
thisTest += 1;
}
if (thisPpi[1] < 299 || thisPpi[1]> 301) {
thisTest += 1;
}
if (thisTest >0) {
badList.push(thisGraphic.itemLink.name);
}
}//ends repeat j
} //ends repeat i
badList;
Copy link to clipboard
Copied
Hi Hopkins,
How can I fix this error in your translated code.
Copy link to clipboard
Copied
Hi,
for certain types of graphics property effectivePpi is not available.
Like placed AI files or PDFs…
Regards,
Uwe
Copy link to clipboard
Copied
Which is why that part is wrapped in my script in a try...catch block.
Copy link to clipboard
Copied
> Which is why that part is wrapped in my script in a try...catch block.
Don't need try/catch. Just check the object constructor... let us assume object is named graphic...
if (graphic instanceof Image) {
ppi = graphic.effectivePpi;
} else {
// 'graphic' is not raster (not an 'Image').
}
Copy link to clipboard
Copied
If you want to skip the code, just download a full working demo of FlightCheck. Drag-and-drop your InDesign file onto it. Look at the main window and see the "images" section. There you can sort by DPI and many other factors.
Friendly Regards,
David Dilling
Copy link to clipboard
Copied
Try this free script. Select book doc, choose to make a CSV and open in Excel, sort by row PPI and you can see all that fall below whatever value you're after.
https://www.marspremedia.com/software/indesign/links-report
Copy link to clipboard
Copied
Why do you need scripting for this? Why do you not simple use Indesign's preflight to check your book?
Copy link to clipboard
Copied
Right.
Preflight will even catch more:
Image data in placed PDFs or AIs, also in placed EPS files.
Regards,
Uwe