Copy link to clipboard
Copied
Illustrator generates guides that extend over the entire work area and inevitably they also end up on other artboards where those guides are useless but above all distract Very. You could create a script that based on the selected guides these guides are removed from the standard position and inserted in the same position but being part of the table only Artboard selected? Manually it is a feasible operation but the steps are long to do (when in my opinion the right behavior for the guides would be to be traced in the s Artboard only and not the whole area.) But the practicality of Adobe programmers we've known for decades. Can anyone help me in this? I think it's a very simple script to implement
Hi @Nicky G., oh yeah, that script had lots of bugs! (edit: fixed now) Anyway, no problem, try this version, which attempts to work as per your proposal. 🙂
- Mark
/**
* Change selected "pasteboard" guides to "artboard" guides
* when they intersect with the active artboard.
* @author m1b
* @discussion https://community.adobe.com/t5/illustrator-discussions/script-transfer-guides-to-artboard/m-p/13749896
*/
(function () {
var doc = app.activeDocument,
items = doc.selection,
...
Copy link to clipboard
Copied
Hi @Nicky G., this is a cool idea. I get annoyed guides messing up my pasteboard, too. It wasn't as straightforward to write the script as you might think, but I think I've got it working. Let me know how it works for you.
- Mark
/**
* Change all "pasteboard" guides to "artboard" guides
* when they intersect with one or more artboards.
* @author m1b
* @discussion https://community.adobe.com/t5/illustrator-discussions/script-transfer-guides-to-artboard/m-p/13749896
*/
(function () {
var doc = app.activeDocument,
artboards = doc.artboards,
items = doc.pathItems,
counter = 0;
for (var i = items.length - 1; i >= 0; i--) {
var item = items[i];
if (
item.guides !== true
|| item.locked == true
|| item.width * item.height > 0
|| !item.hasOwnProperty('pathPoints')
|| item.pathPoints.length !== 2
)
continue;
var b = item.geometricBounds,
orientation = 0,
max = -Infinity,
min = Infinity;
for (var j = artboards.length - 1; j >= 0; j--) {
var a = artboards[j].artboardRect;
if (boundsDoIntersect(a, b)) {
if (item.height == 0) {
// horizontal guide
orientation = 1;
max = Math.max(max, a[2]);
min = Math.min(min, a[0]);
}
else {
// vertical guide
orientation = 2;
max = Math.max(max, -a[3]);
min = Math.min(min, -a[1]);
}
}
}
if (
orientation !== 0
&& !hasCommonDimension([min, -min, max, -max], b)
) {
if (orientation === 1) {
// horizontal
setCornerPathPoint(item.pathPoints[0], [max, b[1]]);
setCornerPathPoint(item.pathPoints[1], [min, b[1]]);
}
else if (orientation === 2) {
// vertical
setCornerPathPoint(item.pathPoints[0], [b[0], -max]);
setCornerPathPoint(item.pathPoints[1], [b[0], -min]);
}
counter++;
}
};
alert('Converted ' + counter + ' guides.');
})();
/**
* Sets a path point's position
* and converts to corner point.
* @param {PathPoint} pathPoint - an Illustrator PathPoint.
* @param {Array<Number>} p - [x, y].
*/
function setCornerPathPoint(pathPoint, p) {
pathPoint.anchor = p;
pathPoint.leftDirection = p;
pathPoint.rightDirection = p;
}
/**
* Returns true when bounds intersect.
* @param {Array<Number>} a - bounds [l,t,r,b].
* @param {Array<Number>} b - bounds [l,t,r,b].
* @returns {boolean}
*/
function boundsDoIntersect(a, b) {
return !(
b[0] > a[2]
|| b[2] < a[0]
|| b[1] < a[3]
|| b[3] > a[1]
);
}
/**
* Returns true when bounds `a` and `b`
* share a common dimension, for example if
* both have the same left and right edges.
* @param {Array<Number>} a - bounds [l,t,r,b].
* @param {Array<Number>} b - bounds [l,t,r,b].
* @param {Number} [tolerance] - how close in points.
* @returns {Boolean}
*/
function hasCommonDimension(a, b, tolerance) {
tolerance = tolerance == undefined ? 0.01 : tolerance;
return (
(
Math.abs(a[1] - b[1]) < tolerance
&& Math.abs(a[3] - b[3]) < tolerance
)
|| (
Math.abs(a[0] - b[0]) < tolerance
&& Math.abs(a[2] - b[2]) < tolerance
)
)
};
Edit 2023-04-26: fixed three problems—handles overlapping artboards, doesn't create unwanted duplicate guides, and doesn't try to operate on guides that have already been trimmed by a previous running of the script. A difference is that if there are multiple artboards in line with the guide, it will span them all.
Copy link to clipboard
Copied
Hi @m1b ,
Thank you so much for your availability and I'm glad you shared with me the need and frustration that this illustrator thing causes in us users, this and many others to tell the truth. I'm always of the opinion that this thing should be solved natively in the software, but I understand that at birth illustrator contained only one table so the need to outline the guides only on the worktable and not in the whole surrounding area did not exist.
Back to us, thank you for this script, great, and I'm sure it wasn't easy, but you were great.
However, as an improvement, I would like to make you some notes on what doesn't work "the right way", but I also specified it in the initial post.
Now from your example we have 2 artboards on top of each other board1,board2.
The script just puts the same guides on the same artboards only within the area of the artboard.
Moral of the story even with the script I would always have the same problem. and I'll explain better.
Table 1: Let's assume that I need 4 horizontal and 6 vertical guides.
the 6 vertical guides go past plate1 and end up in plate2 (example of your arrangement of artboards on top of each other) .
Table2: Let's assume that I need 8 vertical guides (arranged differently with respect to table1)... In the end, on table2 I would have traced 8 guides of table2 + 6 Guides of table1 (14 total)...
If I use your script, the result will always be 14 guides for board2 and 5+6 guides (horizontal + vertical) for board1.
therefore equally the guides of table1 will interfere with table2.
I proposed to: having selected table1 (focus), select "only" the guides we want to insert in the table and start the script (therefore only the selected guides will cut on table1)
Select the guides of board2 keeping focus on artboard2 and run the script.
I noticed another thing:
If after running the script I have my guides inside the artboard, and I add other "Classic illustrator" guides, if I run the script again, the guides previously already present inside the artboard (limited to the artboard), are duplicated one above the other one. And it's a mistake.
Copy link to clipboard
Copied
Hi @Nicky G., oh yeah, that script had lots of bugs! (edit: fixed now) Anyway, no problem, try this version, which attempts to work as per your proposal. 🙂
- Mark
/**
* Change selected "pasteboard" guides to "artboard" guides
* when they intersect with the active artboard.
* @author m1b
* @discussion https://community.adobe.com/t5/illustrator-discussions/script-transfer-guides-to-artboard/m-p/13749896
*/
(function () {
var doc = app.activeDocument,
items = doc.selection,
a = doc.artboards[doc.artboards.getActiveArtboardIndex()].artboardRect,
counter = 0;
if (items.length == 0) {
alert('Please select one or more guides and try again.');
return;
}
for (var i = items.length - 1; i >= 0; i--) {
var item = items[i];
if (
item.guides !== true
|| item.locked == true
|| item.width * item.height > 0
|| !item.hasOwnProperty('pathPoints')
|| item.pathPoints.length !== 2
)
continue;
var b = item.geometricBounds;
if (boundsDoIntersect(a, b)) {
if (item.width == 0) {
setCornerPathPoint(item.pathPoints[0], [b[0], a[1]]);
setCornerPathPoint(item.pathPoints[1], [b[0], a[3]]);
}
else {
setCornerPathPoint(item.pathPoints[0], [a[0], b[1]]);
setCornerPathPoint(item.pathPoints[1], [a[2], b[1]]);
}
counter++;
}
};
app.redraw();
alert('Converted ' + counter + ' guides.');
})();
/**
* Sets a path point's position
* and converts to corner point.
* @param {PathPoint} pathPoint - an Illustrator PathPoint.
* @param {Array<Number>} p - [x, y].
*/
function setCornerPathPoint(pathPoint, p) {
pathPoint.anchor = p;
pathPoint.leftDirection = p;
pathPoint.rightDirection = p;
}
/**
* Returns true when bounds intersect.
* @param {Array[4]} b1 - bounds [l,t,r,b]
* @param {Array[4]} b2 - bounds [l,t,r,b]
* @returns {boolean}
*/
function boundsDoIntersect(b1, b2) {
return !(
b2[0] > b1[2]
|| b2[2] < b1[0]
|| b2[1] < b1[3]
|| b2[3] > b1[1]
);
};
Edit 2023-04-26: minor typo.
Copy link to clipboard
Copied
PERFECT!
It seems to do exactly what it's supposed to do.
You saw in the end it was simpler than the initial script, you saved 50% of the lines of code 🙂
Copy link to clipboard
Copied
Great to hear! Also, I've updated the original script so that it works sensibly, in case someone else comes along to see it! 🙂
- Mark
Copy link to clipboard
Copied
Press Shift+O to activate the Artboard Tool then create a guide by dragging on the rulers as usual. If you drop the guide into the active Artboard the guide will stay within the artboard bounds.
Copy link to clipboard
Copied
I already knew this thanks @CarlosCanto
The problem is that if I have to pull 50 guides at different times I have to enter shift+o mode every time and this is really inconvenient.
ps: I also wrote you a private message to ask you something else
Find more inspiration, events, and resources on the new Adobe Community
Explore Now