Copy link to clipboard
Copied
Im looking for script that I can run, that will draw a cross-hair in the center of every circle in my file. this is for precise drilling locations where the holes are marked with a circle. thanks
I already had a script that performs something similar to what you described (for sign production as well) so I simplified it and added defaults that you can easily adjust to change the crosshair color, width, height, and weight.
A few things to note:
Copy link to clipboard
Copied
Do you manually select the circles before running the script? Because it's easier than having the script analyze every shape in the document to see if it's a circle.
What crosshair settings are preferred? You may need some stroke color, stroke weight, line length (pixels, millimeters, or other units).
Copy link to clipboard
Copied
There are some non-scripting ways, for example Global Edit.
You may share a sample Illustrator file, so one can check if that would work.
Copy link to clipboard
Copied
I already had a script that performs something similar to what you described (for sign production as well) so I simplified it and added defaults that you can easily adjust to change the crosshair color, width, height, and weight.
A few things to note:
Let me know if this does what you need or if you have any questions/issues? Cheers!
// Draw a crosshair mark at the center of each selected object.
(function () {
// get the active document
try {
var doc = app.activeDocument;
} catch (e) {
alert("No active document.\n" + e);
return;
}
// get the document selection
var sel = doc.selection;
if (!selection.length) {
alert("Empty selection.\nMake a selection and rerun the script.");
return;
}
// setup script defaults
var marksLayerName = "Center Crosshair Marks";
var crosshairStrokeWeight = ".0625 in";
var crosshairWidth = ".5 in";
var crosshairHeight = ".25 in";
var crosshairStrokeColor = new RGBColor();
crosshairStrokeColor.red = 255;
crosshairStrokeColor.green = 0;
crosshairStrokeColor.blue = 0;
// convert default unit values to points
var crosshairStrokeWeight = UnitValue(crosshairStrokeWeight).as("pt");
var crosshairWidth = UnitValue(crosshairWidth).as("pt");
var crosshairHeight = UnitValue(crosshairHeight).as("pt");
// create a layer to hold the crosshair marks
var crosshairLayer = createLayer(marksLayerName);
// draw center crosshair mark for each selected object
var bounds, centerX, centerY;
for (var i = 0; i < sel.length; i++) {
bounds = sel[i].geometricBounds; // [left, top, right, bottom]
var centerX = bounds[0] + (bounds[2] - bounds[0]) / 2;
var centerY = -(bounds[1] - (bounds[1] - bounds[3]) / 2);
drawCrosshair(
crosshairLayer,
centerX,
centerY,
crosshairWidth,
crosshairHeight,
crosshairStrokeColor,
crosshairStrokeWeight
);
}
/**
* ************************************
* HELPER FUNCTIONS
* ************************************
*/
function createLayer(name) {
var layer;
try {
layer = doc.layers.getByName(name);
} catch (e) {
layer = doc.layers.add();
layer.name = name;
}
return layer;
}
function drawCrosshair(layer, x, y, width, height, strokeColor, strokeWeight) {
// make a group to hold the parts
var crosshair = layer.groupItems.add();
// draw x-line
var xLine = crosshair.pathItems.add();
xLine.setEntirePath([
[x - width / 2, -y],
[x + width / 2, -y],
]);
xLine.strokeColor = strokeColor;
xLine.stroked = true;
xLine.strokeWidth = strokeWeight;
xLine.filled = false;
// draw y-line
var yLine = crosshair.pathItems.add();
yLine.setEntirePath([
[x, -y + height / 2],
[x, -y - height / 2],
]);
yLine.strokeColor = strokeColor;
yLine.stroked = true;
yLine.strokeWidth = strokeWeight;
yLine.filled = false;
}
})();
Copy link to clipboard
Copied
perfect! thanks!