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

share a script for sign production

New Here ,
Jan 16, 2025 Jan 16, 2025

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

TOPICS
How-to , Scripting

Views

124

Translate

Translate

Report

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

Community Expert , Jan 17, 2025 Jan 17, 2025

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:

  1. The script requires you to select the objects (circles) you want to mark the center of
  2. The script doesn't check to ensure any of the selected objects are actual circles so it will place a center mark on anything that is selected.
  3. You need to adj
...

Votes

Translate

Translate
Adobe
Enthusiast ,
Jan 17, 2025 Jan 17, 2025

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).

Votes

Translate

Translate

Report

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
Community Expert ,
Jan 17, 2025 Jan 17, 2025

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.

Votes

Translate

Translate

Report

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
Community Expert ,
Jan 17, 2025 Jan 17, 2025

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:

  1. The script requires you to select the objects (circles) you want to mark the center of
  2. The script doesn't check to ensure any of the selected objects are actual circles so it will place a center mark on anything that is selected.
  3. You need to adjust the defaults to match your requirements
  4. The script utilizes unit values (docs) so you can enter things like ".125 in", "3 cm", "4 pt", for the default values.
  5. All crosshair marks are grouped by their parts and placed on a separate layer.

 

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;
  }
})();

 

Votes

Translate

Translate

Report

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
New Here ,
Jan 20, 2025 Jan 20, 2025

Copy link to clipboard

Copied

LATEST

perfect! thanks!

 

Votes

Translate

Translate

Report

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