8 Replies Latest reply on Jun 9, 2013 3:28 PM by pixxxel schubser

    Dimension Illustrator CS6

    jay fresno Level 1

      Does anyone know of a script that will automatically put dimensions on rectangular shapes in Illustrator CS6?

        • 1. Re: Dimension Illustrator CS6
          vinoth_mannu Level 1

          #target illustrator

           

          var docRef = app.activeDocument;

           

          with (docRef) {

               $.writeln(geometricBounds);

               $.writeln(visibleBounds);

          }

           

          This might be useful.

          • 2. Re: Dimension Illustrator CS6
            StanStill Level 1

            I am by no means a programmer/scriptor, but I just recently found and tinkered with a script to do pretty much that.

             

            This one puts the dimensions in a specified location on the artboard, rounded to hundredths of an inch. It's probably riddled with all kinds of artifacts from the script that it was adapted from which don't do anything, but it works, which is good enough for me. I use it for putting measurements of printing plate files, but it's pretty well commented so you can find the things you need to change.

             

             

            /*

            Stan's Dimension Script

            */

             

            #target illustrator

             

             

            var myDocument = app.activeDocument;

            var selectedObject = myDocument.selection;

            var activeLayer = app.activeDocument.activeLayer;

            var layerName = activeLayer.name;

            activeLayer.name = "plate";

             

             

            // Get position of selection bounds

            var myBounds = selectedObject[0].geometricBounds;

             

             

            // Set up X and Y co-ordinates

            var x1 = myBounds[0];

            var x2 = myBounds[2];

            var y1 = myBounds[1];

            var y2 = myBounds[3];

             

             

            // Set up data for the Dimensions

            var ptWidth = myBounds[2] - myBounds[0];

            var ptHeight = myBounds[1] - myBounds[3];

            var tmpWidth = (ptWidth / 72);

            var tmpHeight = (ptHeight / 72);

            var finalWidth = tmpWidth.toFixed(2);

            var finalHeight = tmpHeight.toFixed(2);

             

             

            //Find Centre of Object

            var xCentre = x1 + (ptWidth / 2);

            var yCentre = y1 - (ptHeight / 2);

             

             

            // Find text swatch position

            var origSwatches = myDocument.swatches;

            var swatchesLength = origSwatches.length;

            for (i=0;i<swatchesLength;i++) {

                      if (origSwatches[i].name == "text" || origSwatches[i].name == "text") {

                                var textSwatch = origSwatches[i];

                                }

                      }

             

             

            // Check if text swatch is defined

            if (textSwatch == undefined) {

                      alert("Please create a text swatch");

                      }

            else {

                      makeDimensions();

                      releaseLayer();

            }

             

             

             

             

            function makeDimensions() {

             

             

            // Lock the active layer to prevent colour change

            activeLayer.locked = true;

             

             

            // Create Dimensions Layer

            //Now moved to separate function

            /*var mLayer = myDocument.layers.add();

            //mLayer.name = "Dimensions";*/

            mLayerCreate();

             

             

            // Set Document colors to text

            myDocument.defaultFillColor = textSwatch.color;

            myDocument.defaultStrokeColor = textSwatch.color;

             

             

             

            // Create groups for dimensions

            var yMeasure = mLayer.groupItems.add();

            yMeasure.name = "Height";

            var xMeasure = mLayer.groupItems.add();

            xMeasure.name = "Width";

             

             

             

             

            // Create Text for X Measurement

            var xText = xMeasure.textFrames.add();

            xText.contents = finalWidth + " in";

            xText.top = 132;

            xText.left = 260;

            xText.paragraphs[0].paragraphAttributes.justification = Justification.CENTER;

            for (i=0;i<xText.textRange.characters.length;i++) {

                      xText.characters[i].characterAttributes.fillColor = textSwatch.color;

            }

             

             

             

             

            // Create Text for Y Measurement

            var yText = yMeasure.textFrames.add();

            yText.contents = finalHeight + " in";

            yText.top = 132;

            yText.left = 165;

            yText.paragraphs[0].paragraphAttributes.justification = Justification.CENTER;

            for (i=0;i<yText.textRange.characters.length;i++) {

                      yText.characters[i].characterAttributes.fillColor = textSwatch.color;

                      }

            }

             

             

            function mLayerCreate() {

             

                      var mLayerNotExists = true;

             

             

            try {

                app.activeDocument.layers.getByName("Dimensions").remove();

            } catch (e) {};

             

             

            // Check if Dimensions layer exists

            for(i = 0; i < activeDocument.layers.length; i++){

                      if(activeDocument.layers[i].name == "Dimensions"){

                                mLayer = activeDocument.activeLayer = activeDocument.layers[i]; // not using var to declare makes it global

                                mLayerNotExists = false;

                      }

            }

             

             

            // Create Dimensions Layer

            if(mLayerNotExists){

            mLayer = myDocument.layers.add();// not using var to declare makes it global

            mLayer.name = "Dimensions";

            }

            }

             

             

            function releaseLayer(){

                      for(i = 0; i < activeDocument.layers.length; i++) {

                                if(activeDocument.layers[i].name == "plate") {

                                          activeDocument.layers[i].name = layerName;

                                          activeDocument.layers[i].locked = false;

                                          activeDocument.activeLayer = activeDocument.layers[i];

                                          }

                                }

             

             

                      }

            • 3. Re: Dimension Illustrator CS6
              jay fresno Level 1

              I couldn't get either the vinosh or stanstill scripts to work. Guess I don't understand how to use them.

              • 4. Re: Dimension Illustrator CS6
                Larry G. Schneider Adobe Community Professional & MVP

                For the first, it will write the dimensions (to 10 decimal points) in the JavaScript Console window accessed from the Window menu in the ESTK. For the second, copy/paste into a new window in the ESTK and save it. Make sure you have made a swatch called text in the Swatch panel of your file and have an item selected. Then run the script. This is what happens

                 

                Screen shot 2013-06-07 at 3.13.25 PM.png

                • 5. Re: Dimension Illustrator CS6
                  pixxxel schubser Level 5

                  @StanStill,

                   

                  you can start your script in many places accelerate and optimize.

                  for example change this:

                   

                  yText.paragraphs[0].paragraphAttributes.justification = Justification.CENTER;
                  
                  for (i=0;i<yText.textRange.characters.length;i++) {
                            yText.textRange.characterAttributes.fillColor = textSwatch.color;
                            }
                  

                   

                  to:

                   

                  yText.textRange.paragraphAttributes.justification = Justification.CENTER;
                  yText.textRange.characterAttributes.fillColor = textSwatch.color;
                  

                   

                   

                  also you can this:

                   

                   

                  var swatchesLength = origSwatches.length;
                  for (i=0;i<swatchesLength;i++) {
                            if (origSwatches[i].name == "text" || origSwatches[i].name == "text") {
                                      var textSwatch = origSwatches[i];
                                      }
                            } 
                  
                  // Check if text swatch is defined
                  if (textSwatch == undefined) {
                            alert("Please create a text swatch");
                            }
                  else {
                            makeDimensions();
                            releaseLayer();
                  }
                  

                   

                  change to:

                   

                   

                  try {
                      var swatchName = "text";
                      var textSwatch = myDocument.swatches.getByName (swatchName);
                      makeDimensions();
                      releaseLayer();
                      }
                  catch (myError) {
                      alert("Please create a text swatch");
                      // better as an alert: you can define your text swatch here
                      }
                  

                   

                   

                  There is still much more to optimize. Good luck

                  • 6. Re: Dimension Illustrator CS6
                    StanStill Level 1

                    Jay, I have my artboard set up kind of screwy, and by the time I figured out how to change the origin point of the artboard, I had already been using the script for a while and have decided to just leave it like it is. It is probably putting the dimensions way off the artboard for you, so zoom out and see if you find it. Also, the rectangle has to be selected when you run the script.

                     

                    Under // Create text for X Measurement (and Y Measurement) there are top and left values that situate the width and height on the artboard. If you play with those, you should be able to move where the numbers appear.

                     

                    But first, are you saving the files as .jsx files?

                    • 7. Re: Dimension Illustrator CS6
                      StanStill Level 1

                      Wow... that looks so much simpler than the way it was! Thanks.

                      • 8. Re: Dimension Illustrator CS6
                        pixxxel schubser Level 5

                        My pleasure.

                         

                        You are on the right way. But there is still much to be done.