Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Create guides in Illustrator CS4 JS

Participant ,
Feb 05, 2010 Feb 05, 2010

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

TOPICS
Scripting
4.1K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Guru , Feb 06, 2010 Feb 06, 2010

#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!!!

Translate
Adobe
Guru ,
Feb 06, 2010 Feb 06, 2010

#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!!!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Feb 08, 2010 Feb 08, 2010

That great, Mark, thank you very much.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Feb 12, 2010 Feb 12, 2010

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Feb 13, 2010 Feb 13, 2010

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;

}

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Feb 15, 2010 Feb 15, 2010

Hi Mark,

Thank you This is really working good.. But this is working only for the rectangle objects not for ellipse or triangle. Ok instead of that is there possible to give all the shapes with close path items. (Like triangle, pentagonal shapes etc. path with so many sides)   PFA

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Feb 15, 2010 Feb 15, 2010

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…

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Feb 15, 2010 Feb 15, 2010
LATEST

Hi mark,

Its ok thank you so much

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines