Skip to content

Instantly share code, notes, and snippets.

@milligramme
Created February 18, 2011 10:13
Show Gist options
  • Save milligramme/833495 to your computer and use it in GitHub Desktop.
Save milligramme/833495 to your computer and use it in GitHub Desktop.
indesign, doscript,
// create document (hidden)
var doc_obj = app.documents.add(false);
// page length (= jpeg counts)
var p = 50;
// document setting
doc_obj.documentPreferences.pagesPerDocument = p;
doc_obj.documentPreferences.facingPages = false;
// document size
doc_obj.documentPreferences.pageWidth = 90;
doc_obj.documentPreferences.pageHeight = 90;
var doc_w = doc_obj.documentPreferences.pageWidth;
var doc_h = doc_obj.documentPreferences.pageHeight;
// hide frameedge and guide
doc_obj.viewPreferences.showFrameEdges = false;
doc_obj.guidePreferences.guidesShown = false;
// jpeg export option
with(app.jpegExportPreferences){
jpegExportRange = ExportRangeOrAllPages.EXPORT_ALL;
jpegQuality = JPEGOptionsQuality.MAXIMUM;
jpegRenderingStyle = JPEGOptionsFormat.BASELINE_ENCODING;
resolution = 150;
exportingSpread = false;
}
var center = [doc_w/2, doc_h/2];
var max_r = Math.max(doc_w,doc_h) * 0.4; //
var page_obj = doc_obj.pages;
for (var pi=0; pi < p; pi++) {
ov (page_obj[pi], center, max_r, 3, 24); // line weight: 1-3, oval count: 24
};
// show document
doc_obj.windows.add();
var export_path = "~/Desktop/" + new Date().getTime().toString();
Folder(export_path).create();
var img_file = new File(export_path + "/tmp.jpg");
doc_obj.exportFile( ExportFormat.JPG, img_file );
// do somthing
function ov (target, center, max_r, line, count) {
var min_r = 1;
cmyk = ["Cyan", "Magenta", "Yellow", "Black"];
for (var i=0; i < count; i++) {
r = min_r * 2 + max_r * Math.random();
target.ovals.add({
// geometricBounds : [ center[1]-r, center[0]-r, r*2, r*2 ],
geometricBounds : [ center[1]-r, center[0]-r, center[1]+r, center[0]+r ],
fillColor : "None",
strokeColor : cmyk[i%4],
strokeWeight : 1 + line * Math.random()
})
};
}
// open with google chrome
if (File(export_path).getFiles("*.jpg").length > 0) {
// alert("go");
stat = "do shell script \"open -a \'Google Chrome\'" +" "+ export_path +"/\*.jpg\"";
// alert(stat)
app.doScript (stat, ScriptLanguage.APPLESCRIPT_LANGUAGE);
}
else{
alert("nothing is exported");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment