Copy link to clipboard
Copied
I have objects on the page, and I want only objects that are inside a square with a contour (with fill magenta) to be in a group. How do you do that?
Hi,
I think I knowhow your objects look like. I have edited @Silly-V script to group items inside the object which has stroke color as CutContour.
/// <reference types="Path to Illustrator TS Types folder on your system (get it at: https://github.com/bbb999/Types-for-Adobe/tree/master/Illustrator/2015.3)"/>;
//#target illustrator
function test() {
/** @TyPe {Document} */
var doc = /** @TyPe {Application} */(app).activeDocument;
/** @TyPe {PathItem} */
var landingZone;
/** @
...
Copy link to clipboard
Copied
Copy link to clipboard
Copied
The rectangle seems to have a magenta Stroke, not a magenta Fill, so I don’t quite follow, could you please post screenshots including the pertinent Panels (Layers, …) to illustrate?
What is the result supposed to be exactly – just a Group, Clipping Mask, …?
Copy link to clipboard
Copied
just a group All in one layer
I meant the contour is magenta
And not the filling
Please look up I have attached a screenshot
Copy link to clipboard
Copied
For the simplest case: Iterate through the items and test whether or not the "position" property of each item is within the "geometricBounds" of the magenta rectangle; if it is, move to a group; if it isn't, don't.
Copy link to clipboard
Copied
Right, so....?
Copy link to clipboard
Copied
pay attention
That if there are 2 sets of such objects (or more) in the document
The group will be performed for each set individually
And not for all sets
Copy link to clipboard
Copied
What's in any of these "sets" you refer to?
Copy link to clipboard
Copied
This is the basic idea, as explained above. How you want to reference the "magenta rectangle" is up to you. Here, it's referenced by name (so name it as such before running either snippet).
1. Group pathItems completely inside the magenta rectangle.
var group0 = app.activeDocument.groupItems.add();
var paths = app.activeDocument.pathItems;
for (var i = 0; i < paths.length; i++) {
var b1 = paths[i].geometricBounds;
var b2 = paths["magenta rectangle"].geometricBounds;
if ( (b1[0] > b2[0] && b1[2] < b2[2]) && (b1[1] < b2[1] && b1[3] > b2[3]) ) {
paths[i].moveToEnd(group0);
}
}
2. Group pathItems completely or partly inside the magenta rectangle.
var group0 = app.activeDocument.groupItems.add();
var paths = app.activeDocument.pathItems;
for (var i = 0; i < paths.length; i++) {
var b1 = paths[i].geometricBounds;
var b2 = paths["magenta rectangle"].geometricBounds;
if ( (b1[2] > b2[0] && b1[0] < b2[2]) && (b1[3] < b2[1] && b1[1] > b2[3]) ) {
paths[i].moveToEnd(group0);
}
}
Copy link to clipboard
Copied
Carlos Canto made a script to do somethimg like this:
Copy link to clipboard
Copied
but how can i change it to color stroke?
Copy link to clipboard
Copied
Here, try this script:
/// <reference types="Path to Illustrator TS Types folder on your system (get it at: https://github.com/bbb999/Types-for-Adobe/tree/master/Illustrator/2015.3)"/>;
#target illustrator
function test () {
/** @TyPe {Document} */
var doc = /** @TyPe {Application} */(app).activeDocument;
/** @TyPe {PathItem} */
var landingZone;
/** @TyPe {PathItem} */
var thisItem;
/** @TyPe {RGBColor} */
var itemColor;
for (var i = 0; i < doc.pageItems.length; i++) {
thisItem = doc.pageItems[i];
itemColor = thisItem.strokeColor;
// change this to CMYK colors if using CMYK.
if (itemColor.red == 255 && itemColor.blue == 255 && itemColor.green == 0) {
landingZone = thisItem;
break;
}
}
if (typeof(landingZone) == "undefined") {
alert("Landing zone not found.");
return;
}
var firstArtboard = doc.artboards[0];
var storedRect = firstArtboard.artboardRect;
doc.selection = null;
landingZone.selected = true;
firstArtboard.artboardRect = landingZone.visibleBounds;
doc.selectObjectsOnActiveArtboard();
firstArtboard.artboardRect = storedRect;
landingZone.selected = false;
app.executeMenuCommand("group");
};
test();
I just have it working in CMYK documents so you'll need to change the color part to suit your needs.
Copy link to clipboard
Copied
Thanks, I'll check in at the end of the day
Copy link to clipboard
Copied
Thanks!!! I have 2 comments:
When there are 2 such objects in the document, the script is executed for only one object in the document. I would appreciate if you change so that it changes in the document for all objects.
2. I need the group to contain the contour itself as well.
Thanks!
Copy link to clipboard
Copied
Another important note:
It is important that the script work even when there is some fill to the object.
Now it only works if the filling is none.
Copy link to clipboard
Copied
Hi,
I think I knowhow your objects look like. I have edited @Silly-V script to group items inside the object which has stroke color as CutContour.
/// <reference types="Path to Illustrator TS Types folder on your system (get it at: https://github.com/bbb999/Types-for-Adobe/tree/master/Illustrator/2015.3)"/>;
//#target illustrator
function test() {
/** @TyPe {Document} */
var doc = /** @TyPe {Application} */(app).activeDocument;
/** @TyPe {PathItem} */
var landingZone;
/** @TyPe {PathItem} */
var thisItem;
/** @TyPe {RGBColor} */
var itemColor;
for (var i = 0; i < doc.pageItems.length; i++) {
thisItem = doc.pageItems[i];
itemColor = thisItem.strokeColor;
// change this to CMYK colors if using CMYK.
//if (itemColor.red == 255 && itemColor.blue == 255 && itemColor.green == 0) {
if (thisItem.stroked && thisItem.strokeColor.spot && thisItem.strokeColor.spot.name == 'CutContour') {
landingZone = thisItem;
var firstArtboard = doc.artboards[0];
var storedRect = firstArtboard.artboardRect;
doc.selection = null;
landingZone.selected = true;
firstArtboard.artboardRect = landingZone.visibleBounds;
doc.selectObjectsOnActiveArtboard();
firstArtboard.artboardRect = storedRect;
app.executeMenuCommand("group");
}
}
};
test();
Give it a try.
Copy link to clipboard
Copied
Thanks a lot!!!!!!