Skip to main content
Participant
January 21, 2011
Question

I need a script that adds specific sized crop marks around a selected object.

  • January 21, 2011
  • 1 reply
  • 599 views

This is what it needs to do:

//Get height and width of currently selected object//

var myDoc = app.activeDocument;

var selectedArt = myDocument.selection;

var artBounds = selectedArt [0] .geometricBounds;

//Then pass these on two say "artWidth" and "artHeight" which adds .25 inches in pixel mesurements to both stored height and width variables.//

var artWidth = artBounds[0 + .25in “in pixel value”]

var artHeight = artBounds[1 + .25in “in pixel value”]

//Then passes that information on to a document write function that will create a new box around the object that is centered awround the originally selected object’s position//

function makeDimensions()
{

}

// From here I think I can work within the actions pallet to finish the steps//

But how do I start this?

This topic has been closed for replies.

1 reply

Muppet_Mark-QAl63s
Inspiring
January 22, 2011

Illustrator uses points as is measurement units. If you wish to use other then you will need to use 'UnitValues' in your script… This should give you the basic idea of how to create a new box .25 inch around the current selection. The example is set to work with just the one item but you can easily change that if you wish. Using 'visualBounds' in many cases is a better option as it also accounts for stroke widths should you have any… Your code is JavaScript and you are going to be disappointed to find you can't call on actions with this language. So you are going to have to code the rest too… At least you have the start…

#target illustrator function main() {      if (app.documents.length == 0) {           alert('Open a document before running this script');                return;      } else {           var docRef = app.activeDocument;           with (docRef) {                if (selection.length == 0) {                     alert('No items are selected…');                     return;                }                if (selection.length > 1) {                     alert('Too many items are selected…');                     return;                } else {                     var selVB = selection[0].visibleBounds;                     var rectTop = selVB[1] + 18;                     var rectLeft = selVB[0] - 18;                     var rectWidth = (selVB[2] - selVB[0]) + 36;                     var rectHeight = (selVB[1] - selVB[3]) + 36;                     var padBox = pathItems.rectangle(rectTop, rectLeft, rectWidth, rectHeight, false);                     padBox.stroked = false;                     redraw();                }                     }      } } main();