Skip to content

Instantly share code, notes, and snippets.

@groupetma
Last active August 29, 2015 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save groupetma/4a0a9d27c169e1dc9a72 to your computer and use it in GitHub Desktop.
Save groupetma/4a0a9d27c169e1dc9a72 to your computer and use it in GitHub Desktop.
Lorsqu'un ou plusieurs éléments sont sélectionnés, ce script les exportera en image JPG.
/* Ce script exporte la sélection en JPG
This script will export selection to JPG
par Ben Cloutier (Groupe tma)
*/
nomDuScript = "Export sélection JPG"
dateRev = "1.0 (rev.10.04.2015)"
myId = "ben@bencloutier.com";
app.scriptPreferences.userInteractionLevel = UserInteractionLevels.INTERACT_WITH_ALL;
app.scriptPreferences.enableRedraw = 1;
try{
myDocument = app.documents.item(0);
myPage = myDocument.pages.item(0);
myDocumentName = myDocument.name.toString();
myDocument.viewPreferences.rulerOrigin = RulerOrigin.pageOrigin;
if(app.selection[0].constructor.name == "Group"){
alert("Votre sélection est un groupe.\nLa dimension des blocs ne sera pas être ajustée.");
}
with(myDocument.viewPreferences){
//Measurement unit choices are:
//* MeasurementUnits.agates
//* MeasurementUnits.picas
//* MeasurementUnits.points
//* MeasurementUnits.inches
//* MeasurementUnits.inchesDecimal
//* MeasurementUnits.millimeters
//* MeasurementUnits.centimeters
//* MeasurementUnits.ciceros
//Set horizontal and vertical measurement units to points.
horizontalMeasurementUnits = MeasurementUnits.inches;
verticalMeasurementUnits = MeasurementUnits.inches;
}
myElements = app.activeDocument.selection;//Sélection faites
myPageNum = myElements[0].parentPage.name;
}catch(e){
if(myElements.length != undefined){
alert("Aucune image sélectionné!\nVous devez sélectionner une ou plusieurs images avec la flèche noire.");
}else{
alert("Problème à l'horizon!\n\n" + e);
}
goOut();
}
function goOut(){
app.scriptPreferences.userInteractionLevel = UserInteractionLevels.INTERACT_WITH_ALL;
app.scriptPreferences.enableRedraw = 1;
exit();
}
function main(){
myCreateFolder = false;
myFolderCheck();
setSameSize();
exportJPG();
goOut();
}
function setSameSize(){
for(s=0;s<myElements.length;s++){
try{
myContent = myElements[s].graphics[0];
myElements[s].fit(FitOptions.FRAME_TO_CONTENT);
var Bound = myContent.geometricBounds;
myElements[s].geometricBounds = [(Bound[0] -.1 + "in"), (Bound[1] - .1 + "in"), (Bound[2] + .25 + "in"), (Bound[3] + .25 + "in")];
}catch(gg){}
}
}
function exportJPG(){
if(myElements.length != 1){
try{
var myObj = app.activeWindow.activePage.groups.add(app.selection);
}catch(gr){}
}else{
var myObj = myElements[0];
}
with(app.jpegExportPreferences){
antiAlias = true;
embedColorProfile = false;
exportResolution = 300;
jpegColorSpace = JpegColorSpaceEnum.RGB; //JpegColorSpaceEnum.CMYK, JpegColorSpaceEnum.GRAY r/w One of RGB, CMYK or Gray
jpegQuality = JPEGOptionsQuality.HIGH; //JPEGOptionsQuality.LOW, JPEGOptionsQuality.MEDIUM, JPEGOptionsQuality.HIGH, JPEGOptionsQuality.MAXIMUM r/w The compression quality.
jpegRenderingStyle = JPEGOptionsFormat.BASELINE_ENCODING; // JPEGOptionsFormat.PROGRESSIVE_ENCODING r/w The rendering style.
simulateOverprint = true;
}
var myImageNum = prompt("Entrez le nom de l'image" + "\n","");
if(myImageNum == null){goOut();}
myImageNum = myImageNum.replace(/p/ig,"");
if(myImageNum.length == 1){myImageNum = "0" + myImageNum;}
if(myPageNum.length == 1){myPageNum = "0" + myPageNum;}
myCreateFolder = true;
myFolderCheck();
myFile = File(myMainFolder + "\/" + myImageNum + ".jpg");
try{
myObj.exportFile(ExportFormat.JPG, myFile, false);
}catch(parentGroupErr){
alert("Problème avec la sélection!\nSi vous avez sélectionné les blocs d'un groupe individuellement, le script ne pourra pas compoléter l'export.");
goOut();
}
}
function myFolderCheck(){
try{
myMainFolder = myDocument.filePath.toString() + "\/" + myDocumentName.replace(/\.indd$/g,"");
if(!myMainFolder.exists && myCreateFolder == true){
var createFolder = Folder(myMainFolder).create();
}
return myMainFolder;
}catch(fCheck){
alert("Document pas sauvegardé!\nVous devez sauvegarder votre document avant pour poursuivre.\n\nL'image n'a pas été créée.");
goOut();
}
}
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment