Copy link to clipboard
Copied
I am looking for some help in creating a script that can automatically select objects of the same width and height, in this case 6 circles used as registration marks for a client that requires them to be in a certain named layer. Currently I manually select the circles and use the same fill color menu command but I am trying to automate the task so that I don't have to worry about selecting it myself. When I do the same fill command I also have to manually delete another mark that isn't needed when I do that, so I figured the easiest way would be to script it so that it is by size because that way it wouldn't select the mark that I need to delete anyways.
Can this be done and if so can someone point me into the right direction or give me some pointers?
I would need the script to be able to automatically select the circles and if possible move it to a named layer.
with the limited information available, i was forced to make some assumptions. but this should do what you want, or at least give you the tools to edit it to do what you want.
This selects all items that have a "Registration" fill color, then it checks all the selected items to see if they're smaller than a maximum size, or larger than a minimum size.
https://github.com/wdjsdev/public_illustrator_scripts/blob/master/get_registration_marks.js
/*
Script Name:
Get Registration marks
S...
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Manan,
Thank you for sending me that script. I was able to sort of get something to work out of it, but it still required a lot of clicking on things which I am trying to avoid as much as possible because this is a task that I do about 100 times a day.
-Brock
Copy link to clipboard
Copied
with the limited information available, i was forced to make some assumptions. but this should do what you want, or at least give you the tools to edit it to do what you want.
This selects all items that have a "Registration" fill color, then it checks all the selected items to see if they're smaller than a maximum size, or larger than a minimum size.
https://github.com/wdjsdev/public_illustrator_scripts/blob/master/get_registration_marks.js
/*
Script Name:
Get Registration marks
Script Description:
Select all items using the registration fill color.
Loop selected items to determine if they meet min/max size criteria
Selected items that meet criteria are moved to registration layer
Selected items that do not meet criteria can be deleted or ignored
Author:
William Dowling
Email: illustrator.dev.pro@gmail.com
Github: github.com/wdjsdev
Paypal: paypal.me/illustratordev
Forum Post:
https://community.adobe.com/t5/illustrator-discussions/script-to-select-multiple-objects-that-are-all-sized-the-same/td-p/12460743
Github Repo:
https://github.com/wdjsdev/public_illustrator_scripts/blob/master/get_registration_marks.js
*/
function getRegMarks()
{
// set up the script and declare some variables
var doc = app.activeDocument;
var layers = doc.layers;
var swatches = doc.swatches;
var regSwatch = swatches["[Registration]"];
// deselect all and then select all items that are filled with [Registration] color
doc.selection = null;
doc.defaultFillColor = regSwatch.color;
app.executeMenuCommand("Find Fill Color menu item");
// check to see whether any items were selected.
// if not, alert the user and exit.
var sel = doc.selection;
if (!sel.length)
{
alert("No registration marks found.");
return;
}
// if we've gotten this far that means registration marks have been successfully
// selected. now let's create a new layer to copy them to.
var myRegMarksLayer = layers.add();
myRegMarksLayer = "Registration";
// You can also target
// an existing layer by name instead of creating a new one.
// to use an existing layer, you can get it like this:
// var myRegMarksLayer = layers["Registration"]; // just enter the name of the layer you want between the brackets
// here we set a variable to determine whether a selected object is
// the correct size. Let's say your registration circles are 50pt in
// diameter and your other mark that you need to delete is 25pt wide/tall
// if we set the minimum size variable to, say, 45pt, then we can check
// the dimensions of each selected piece to see if it meets the minimum size
// requirement. any pieces that do not meet the requirement can be deleted or ignored.
var minimumSize = 45; // use this line if you only want items that are at least this big
// var maximumSize = 50; // use this line if you only want items that are at MOST this big.
for (var s = sel.length - 1; s >= 0; s--)
{
// now, let's check to see if the current selected item
// meets the min/max criteria set above
// i'm assuming we're just checking width here. but
// you can change this to height if you want, or you could
// get some information about the area of the object
// if that is more useful.
if (sel[s].width >= minimumSize)
{
sel[s].moveToBeginning(myRegMarksLayer);
}
else
{
// choose what to do here.. you can ignore it..
// or you can delete it. if you want to ignore it,
// just comment the next line.
sel[s].remove();
}
}
}
getRegMarks();
Copy link to clipboard
Copied
Dilliam,
Thank you so much for responding. I have been doing a lot of research on this forum about illustrator scripts and your name seems to pop up on most of the posts I have read, so I am very thankful that you are helping me with this.
I attempted to run the script in Illustrator and I am getting back an error for line 30.
I attempted to change it from
var regSwatch = swatches "[Registration]";
to
var regSwatch = swatches "DIE";
Which is the swatch name that I use for the marks. It seems like it isn't recognizing it somehow. I tried changing the mark swatch name to [Registration] in illustrator and it still came up with an error.
I have a sample file so you can see what I am trying to do. The one that says start is the file that I begin with, and the one that says end is the way it needs to be setup.
Essentially, it is a cut file for a cutting machine that needs to have the file setup in a certain way for it to read it properly.
The rectangle zund mark needs to be in a layer called "z"
The 6 "reg marks" or dots need to be in a layer called "cam"
and the stroke die lines need to be in a layer called "cut"
Then I need it to delete anything else in the file that is not those three objects if not the automatic cutter gets confused.
I have a script and action combo to setup the layers, then to select the DIE stroke and move it to the cut layer. I have sourced that script from a previous forum post so I don't really know what I am doing. My issue is that the zund mark and the 6 reg marks share the same spot color so I can't do the same method as I did with the stroke, so I am trying to have the script select these marks based on the size.
Let me know if this helps and if you have any more pointers. I really appreciate your help on this.
-Brock
Copy link to clipboard
Copied
Regarding the swatch, change the line to
var regSwatch = swatches["[Registration]"];
or
var regSwatch = swatches["DIE"];
Copy link to clipboard
Copied
YES! This was what was tripping me up. I was forgetting the [ ] around the DIE swatch.
This code works perfect for my needs now after adjusting it to fit my needs.
Thanks everyone.
Copy link to clipboard
Copied
Hey Brock. Sorry about that. i didn't test the code before i sent it over (because often times it takes just as long to generate a sample file from scratch as it does to wite the code. Those silly brackets inside of the "[Registration]" swatch name threw me off. Most swatches don't have that in the name, so seeing those brackets tricked me into thinking i had accessed the array properly when i had not.
my shame shall live in perpetuity. But i'm glad it's all working for ya. 😃
Copy link to clipboard
Copied
Thanks Femke.
I started typing out a whole thing about how i messed up and fixing it etc.. but family life got in the way.
The code was updated on github yesterday to reflect this fix, but i didn't get to posting here about it until now.
Copy link to clipboard
Copied
It's alright. Thanks.
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more