Copy link to clipboard
Copied
I am just starting with scripts and this is my first visit here, so if there is a protocol for this (I should search first or something) please let me know.
What I am hoping to accomplish is to have a script generate a list of coordinates that define the size and position of the artboards in an illustrator file - in a perfect world, we would then perform some calculations within the script that would print out a string of numbers my shear operators could use to cut printed lables to the correct size (the numbers would be printed right on the press form).
I've tried a couple of things, but my programming skills are a few years out of date and I could use any help anyone can offer - or if there is an aleady complete solution, direct me to it.
Thanks in advance!
Copy link to clipboard
Copied
OK...let's shift gears a bit...
I found this script on wundes.com that generates an alert listing all the attributes for an item the user selects:
/////////////////////////////////////////////////////////////////
// The Document Object Model Explorer v.2 -- CS
//>=--------------------------------------
//
// Select an object on the page, then run this script.
// It will return a list of everything that object contains.
// You can also manually explore the document object model by entering an object's path.
//
// As of version 2, a "displayErrors" variable has been added.
// Now users can view objects that failed.
// "displayErrors" defaults to true, but can be turned off by
// setting it to "0" in the first line of the script.
//
// Output is also now alphabetized, and is broken into multiple alerts if output is
// longer than the "maxLines" variable.
//
// Prompt can now be used as a javascript command line too.
// If user input returns a value, the value is returned in an alert box.
//>=--------------------------------------
// JS code (c) copyright: John Wundes ( john@wundes.com ) www.wundes.com
//copyright full text here: http://www.wundes.com/js4ai/copyright.txt
//////////////////////////////////////////////////////////////////
var displayErrors = 1;
var maxLines = 50;
var bob = "";
var disp_ar = new Array();
//the item count object:
var c = 0;
var observed = prompt("What do you want to explore? i.e.;\r app (not used before CS)\r documents\r activeDocument.pageItems[0]","activeDocument.selection[0]");
//assign prompt text to actual object;
// a side effect of which is,
// if the user input is actually a line of executable code,
// it gets run here:
var thisObject = eval(observed);
try
{
for (all in thisObject )
{
c++;
//attempt to decypher each sub object
try
{
bob= all+"=";
bob+= eval(observed+"."+all);
disp_ar.push(bob);
}
catch (e)
{
// if undecypherable, say why:
if(displayErrors){
bob = all+"="+(e.toString().split(":"))[1];
disp_ar.push(bob);
}
}
disp_ar.sort();
}
//decide arbitrary max length of list before switching to tabs.
if(c>1){
// if object has more than one object content:
var nicedisp = "";
var dispLen = disp_ar.length;
// if longer than max, divide by the amount longer than max, so you don't
// end up with a dangling variable at the end.
var maxNum = dispLen>maxLines?dispLen/Math.ceil(dispLen/maxLines):maxLines;
var dispOutput = new Array("");
var more = "";
var myLoc = 0;
for (var x=0;x<dispLen;x++)
{
// add spacing for formatting of line numbers less that 10.
if(x<9 ){
spc = " ";
} else{
spc = "";
}
var thisMod = Math.ceil(x%maxNum);
if(thisMod==true && x>maxNum -1){
myLoc++;
//initialize array slot:
dispOutput[myLoc] = "";
}
dispOutput[myLoc]+=(spc+(x+1)+") "+disp_ar
}
//show output page(s):
var outLen = dispOutput.length;
for (var a=0;a<outLen;a++)
{
more = a<(outLen-1)?" More...":"";
alert("Contents of:\r"+observed+"\r------------------------\r"+dispOutput+more);
}
}else{
alert("Value of:\r"+observed+"\r------------------------\r"+thisObject );
}
}
catch (e)
{
//if user is running code from command line, do nothing.
//if object returns something, show it:
if(thisObject!= undefined){
alert(thisObject);
}
}
//handle spacing for columns
function makeSpace(num){
spc = "";
for (var j=0;j<num ;j++ )
{
spc+="|";
}
return spc;
}
Being new to this, is there a way I can restrict it to just getting "GeometricBounds" for the object selected, and sending them to a file (PDF or AI would be best so we can copy any paste back into the working file).
If there is a way to do that, I will need to know how to manipulate the data (convert to millimeters, then do some addition and subtraction to generate the shear cut info my crews need printed on the press sheets.
In a perfect world, the final output would look like the image below, but a simple listing of the numbers will get me to where I need to be.
Copy link to clipboard
Copied
Hi GNC
A tip: when you asks for the height or width or cropbox (that return an array of coordinates) from the document, you are actually calling the informations from the active artboard. So, in simple steps, what you need to do is just use a loop that switch the active artboard and read the properties:
For example:
#target illustrator
#targetengine main
var doc = app.activeDocument;
var pages = doc.artboards;
for (var g=0;g<pages.length;g++){
pages.setActiveArtboardIndex (g);
alert(doc.width);
alert(doc.height);
alert(doc.cropBox);
};
So, basically you just active one artboard and read the properties as if it were the document. The setActiveArtboardIndex() method will switch the active artboard. After switching, you read the properties of the document (like width, height and cropbox).
Test and tell if these information are what you need
Best Regards
Gustavo.
Copy link to clipboard
Copied
Hmmm -- the usual Illustrator scripts seem out to lunch Perhaps I can help you get going. Is the following enough to help you on your way?
On http://jongware.mit.edu/iljscs6html/iljscs6/pc_Artboard.html you can see the basic properties of artboards; the one you are interested in is 'artboardRect'.
// 'artboards' is a property of 'Document'
// it's an array, so this tells you how many you have:
alert (app.activeDocument.artboards.length);// enumerate them with a for-loop
for (i=0; i<app.activeDocument.artboards.length; i++)
{
// .. using each by indexed number
// .. and what you want to know is
// "artboardRect: Size and position of artboard"
r = app.activeDocument.artboards.artboardRect;
// now r holds the coordinates:
alert ('left:'+r[0]+' right:'+r[1]+' top:'+r[2]+' bottom:'+r[3]);
}
.. The alert now simply shows the values for each of your artboards, in points. Points-to-millimeter is easy (72 points in an inch, 25.4 mm in an inch):
mm = points * 25.4 / 72
and from the coordinates, you can get width and height.
Copy link to clipboard
Copied
Thanks for the help everyone - your feedback was very helpful.
We have moved on to pursuing path more in line with my 2nd post above - getting the script to report on the size and position of a selected object (in our case the lines that represent or trimmed label size).
Having the information printed in an alert is great, but then it has to be re-typed (and possibly mistyped). I'm so new at this that I don't understand how to get the script to print the information to a file, or how to manipulate the numbers I get within the script so it just prints out the numbers we need right on the press sheet (or on another sheet that we can copy and paste from - the goal being to avoid any keypunch errors)
Our example would be a 28" x 40" press sheet that needs to be trimmed down to 30" x 23"
The numbers we need to generate are:
24.875 (Cut from bottom to top to maintain the press lead edge, which is at the bottom of the sheet)
35 (Cut from left to right)
23 (Cut from top to bottom)
30 (Cut from right to left)
Here is a visual of what we are doing:
The object we would be selecting in the Illustrator file would be a box that is 30' wide and 23' tall, and the 0,0 point of the file would be moved to the lower left of the larger box (the original 28" x 40" press sheet) before this that selection was made and the the script is run.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now