Copy link to clipboard
Copied
Hi, I need to create 4 guides in Illustrator page 3/16 inch from each edge of the artboard using javascript.
Could someone help me.
Thank you very much.
Yulia
#target illustrator
var docRef = app.activeDocument;
with (docRef) {
var myGuides = pathItems.rectangle(height -13.5, 13.5, width -27, height -27, false);
myGuides.guides = true;
}
I only have CS2 so I don't know how this will work with your multi artboards!!!
Copy link to clipboard
Copied
#target illustrator
var docRef = app.activeDocument;
with (docRef) {
var myGuides = pathItems.rectangle(height -13.5, 13.5, width -27, height -27, false);
myGuides.guides = true;
}
I only have CS2 so I don't know how this will work with your multi artboards!!!
Copy link to clipboard
Copied
That great, Mark, thank you very much.
Copy link to clipboard
Copied
Hi,
Same way i have used some rectangle and square boxes. with selecting some few objects inside those i have to give -3 mm offset as guide. any script for this..
Pls make sure that i have to give -3 mm offset only for the selected objects.
Thankyou
Joe
Copy link to clipboard
Copied
Joe, I think that this should be pretty close to what you want. It looks for path items in the selection, then should check to see if its a rectangle if it is then inset guides 3mm. I think it needs a check for right & left direction control points but I have NOT the time at the mo.
#target illustrator
var docRef = app.activeDocument;
// Convert mm to points
var thisOffset = 3 * 2.834645;
with (docRef) {
// Get selected items Array
if (selection != '') {
for (var i = 0; i < selection.length; i++) {
// Check if its a path item
if (selection instanceof PathItem) {
// This might need a better test!!!
if (isRectangle(selection)) {
// Ignore any stroke values
var thisPath = selection.geometricBounds;
// Calculate guide box
var guideTop = thisPath[1] - thisOffset;
var guideLeft = thisPath[0] + thisOffset;
var guideWidth = (thisPath[2] - thisPath[0]) - (thisOffset * 2);
var guideHeight = (thisPath[1] - thisPath[3]) - (thisOffset * 2);
// Make new rectangle
var myGuides = pathItems.rectangle(guideTop, guideLeft, guideWidth, guideHeight, false);
// Make it guides
myGuides.guides = true;
} else {
alert('A Path Item was NOT a rectangle?');
}
} else {
alert('An object was NOT a Path Item?');
}
}
} else {
alert('You have NO selected objects?');
}
}
function isRectangle(pathObject) {
with (pathObject) {
if (pathPoints.length != 4) return false;
if (pathPoints[0].anchor[0] != pathPoints[3].anchor[0]) return false;
if (pathPoints[1].anchor[0] != pathPoints[2].anchor[0]) return false;
if (pathPoints[0].anchor[1] != pathPoints[1].anchor[1]) return false;
if (pathPoints[2].anchor[1] != pathPoints[3].anchor[1]) return false;
return true;
}
}
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Rectangles/Squares is pretty easy to deal with. Polygons require trigonometry that I have NOT used since school and that was some years ago (a few beers have rinsed my mind since then). Shapes with béziers to control curves would possibly wreck a weekend… I have been trying to use trig but have nothing sorted just yet…
Copy link to clipboard
Copied
Hi mark,
Its ok thank you so much
Find more inspiration, events, and resources on the new Adobe Community
Explore Now