Skip to main content
Participant
May 29, 2024
Answered

Can this be automated: Selecting multiple seperate rectangle shapes and calculating the L & W

  • May 29, 2024
  • 1 reply
  • 1034 views

Hello,

 

I'm trying to make invoicing much more efficient for some dies I get sent to be made.

This requires me to list the L & W for each die and than record the SQ IN for each.

So I need 3 pieces of info for each die: L", W", total SQ IN

 

We may have up to 30 dies in a single order, and the size of each is different. Doing this manually is extremely time consuming by selecting the perimeter of each die (which is essentially a rectangle shape), recording the L and W from the transform panel and then doing L x W to get the SQ IN. 

 

It would be a huuuuge time saver to automate this. Ideally by selecting all the dies at once and performing some kind of script. Is something like this possible?

This topic has been closed for replies.
Correct answer jduncan

Hi, thanks so much for your response. The minimum requirement is for both the W and H value. So both of these values need to be rounded up to 2" if it is less than

 

And yes, we need it enabled by default and in red... if possible!


Okay, so I updated the script to add a "*" after any width or height that was rounded up to 2. Also, if either dimension of a die is less than 2, I include a "*" in the area (sq/in) info.

 

When you mentioned "in red", I didn't know if you meant the layer tab color in the layers palette or the die info text color, so I set both to red.

 

Finally, the information layer is set to "printable" so it will show up by default in Acrobat.

 

Test the udpated script below out and let me know if this get you what you needed? Cheers!

/*
DiePathDimensions.jsx for Adobe Illustrator
-------------------------------------------

Add **selected** die path width, height, and area to the artboard.

Created in response to this question on the Adobe forum:
https://community.adobe.com/t5/illustrator-discussions/can-this-be-automated-selecting-multiple-seperate-rectangle-shapes-and-calculating-the-l-amp-w/td-p/14648989
*/

(function () {
  // setup variables
  var doc, infoLayer, die, w, h, info, frame;

  // no need to continue if there is no active document
  if (!app.documents.length) {
    alert("No active document.");
    return;
  }

  doc = app.activeDocument;

  // no need to continue if there is no active selection
  if (!doc.selection.length) {
    alert("No active selection.");
    return;
  }

  // cleanup old info if found
  try {
    infoLayer = doc.layers.getByName("DIE INFORMATION");
    infoLayer.remove();
  } catch (error) {
    $.writeln("infoLayer not present");
  }

  // setup the layer/info color info
  var color = new RGBColor();
  color.red = 255;
  color.green = color.blue = 0;

  // create a layer to hold the die information
  infoLayer = doc.layers.add();
  infoLayer.color = color;
  infoLayer.name = "DIE INFORMATION";

  // please note: in the sample file, each die was grouped by iteself and
  // withing another larger group that included a few text boxes so this script
  // only acts on the first pathItem within the die pathItem group

  // iterate over each selected object
  for (var i = 0; i < doc.selection.length; i++) {
    die = doc.selection[i].pathItems[0];
    w = UnitValue(die.width, "px").as("in");
    h = UnitValue(die.height, "px").as("in");
    a = w * h;
    // ensure minimum die size requirement of 2 for both width and height
    wString = w < 2 ? "2*" : w.toFixed(4);
    hString = h < 2 ? "2*" : h.toFixed(4);
    aString = w < 2 || h < 2 ? a.toFixed(4) + "*" : a.toFixed(4);
    // format the info as:
    // XX.XXXX in x XX.XXXX in
    // XX.XXXX sq/in
    info = wString + " in x " + hString + " in\n" + aString + " sq/in";
    // add a new text frame at the top left of the die with the die info
    frame = infoLayer.textFrames.add();
    frame.position = Array(die.left, die.top);
    frame.textRange.size = 12;
    frame.textRange.fillColor = color;
    frame.contents = info;
  }
})();

 

1 reply

jduncan
Community Expert
Community Expert
May 29, 2024

That is pretty simple to do....

 

Can you provide us with a sample file to work with? This just makes things easier when working on the script and saves some of the back-and-forth messages and guess work.

 

Also, how do you want the calculated information presented? It can be saved to a text file, added into a temporary text box in the art file, copied to the clipboard...

 

Thanks!

Participant
May 29, 2024

Yes! Attached is a sample file. The blue rectangles is what we need: L", W", total SQ IN

 

Is it possible to add these values outside of each rectangle? If not, having them somewhere in the artfile (permenantly) would be best!

Participant
June 6, 2024

Is the minimum requirement for the entire die area, or for both the width and the height?

 

And, the text layer has the "printable" option set to false so that is why you aren't seeing it inside of  Acrobat. It is actually there you just need to enable the layer like below. I can make it enabled by default if you prefer, just let me know?

 


Hi, thanks so much for your response. The minimum requirement is for both the W and H value. So both of these values need to be rounded up to 2" if it is less than

 

And yes, we need it enabled by default and in red... if possible!