-
Notifications
You must be signed in to change notification settings - Fork 30
Rectangles Ovals Polygons
fabiantheblind edited this page May 4, 2016
·
3 revisions
###rectangles, ovals and polygons
/**
* Rectangles ovals polygons
*/
main();
function main(){
var pw = 170; // for better handling
var ph = pw/3; // also
// make a document
var doc = app.documents.add({
documentPreferences:{
pageWidth:pw,
pageHeight:ph
}
});
// there is already a page
var page = doc.pages[0];
// some variables for calculating positions
// of our objects
var step = (pw/3);
var gutter = 10;
var y1 = gutter;
var x1 = gutter;
var y2 = (ph - gutter);
var x2 = (step - gutter);
// make a rectangle
var rect = page.rectangles.add({geometricBounds:[y1,x1,y2,x2]});
// move to the right
x1 += step;
x2 = x2 + step ;
// make an oval
var oval = page.ovals.add({geometricBounds:[y1,x1,y2,x2]});
// move again
x1 += step;
x2 = x2 + step;
// make a polygon
var poly = page.polygons.add({geometricBounds:[y1,x1,y2,x2]});
// now we throw them in an array
var items = [rect,oval,poly];
// load 3 images
var images = File.openDialog("Select at least "+items.length+" images","*.*",true);
// this is an object to encapsulate all the
// communication with the user
var comunication = messages(images.length, items.length);
// if the images don't fit the number of objects
// stop the function
if(images.length < items.length){
comunication.wrong_num();
return;
}else if(images.length == items.length){
comunication.right_num();
}else if (images.length > items.length){
comunication.check_diff();
}
// loop our array and do some stuff
// the objects in the array have some
// (seems like all) properties
// in common.
for(var i in items){
thing = items[i]; // isolate it we don't know what it is
thing.strokeWeight = 0; // set to no stroke
thing.place(images[i]); // place one of the images
thing.fit(FitOptions.CENTER_CONTENT); // fit it
thing.fit(FitOptions.FILL_PROPORTIONALLY); // fit it
// you can find out what kind of object
// you have by checking like this
if(thing instanceof Rectangle){
alert("I'm an "+ thing.constructor.name +". at index " + i + "");
thing.bottomLeftCornerOption = CornerOptions.ROUNDED_CORNER;
}; // close if
}; // close loop
return 0;
}; // close main function
/**
* This function does some communication based on a numbers
* Just for fun ;)
*
*/
function messages(images_len,items_len){
var diff = images_len - items_len;
var obj = {
"images_len":images_len,
"items_len":items_len,
"diff":diff,
/* the message if it is the right num*/
"right_num":function (){
alert("Well done. This is the right amount of images.\n"+
"Sing with me: '"+ items_len + "' is the magic number!\n" +
"Yes t is my friend - It's the magic number...");
},
/* the message if it is not enough */
"wrong_num":function(){
alert("You need more images.\nTry again.");
},
/* if there are to many images do some talking */
"one":"Hm. There is "+ diff+ " image more.\n",
"multi": "Hm. There are "+ diff + " images more.\n",
"end":"I will only use "+ items_len + " of them.",
"build": function(bool){
if(bool == true){
return this.one + this.end;
}else{
return this.multi + this.end;
}
}/* close conditional*/,
/*now the function that gets called */
"check_diff":function(){
if(diff == 1){
alert(this.build(true));
}else{
alert(this.build(false));
}
}
}/* close build function in object. IMPORTANT don't add an ";" */
; /* Close the obj object */
return obj;
}
This wiki is maintained by:
fabiantheblind
Thanks to:
- JohnDarnell for fixing lots of typos.
- jsp for fixing lots of typos.
- ltfschoen for fixing typos.
- wridgers for adding more links.
Thanks to the students from the seminar for asking all those questions and making me start this wiki.
- adinaradke
- AnitaMei
- ce0311
- coerv
- felixharle
- FerdinandP
- Flave
- marche
- monkian
- natael
- OliverMatelowski
- PDXIII
- praktischend
- schlompf
- skaim
You are awesome.
- Arrays
- Classes
- Comments
- Conditionals
- Functions
- Inspect Properties
- Loops
- Objects
- Output And Interaction
- Recursive Functions
- Inspect Properties
- Variables And Operations
- Extended JavaScript Guide
- Bridge Talk
- Create And Read Files
- ExtendScript Toolkit
- File
- Folder
- Includes JSX
- Object Watch
- Read In JSON From File And DONT Eval
- Storing Data In A Target Engine
- Target an application
- XML
- app
- Colorbrewer
- Colors And Swatches
- Delay And View
- Dialogs
- Documents
- Duplicate And Transform
- Event AfterSave
- Export IDML
- ExtendScript in InDesign Scripting DOM
- Fonts
- GeometricBounds and Coordinates
- Get named pageItems
- Graphic Lines
- Groups
- HSL Color Wheel
- Images
- Includes
- InsertionPoints
- Layers
- Line Feeds And Carrige Returns
- Masterspreads
- Matrix
- Objectstyles
- Outlines Groups Alignment
- Pages And Margins
- Pathfinder
- Placeholder Text
- Rectangles Ovals Polygons
- RulerOrigin
- Select words at insertionPoint
- Simple Find And Change Grep with FC Query
- Simple Find And Change Grep
- Simple Find And Change Text
- Spiro
- Styles
- Text Analysis ID FC
- Text Analysis
- Text Find Locations
- Text
- Transformation Matricies
- TransparencySettings
- XML creation and import