Skip to main content
Klаus
Inspiring
January 5, 2013
Question

CS6: Measure a shape’s area?

  • January 5, 2013
  • 3 replies
  • 24661 views

Hi there!

With Illustrator CS6, is there a way to measure/calculate the enclosed area of a given vector shape?

Thanks

Klaus

    This topic has been closed for replies.

    3 replies

    Participant
    April 9, 2015

    None of these work for me, it just keeps giving me a syntax error. Why is this?

    Participant
    April 9, 2015

    It works for me. I think the culprit could be your not saving it as really plain text, just changing the file ending is not enough.

    Or that your actually have a syntax error.

    The script is not mine, but I take liberty and attach my version of the entire script below.

    But be aware that if you have too many and too complex shapes, the script does not calculate correct at all times.

    Best regards, Alfred.

    if (app.documents.length > 0) {

      if (app.activeDocument.selection.length < 1) {

      alert('Select a path first');

      } else if (app.activeDocument.selection[0].area) {

      // Individual Items

      var objects =  app.activeDocument.selection;

      } else if (app.activeDocument.selection[0].pathItems) {

      // Group/Compound Shape

      var objects = app.activeDocument.selection[0].pathItems;

      } else {

      alert('Please select a path or group.');

      }

      // Collect info

      var totalArea = 0;

      for (var i=0; i<objects.length; i++) {

      if (objects.area) {

      var totalArea = totalArea + objects.area;

      }

      }

      // Conversions

      var ppCm = 28.34645669291;

      var areaInCm = Math.round((totalArea / ppCm / ppCm) * 100) / 100;

      if (areaInCm < 0) var areaInCm = -areaInCm;

      // Display

      alert('Shape Area\n' + areaInCm + ' square centimeters \n' + i + ' shapes');

    }





    June 9, 2013

    I'm sorry to be so ignorant, but could someone please provide what precisely needs to be copied into the text document and saved as .jsx (in order to calculate the area of any given vector shape in Adobe Illustrator CS6)? I've tried several variations of the code from the above link, with and without the beginning "alert" and parenthesis, and with or without the closing semicolon, but am always getting a syntax error when I try to launch the script in Illustrator.

    Thanks for your help.

    Larry G. Schneider
    Community Expert
    Community Expert
    June 9, 2013

    This is the line


    alert("Area & Length\nArea: " + (app.activeDocument.selection[0].area/5184).toFixed(3) + "\nLength: " + (app.activeDocument.selection[0].length/72).toFixed(3));

    This is for inches to 3 decimal places.

    Copy the above and paste into a new window in either the ExtendScript Tool Kit (ESTK found in Applications/Utilities/Adobe Utilities) or in a text editor. If you use the text editor make sure you save it as plain text with a .jsx extension. Place it in the Application/Adobe Illustrator CSX/Presets/en_US/Scripts folder and restart. Open a file, select an object and run the script from File/Scripts.

    999ducatista
    Participating Frequently
    November 6, 2014

    so it seems the area script will calculate the area of a simple shape, like a rectangle or a circle, but not a compound shape, or an odd shape like a letter (made with outline) or a donut shape....bummer...still on the hunt myself for this solution in CS6...

    Jacob Bugge
    Community Expert
    Community Expert
    January 5, 2013

    Klaus,

    I hope this thread will help you.

    http://forums.adobe.com/message/4742474#4742474

    Klаus
    KlаusAuthor
    Inspiring
    January 5, 2013

    I’ve read that before, but it did not actually help me.

    Klаus
    KlаusAuthor
    Inspiring
    January 5, 2013

    Then why don't you just ask how to handle scripts?

    Copy the line of code into a text document (ASCII), save it as a .jsx in Illustrator program folder > Presets > Scripts, restart Illustrator and select from  File > Scripts.


    Thanks, Monika.

    Had to alter the code, though, because none of the versions there prompted me with correct millimeter or square millimeter values.