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

Illustrator CS6 - Adding dimensional information to a drawing

New Here ,
Jun 03, 2014 Jun 03, 2014

Copy link to clipboard

Copied

How can I add actual dimensions to an object.  I'ver created the drawing, but now want to add the dimension informaiton of a few objects into the drawing, without having to manually add the line and arrow and text.

Views

30.4K

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
Adobe
Community Expert ,
Jun 03, 2014 Jun 03, 2014

Copy link to clipboard

Copied

MrBugs,

Illy has no dimensional information.

You will need to use some plugin, or some other application, or hope that James will post a link to his script(s) for that. You can see how it works here, in the Desperate Measure thread:

Desperate Measure

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 ,
Jun 03, 2014 Jun 03, 2014

Copy link to clipboard

Copied

save the text below to a .jsx file, and run that as a script.

-------

/*

Dimensioning - Nick Blakey 2007

This will add measurement marks and dimensions to any selected item.

This script requires that a swatch already exist for the colour "Cutter" (or "cutter")

*/

var myDocument = app.activeDocument;

var selectedObject = myDocument.selection;

var activeLayer = app.activeDocument.activeLayer;

var layerName = activeLayer.name;

activeLayer.name = "Source4Measure";

// 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 Measurements

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

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

var tmpWidth = Math.round(ptWidth / 0.02834645);

var tmpHeight = Math.round(ptHeight / 0.02834645);

var finalWidth = tmpWidth / 100;

var finalHeight = tmpHeight / 100;

//Find Centre of Object

var xCentre = x1 + (ptWidth / 2);

var yCentre = y1 - (ptHeight / 2);

// Find Cutter swatch position

var origSwatches = myDocument.swatches;

var swatchesLength = origSwatches.length;

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

  if (origSwatches.name == "cutter" || origSwatches.name == "Cutter") {

  var cutterSwatch = origSwatches;

  }

  }

// Check if Cutter swatch is defined

if (cutterSwatch == undefined) {

  alert("Please create a cutter swatch");

  }

else {

  makeDimensions();

  releaseLayer();

}

function makeDimensions() {

// Lock the active layer to prevent colour change

activeLayer.locked = true;

// Create Measurements Layer

//Now moved to separate function

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

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

mLayerCreate();

// Set Document colors to Cutter

myDocument.defaultFillColor = cutterSwatch.color;

myDocument.defaultStrokeColor = cutterSwatch.color;

// Create White Color Object for Measurement Boxes

newWhite = new CMYKColor();

newWhite.black = 0;

newWhite.cyan = 0;

newWhite.magenta = 0;

newWhite.yellow = 0;

// Create groups for measurements

var yMeasure = mLayer.groupItems.add();

yMeasure.name = "Height";

var xMeasure = mLayer.groupItems.add();

xMeasure.name = "Width";

// X Measurement Line and Endpoints

var xLine1 = xMeasure.pathItems.add();

xLine1.stroked = true;

xLine1.setEntirePath ([[x1,y1+36],[xCentre - 30,y1+36]]);

var xLine2 = xMeasure.pathItems.add();

xLine2.stroked = true;

xLine2.setEntirePath ([[xCentre + 30,y1+36],[x2,y1+36]]);

var xLineEnd1 = xMeasure.pathItems.add();

xLineEnd1.stroked = true;

xLineEnd1.setEntirePath ([[x1,y1+40],[x1,y1+32]]);

var xLineEnd2 = xMeasure.pathItems.add();

xLineEnd2.stroked = true;

xLineEnd2.setEntirePath ([[x2,y1+40],[x2,y1+32]]);

// Y Measurement Line and Endpoints

var yLine1 = yMeasure.pathItems.add();

yLine1.stroked = true;

yLine1.setEntirePath ([[x2+36,y1],[x2+36,yCentre + 30]]);

var yLine2 = yMeasure.pathItems.add();

yLine2.stroked = true;

yLine2.setEntirePath ([[x2+36,yCentre - 30],[x2+36,y2]]);

var yLineEnd1 = yMeasure.pathItems.add();

yLineEnd1.stroked = true;

yLineEnd1.setEntirePath ([[x2+32,y1],[x2+40,y1]]);

var yLineEnd2 = yMeasure.pathItems.add();

yLineEnd2.stroked = true;

yLineEnd2.setEntirePath ([[x2+32,y2],[x2+40,y2]]);

/* Create Box for X Measurement text

Deprecated by use of two lines in measurement line

var xBox = xMeasure.pathItems.rectangle (y1 + 46, xCentre - 30, 60, 20);

xBox.filled = true;

xBox.fillColor = newWhite;

xBox.fillOverprint = false;

xBox.stroked = false;*/

// Create Text for X Measurement

var xText = xMeasure.textFrames.add();

xText.contents = finalWidth + "mm";

xText.top = y1 + 42;

xText.left = xCentre;

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

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

  xText.characters.characterAttributes.fillColor = cutterSwatch.color;

}

/* Create Box for Y Measurement Text

Deprecated by use of two lines in measurement line

var yBox = yMeasure.pathItems.rectangle (yCentre + 30, x2 + 26, 20, 60);

yBox.filled = true;

yBox.fillColor = newWhite;

yBox.fillOverprint = false;

yBox.stroked = false;*/

// Create Text for Y Measurement

var yText = yMeasure.textFrames.add();

yText.contents = finalHeight + "mm";

yText.rotate (-90); //, true, false, false, false, Transformation.CENTER);

yText.top = yCentre;

yText.left = x2 + 30;

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

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

  yText.characters.characterAttributes.fillColor = cutterSwatch.color;

  }

}

function mLayerCreate() {

  var mLayerNotExists = true;

// Check if measurements layer exists

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

  if(activeDocument.layers.name == "Measurements"){

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

  mLayerNotExists = false;

  }

}

// Create Measurements Layer

if(mLayerNotExists){

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

mLayer.name = "Measurements";

}

}

function releaseLayer(){

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

  if(activeDocument.layers.name == "Source4Measure") {

  activeDocument.layers.name = layerName;

  activeDocument.layers.locked = false;

  activeDocument.activeLayer = activeDocument.layers;

  }

  }

  // Set Document colors back to Default

  black = new CMYKColor();

  black.black = 100;

  myDocument.defaultFillColor = newWhite;

  myDocument.defaultStrokeColor = black;

  }

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
Guest
Jul 02, 2014 Jul 02, 2014

Copy link to clipboard

Copied

Hi Mike,

I'm trying to use the script but after running it from Illustrator CS6 it says something like "Please create a cutter swatch" but I don't really know what's this or what do I need to set up first?

Thank you for your help.

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
Enthusiast ,
Jul 02, 2014 Jul 02, 2014

Copy link to clipboard

Copied

If you need to do this a lot, buying a plug in saves you time and money in the long run.

This is what we use: Hot Door - CADtools - Overview

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 Beginner ,
Jul 27, 2014 Jul 27, 2014

Copy link to clipboard

Copied

Diego, you have to create a color swatch in your color swatch panel. Name it "Cutter".

Or if you're a little code savvy, go into the jsx file itself on line 40, and replace the two swatch names "Cutter" and "cutter" with "Black" and "black" (which, in most cases, your illustrator files have as a default swatch in the color palette).

I often have a different color for my dimension measurement lines so I make a specific CMYK color and call it Cutter, and I'm off measuring things.

If you don't understand how to make a swatch, you need to become more familiar with the basic operation of Illustrator. Go here for directions:

Adobe Illustrator * Using and creating swatches

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 ,
Jun 03, 2014 Jun 03, 2014

Copy link to clipboard

Copied

Running Mac OS?

Try: Re: Dimension Lines

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 ,
Jun 03, 2014 Jun 03, 2014

Copy link to clipboard

Copied

Running Windows 7 on PC.

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
Advisor ,
Jul 02, 2014 Jul 02, 2014

Copy link to clipboard

Copied

Check out the plugin Specctr,  http://www.specctr.com/. It's really inexpensive and gives you the ability to easily do what you want along with a ton of other cool features.

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 Beginner ,
Jul 27, 2014 Jul 27, 2014

Copy link to clipboard

Copied

Go here and download the above script:

PRODUCTION-AddDimensions.jsx

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 ,
Oct 16, 2015 Oct 16, 2015

Copy link to clipboard

Copied

This post is a few years old, and have found a better script, by Vasily. Copy and paste text in a text editor, and save files as PRODUCTION-AddDimensions2.jsx into your  scripts folder.

//============================= SPEC WRITER By Vasily ==========================// 

function main(){ 

//---------------------------------------------------- Basic Functions 

    function asSourceString(func){ 

        return func.toSource().toString().replace("(function "+func.name+"(){","").replace(/}\)$/,""); 

    } 

    function sendBTmsg(func, updateObj, resultFunc, resultFuncArgs){ 

        if(updateObj==undefined){updateObj={self: 'nothing'}}; 

        var updateObjName=updateObj.self; 

        if(updateObjName!=undefined){ 

            var bt=new BridgeTalk; 

            bt.target='illustrator'; 

            var btMsg=asSourceString(func); 

            for(all in updateObj){ 

                if(all!='self'){ 

                    var rx=new RegExp(updateObjName+'\\.'+all,'g'); 

                    btMsg=btMsg.replace(rx,updateObj[all]); 

                } 

            } 

            bt.body=btMsg; 

            //$.write(btMsg); 

            bt.onResult=function(result){ 

                if(resultFunc!=undefined){ 

                    resultFunc(result.body, resultFuncArgs); 

                } 

            } 

            bt.send(); 

        } else { 

            $.writeln("Error, function 'sendBTmsg(func, updateOb)': the update object should have a 'self' property, indentifying its' name."); 

        } 

    } 

    function CMYKtoRGB(c,m,y,k){ 

        return [(1-(c/100))*(1-(k/100)),(1-(m/100))*(1-(k/100)),(1-(y/100))*(1-(k/100))]; 

    } 

    function drawFromObjString(objString, canvasArea){ 

        var obj=eval(objString); 

        var canvas=canvasArea.graphics; 

        var counter=obj.total; 

        while(counter>=0){ 

            for(all in obj){ 

                if(all.match(/\d{1,2}$/g) && all.match(/\d{1,2}$/g)==counter){ 

                    var thisShp=obj[all]; 

                    var vectorPts=thisShp.pathPoints; 

                    canvas.newPath(); canvas.moveTo(thisShp.pathPoints[0][0],thisShp.pathPoints[0][1]); 

                    for(var j=0; j<vectorPts.length; j++){ 

                        var thisAnchor=vectorPts

                        var x=thisAnchor[0], y=thisAnchor[1]; 

                        canvas.lineTo(x,y); 

                    } 

                    canvas.closePath(); 

                    if(thisShp.fillColor!=null){ 

                        var clr=thisShp.fillColor; //RGB only 

                        var myBrush=canvas.newBrush(canvas.BrushType.SOLID_COLOR,clr); 

                        canvas.fillPath(myBrush); 

                    } 

                    if(thisShp.strokeColor!=null){ 

                        var clr=thisShp.strokeColor; //RGB only 

                        var myPen=canvas.newPen(canvas.PenType.SOLID_COLOR,[clr[0],clr[1],clr[2],1], thisShp.strokeWidth); 

                        canvas.strokePath(myPen); 

                    } 

                } 

            } 

            counter-=1; 

        } 

    } 

//------------------------------------------------------------ Specific Functions 

    function boo(){ 

        alert("Howdy!!!"); 

    } 

    function doNothing(){ 

        var nothing=function(){ 

            return; 

        }() 

    } 

    function returnRefresh(){ 

        outcome={ 

            width: width, 

            height: height, 

            unitsName: unitsName, 

        }.toSource() 

    } 

    function processRefresh(objString, args){ 

        var uiStuff=args[0]; 

        var obj=eval(objString); 

        uiStuff.wE.text=obj.width+" "+obj.unitsName; 

        uiStuff.hE.text=obj.height+" "+obj.unitsName; 

    } 

    //putSpecs() continued from paletteToAI() using 'item', 'left', 'top', 'right', 'bottom', 'width, 'height', 'unitsName', 'proportionFactor' 

    function putSpecs(){ 

        var specsLayer=null; 

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

            var thisLayer=doc.layers

            if(thisLayer.name=="Specs_Layer"){ 

                specsLayer=thisLayer; 

                thisLayer.locked=false; 

                thisLayer.visible=true; 

                break; 

            } 

        } 

        if(specsLayer==null){ 

            specsLayer=doc.layers.add(); 

            specsLayer.name="Specs_Layer"; 

        } 

        function specLine(pt_1, pt_2, parent, orientation, color, textContents, specOffset, arrowType, proportionFactor){ 

            var end_1=parent.pathItems.add(); 

            var end_2=parent.pathItems.add(); 

            var path=parent.pathItems.add(); 

            var text=parent.textFrames.add(); text.contents=textContents; 

            var hd=10*proportionFactor; 

            var vd_1=4*proportionFactor; 

            var vd_2=6*proportionFactor; 

            if(orientation=='horizontal'){ 

                if(arrowType==1){ 

                    end_1.setEntirePath([[pt_1[0]+hd,pt_1[1]],[pt_1[0]+hd,pt_1[1]+vd_1],[pt_1[0],pt_1[1]],[pt_1[0]+hd,pt_1[1]-vd_1],[pt_1[0]+hd,pt_1[1]]]); 

                    end_2.setEntirePath([[pt_2[0]-hd,pt_2[1]],[pt_2[0]-hd,pt_2[1]+vd_1],[pt_2[0],pt_2[1]],[pt_2[0]-hd,pt_2[1]-vd_1],[pt_2[0]-hd,pt_2[1]]]); 

                } else { 

                    end_1.setEntirePath([[pt_1[0],pt_1[1]],[pt_1[0],pt_1[1]+vd_2],[pt_1[0],pt_1[1]],[pt_1[0],pt_1[1]-vd_2],[pt_1[0],pt_1[1]]]); 

                    end_2.setEntirePath([[pt_2[0],pt_2[1]],[pt_2[0],pt_2[1]+vd_2],[pt_2[0],pt_2[1]],[pt_2[0],pt_2[1]-vd_2],[pt_2[0],pt_2[1]]]); 

                } 

                path.setEntirePath([pt_1,pt_2]); 

                text.left=((pt_2[0]-pt_1[0])/2)+pt_1[0]-(text.width/2); text.top=pt_1[1]-(specOffset/2); 

            } else if(orientation=='vertical'){ 

                if(arrowType==1){ 

                    end_1.setEntirePath([[pt_1[0],pt_1[1]-hd],[pt_1[0]-vd_1,pt_1[1]-hd],[pt_1[0],pt_1[1]],[pt_1[0]+vd_1,pt_1[1]-hd],[pt_1[0],pt_1[1]-hd]]); 

                    end_2.setEntirePath([[pt_2[0],pt_2[1]+hd],[pt_2[0]-vd_1,pt_2[1]+hd],[pt_2[0],pt_2[1]],[pt_2[0]+vd_1,pt_2[1]+hd],[pt_2[0],pt_2[1]+hd]]); 

                } else { 

                    end_1.setEntirePath([[pt_1[0],pt_1[1]],[pt_1[0]-vd_2,pt_1[1]],[pt_1[0],pt_1[1]],[pt_1[0]+vd_2,pt_1[1]],[pt_1[0],pt_1[1]]]); 

                    end_2.setEntirePath([[pt_2[0],pt_2[1]],[pt_2[0]-vd_2,pt_2[1]],[pt_2[0],pt_2[1]],[pt_2[0]+vd_2,pt_2[1]],[pt_2[0],pt_2[1]]]); 

                } 

                path.setEntirePath([pt_1,pt_2]); 

                text.left=pt_1[0]+(specOffset/2); text.top=((pt_2[1]-pt_1[1])/2)+pt_1[1]+(text.height/2); 

            } 

            end_1.stroked=true; end_1.strokeWidth=1; end_1.strokeColor=color; end_2.stroked=true; end_2.strokeColor=color; end_2.strokeWidth=1; 

            end_1.filled=true; end_1.fillColor=color; end_2.filled=true; end_2.fillColor=color; 

            path.stroked=true; path.filled=false; path.strokeColor=color;  path.strokeWidth=1; 

            text.textRange.characterAttributes.fillColor=color; 

        } 

        var markerColor; 

        if(INFO.colortype=='CMYKColor'){ 

            markerColor=new CMYKColor(); 

            markerColor.cyan=INFO.clr_1; markerColor.magenta=INFO.clr_2; markerColor.yellow=INFO.clr_3; markerColor.black=INFO.clr_4; 

        } else if(INFO.colortype=='RGBColor'){ 

            markerColor=new RGBColor(); 

            markerColor.red=INFO.clr_1; markerColor.green=INFO.clr_2; markerColor.blue=INFO.clr_3; 

        }  else if(INFO.colortype=='GrayColor'){ 

            markerColor=new GrayColor(); 

            markerColor.gray=INFO.clr_1; 

        } 

        var specGrp=doc.groupItems.add(specsLayer, ElementPlacement.PLACEATBEGINNING); 

        var time=new Date(); 

        var hours=time.getHours(); 

        var minutes=time.getMinutes(); 

        var seconds=time.getSeconds(); 

        if(seconds<10){seconds='0'+seconds;} 

        if(minutes<10){minutes='0'+minutes;} 

        var ampm=function(){ 

            if(hours>12){ 

                hours-=12; 

                return 'pm'; 

            } else { 

                return 'am'; 

            } 

        }(); 

        var specOffset=10, aT=INFO.arrowType; 

        specGrp.name=item.name+"_Specs_"+(hours)+":"+minutes+":"+seconds+ampm; 

        var wSpec=specGrp.groupItems.add(); wSpec.name="Width Spec"; 

        specLine([left,bottom-specOffset],[right,bottom-specOffset], wSpec, 'horizontal', markerColor, "W: "+width+' '+unitsName,specOffset,aT,proportionFactor); 

        var hSpec=specGrp.groupItems.add(); hSpec.name="Height Spec"; 

        specLine([right+specOffset,top],[right+specOffset,bottom], hSpec, 'vertical', markerColor, "H: "+height+' '+unitsName,specOffset,aT,proportionFactor); 

        outcome={ 

            width: width, 

            height: height, 

            unitsName: unitsName, 

        }.toSource() 

    } 

    function getDefaultFill(){ 

        outcome=null; 

        if(app.documents.length>0){ 

            var doc=app.activeDocument; 

            try{ 

                var df=doc.defaultFillColor, colorArray=[]; 

                var type=df.typename; 

                if(type=="GrayColor"){ 

                    colorArray=[df.gray]; 

                } else if(type=="RGBColor"){ 

                    colorArray=[df.red,df.green,df.blue]; 

                } else if(type=="CMYKColor"){ 

                    colorArray=[df.cyan,df.magenta,df.yellow,df.black]; 

                } else if(type=="GradientColor"){ 

                    alert("Sorry, no gradient colors allowed."); 

                    type=null, colorArray=null; 

                } else if(type=="SpotColor"){ 

                    colorArray=df.spot.name; 

                } else if(type=="PatternColor"){ 

                    alert("Sorry, no Pattern colors allowed."); 

                    type=null, colorArray=null; 

                } 

            } catch(e){ 

                alert("Sorry, couldn't set spec color to current FillColor due to: "+e); type=null, colorArray=null; 

            } 

            outcome={ 

                type: type, 

                colorArray: colorArray 

            }.toSource(); 

        } else { 

            alert("There isnt an open document!"); 

        } 

    } 

    function processDefaultFill(objString, args){ 

        var cE=args[0], info=args[1]; 

        var obj=eval(objString); 

        if(obj.type=="RGBColor"){ 

            var clr=[ 

                Math.round((obj.colorArray[0]/255)*100)/100, 

                Math.round((obj.colorArray[1]/255)*100)/100,  

                Math.round((obj.colorArray[2]/255)*100)/100 

            ]; 

            cE.pen=cE.penParent.newPen(cE.penParent.PenType.SOLID_COLOR,[clr[0],clr[1],clr[2],1],3); 

            cE.canvasG.hide(); cE.canvasG.show(); 

            info.colortype='"'+obj.type+'"'; 

            info.clr_1=obj.colorArray[0]; info.clr_2=obj.colorArray[1]; info.clr_3=obj.colorArray[2]; 

        } else if(obj.type=="CMYKColor"){ 

            var clr=CMYKtoRGB(obj.colorArray[0], obj.colorArray[1], obj.colorArray[2], obj.colorArray[3]); 

            cE.pen=cE.penParent.newPen(cE.penParent.PenType.SOLID_COLOR,[clr[0],clr[1],clr[2],1],3); 

            cE.canvasG.hide(); cE.canvasG.show(); 

            info.colortype='"'+obj.type+'"'; 

            info.clr_1=obj.colorArray[0]; info.clr_2=obj.colorArray[1]; info.clr_3=obj.colorArray[2]; info.clr_4=obj.colorArray[3]; 

        } else if(obj.type=="GrayColor"){ 

            var grayValue=1-(Math.round(((obj.colorArray[0]/100)*255)*100)/100)/255; 

            var clr=[grayValue, grayValue, grayValue]; 

            cE.pen=cE.penParent.newPen(cE.penParent.PenType.SOLID_COLOR,[clr[0],clr[1],clr[2],1],3); 

            cE.canvasG.hide(); cE.canvasG.show(); 

            info.colortype='"'+obj.type+'"'; 

            info.clr_1=obj.colorArray[0]; 

        } 

    } 

    function drawArrows(canvas, myPen){ 

        var ofstL=10, ofstR=80, top_1=15, top_2=43; 

        canvas.newPath(); canvas.moveTo(ofstL,top_1); canvas.lineTo(ofstR,top_1); canvas.closePath(); canvas.strokePath(myPen); 

        canvas.newPath(); canvas.moveTo(ofstL,top_1); canvas.lineTo(ofstL,top_1+3); canvas.lineTo(ofstL-3,top_1); canvas.lineTo(ofstL,top_1-3);  

        canvas.closePath(); canvas.strokePath(myPen); 

        canvas.newPath(); canvas.moveTo(ofstR,top_1); canvas.lineTo(ofstR,top_1+3); canvas.lineTo(ofstR+3,top_1); canvas.lineTo(ofstR,top_1-3);  

        canvas.closePath(); canvas.strokePath(myPen); 

         

        canvas.newPath(); canvas.moveTo(ofstL-2,top_2); canvas.lineTo(ofstR+2,top_2); canvas.closePath(); canvas.strokePath(myPen); 

        canvas.newPath(); canvas.moveTo(ofstL-2,top_2-5); canvas.lineTo(ofstL-2,top_2+5); canvas.closePath(); canvas.strokePath(myPen); 

        canvas.newPath(); canvas.moveTo(ofstR+2,top_2-5); canvas.lineTo(ofstR+2,top_2+5); canvas.closePath(); canvas.strokePath(myPen); 

    } 

    // Main messenger function 

    function paletteToAI(){ 

        outcome=null; 

        if(app.documents.length>0){ 

            var doc=app.activeDocument; 

            var sel=doc.selection; 

            if(sel.length>0){ 

                var top,left,bottom,right; 

                if(sel.length>1){ 

                    alert("selection items : "+sel.length); 

                } else { 

                    var item=sel[0]; 

                    left=item.visibleBounds[0]; 

                    top=item.visibleBounds[1]; 

                    right=item.visibleBounds[2]; 

                    bottom=item.visibleBounds[3]; 

                    var cv=1*INFO.unitsRatio; 

                    var decimals=Math.pow(10,INFO.decimals); 

                    var pointWidth=-1*(left-right); 

                    var pointHeight=top-bottom; 

                    var width=Math.round(-1*(left-right)*cv*decimals)/decimals; 

                    var height=Math.round((top-bottom)*cv*decimals)/decimals; 

                    var unitsName=INFO.unitsName; 

                    var proportionFactor=function(){ 

                        var num=(pointWidth<pointHeight) ? pointWidth:pointHeight; 

                        if(num>72){ 

                            return 1; 

                        } else { 

                            return (num>10) ? num/72:10/72; 

                        } 

                    }(); 

                    INFO.procedure; 

                } 

            } else { 

                alert("Please select an Art Object..."); 

                outcome=null; 

            } 

        } else { 

            alert("There isnt an open document!"); 

            outcome=null; 

        } 

    } 

//------------------------------------------------------------------------Staying Variables 

    var os=function(){ 

        if($.os.match('Windows')){ 

            return 'Windows'; 

        } else { 

            return 'Mac'; 

        } 

    }(); 

    var version=parseInt(app.version); 

    var UNITS={ 

        self: "UNITS", 

        _in: {ratio: 1/72, name: '"in"'}, 

        _mm: {ratio: 0.352777778, name: '"mm"'}, 

        _pt: {ratio: 1, name: '"pt"'} 

    }; 

    var INFO={ 

        self: "INFO", 

        unitsRatio: UNITS._in.ratio, 

        unitsName: UNITS._in.name, 

        procedure: asSourceString(doNothing), 

        decimals: 3, 

        colortype: '"CMYKColor"', 

        clr_1: 0, 

        clr_2: 100, 

        clr_3: 100, 

        clr_4: 0, 

        arrowType: 1, 

    }; 

    var uiStuff={}; 

    var colorElements={}; 

//------------------------------------------------------------------------Palette----------------------------------------------------------------// 

    var controlPalette=function(){ 

        var logo="({total: 33, shape_33:{pathPoints:[[175, 7], [100, 7], [100, 6], [98, 6], [93, 6], [91, 6], [91, 7], [84, 7], [84, 6], [82, 6], [77, 6], [75, 6], [75, 7], [34, 7], [31, 5], [29, 5], [24, 5], [22, 5], [20, 7], [17, 7], [5, 28], [5, 29], [20, 29], [22, 31], [24, 31], [29, 31], [31, 31], [34, 29], [36, 29], [36, 31], [38, 31], [38, 31], [40, 31], [40, 29], [49, 29], [49, 31], [51, 31], [59, 31], [61, 31], [61, 29], [62, 29], [64, 31], [66, 31], [70, 31], [72, 31], [74, 29], [79, 29], [79, 31], [81, 31], [86, 31], [87, 31], [88, 31], [89, 31], [94, 31], [97, 31], [97, 29], [101, 29], [101, 31], [103, 31], [104, 31], [106, 31], [106, 29], [108, 29], [108, 31], [111, 31], [111, 31], [113, 31], [113, 29], [114, 29], [114, 31], [116, 31], [117, 31], [119, 31], [119, 29], [124, 29], [124, 31], [126, 31], [127, 31], [129, 31], [129, 29], [133, 29], [133, 31], [135, 31], [143, 31], [145, 31], [145, 29], [146, 29], [146, 31], [148, 31], [149, 31], [151, 31], [151, 29], [154, 29], [154, 31], [156, 31], [156, 31], [158, 31], [158, 29], [163, 29]], fillColor:null, strokeColor:[0.69, 0.7, 0.59], strokeWidth: 3}, "+ 

        "shape_32:{pathPoints:[[17, 7], [5, 28], [5, 29], [163, 29], [175, 7]], fillColor:[0, 0.84, 0.87], strokeColor:null},"+ 

        "shape_31:{pathPoints:[[19, 28], [22, 31], [29, 31], [32, 28], [32, 19], [29, 16], [23, 16], [23, 9], [29, 9], [29, 11], [32, 11], [32, 8], [29, 5], [22, 5], [19, 8], [19, 17], [22, 20], [29, 20], [29, 27], [23, 27], [23, 25], [19, 25]], fillColor:[0.62, 0.18, 0], strokeColor:null}, "+ 

        "shape_30:{pathPoints:[[43, 10], [36, 10], [36, 31], [38, 31], [38, 22], [43, 22], [46, 20], [46, 13]], fillColor:[0.62, 0.18, 0], strokeColor:null}, "+ 

        "shape_29:{pathPoints:[[45, 19], [38, 19], [38, 13], [45, 13]], fillColor:[0.62, 0.18, 0], strokeColor:null}, "+ 

        "shape_28:{pathPoints:[[59, 13], [59, 10], [49, 10], [49, 31], [59, 31], [59, 28], [52, 28], [52, 22], [56, 22], [56, 19], [52, 19], [52, 13]], fillColor:[0.62, 0.18, 0], strokeColor:null}, "+ 

        "shape_27:{pathPoints:[[72, 16], [72, 13], [70, 10], [64, 10], [62, 13], [62, 28], [64, 31], [70, 31], [72, 28], [72, 25], [69, 25], [69, 28], [65, 28], [65, 13], [69, 13], [69, 16]], fillColor:[0.62, 0.18, 0], strokeColor:null}, "+ 

        "shape_26:{pathPoints:[[77, 10], [80, 27], [79, 27], [79, 31], [86, 31], [86, 27], [84, 27], [87, 22], [89, 27], [87, 27], [87, 31], [94, 31], [94, 27], [93, 27], [96, 10], [98, 10], [98, 6], [91, 6], [91, 10], [93, 10], [90, 21], [89, 13], [87, 13], [83, 21], [80, 10], [82, 10], [82, 6], [75, 6], [75, 10]], fillColor:[0.62, 0.18, 0], strokeColor:null}, "+ 

        "shape_25:{pathPoints:[[111, 13], [109, 10], [101, 10], [101, 31], [104, 31], [104, 22], [108, 22], [108, 31], [111, 31], [111, 21], [111, 21], [111, 20]], fillColor:[0.62, 0.18, 0], strokeColor:null}, "+ 

        "shape_24:{pathPoints:[[111, 19], [104, 19], [104, 13], [111, 13]], fillColor:[0.62, 0.18, 0], strokeColor:null}, "+ 

        "shape_23:{pathPoints:[[114, 10], [114, 31], [117, 31], [117, 10]], fillColor:[0.62, 0.18, 0], strokeColor:null}, "+ 

        "shape_22:{pathPoints:[[120, 10], [120, 13], [124, 13], [124, 31], [127, 31], [127, 13], [130, 13], [130, 10]], fillColor:[0.62, 0.18, 0], strokeColor:null}, "+ 

        "shape_21:{pathPoints:[[143, 13], [143, 10], [133, 10], [133, 31], [143, 31], [143, 28], [136, 28], [136, 22], [140, 22], [140, 19], [136, 19], [136, 13]], fillColor:[0.62, 0.18, 0], strokeColor:null}, "+ 

        "shape_20:{pathPoints:[[156, 13], [154, 10], [146, 10], [146, 31], [149, 31], [149, 22], [154, 22], [154, 31], [156, 31], [156, 21], [156, 21], [156, 20]], fillColor:[0.62, 0.18, 0], strokeColor:null}, "+ 

        "shape_19:{pathPoints:[[156, 19], [149, 19], [149, 13], [156, 13]], fillColor:[0.62, 0.18, 0], strokeColor:null}, "+ 

        "shape_18:{pathPoints:[[22, 28], [24, 31], [31, 31], [34, 28], [34, 19], [31, 16], [25, 16], [25, 9], [31, 9], [31, 11], [34, 11], [34, 8], [31, 5], [24, 5], [22, 8], [22, 17], [24, 20], [31, 20], [31, 27], [25, 27], [25, 25], [22, 25]], fillColor:[0.94, 0.35, 0.16], strokeColor:null}, "+ 

        "shape_17:{pathPoints:[[74, 16], [74, 13], [72, 10], [66, 10], [64, 13], [64, 28], [64, 29], [66, 31], [72, 31], [74, 29], [74, 28], [74, 25], [71, 25], [71, 28], [67, 28], [67, 13], [71, 13], [71, 16]], fillColor:[0.94, 0.35, 0.16], strokeColor:null}, "+ 

        "shape_16:{pathPoints:[[51, 10], [51, 31], [61, 31], [61, 28], [54, 28], [54, 22], [58, 22], [58, 19], [54, 19], [54, 13], [61, 13], [61, 10]], fillColor:[0.94, 0.35, 0.16], strokeColor:null}, "+ 

        "shape_15:{pathPoints:[[45, 10], [38, 10], [38, 31], [40, 31], [40, 22], [45, 22], [48, 20], [48, 13]], fillColor:[0.94, 0.35, 0.16], strokeColor:null}, "+ 

        "shape_14:{pathPoints:[[45, 19], [40, 19], [40, 13], [45, 13]], fillColor:[0.94, 0.35, 0.16], strokeColor:null}, "+ 

        "shape_13:{pathPoints:[[79, 10], [82, 27], [81, 27], [81, 31], [88, 31], [88, 27], [86, 27], [89, 22], [91, 27], [89, 27], [89, 31], [97, 31], [97, 27], [95, 27], [98, 10], [100, 10], [100, 6], [93, 6], [93, 10], [95, 10], [92, 21], [89, 13], [85, 21], [82, 10], [84, 10], [84, 6], [77, 6], [77, 10]], fillColor:[0.94, 0.35, 0.16], strokeColor:null}, "+ 

        "shape_12:{pathPoints:[[113, 13], [111, 10], [103, 10], [103, 31], [106, 31], [106, 22], [111, 22], [111, 31], [113, 31], [113, 21], [113, 21], [113, 20]], fillColor:[0.94, 0.35, 0.16], strokeColor:null}, "+ 

        "shape_11:{pathPoints:[[106, 19], [106, 13], [111, 13], [111, 19]], fillColor:[0.94, 0.35, 0.16], strokeColor:null}, "+ 

        "shape_10:{pathPoints:[[116, 10], [116, 31], [119, 31], [119, 10]], fillColor:[0.94, 0.35, 0.16], strokeColor:null}, "+ 

        "shape_9:{pathPoints:[[122, 10], [122, 13], [126, 13], [126, 31], [129, 31], [129, 13], [132, 13], [132, 10]], fillColor:[0.94, 0.35, 0.16], strokeColor:null}, "+ 

        "shape_8:{pathPoints:[[145, 13], [145, 10], [135, 10], [135, 31], [145, 31], [145, 28], [138, 28], [138, 22], [142, 22], [142, 19], [138, 19], [138, 13]], fillColor:[0.94, 0.35, 0.16], strokeColor:null}, "+ 

        "shape_7:{pathPoints:[[158, 13], [156, 10], [148, 10], [148, 31], [151, 31], [151, 22], [156, 22], [156, 31], [158, 31], [158, 21], [158, 21], [158, 20]], fillColor:[0.94, 0.35, 0.16], strokeColor:null}, "+ 

        "shape_6:{pathPoints:[[151, 19], [151, 13], [156, 13], [156, 19]], fillColor:[0.94, 0.35, 0.16], strokeColor:null}, "+ 

        "shape_5:{pathPoints:[[45, 13], [45, 19], [43, 19], [43, 13]], fillColor:[0.62, 0.18, 0], strokeColor:null}, "+ 

        "shape_4:{pathPoints:[[156, 13], [156, 19], [154, 19], [154, 13]], fillColor:[0.62, 0.18, 0], strokeColor:null}, "+ 

        "shape_3:{pathPoints:[[111, 13], [111, 19], [108, 19], [108, 13]], fillColor:[0.62, 0.18, 0], strokeColor:null}, "+ 

        "shape_2:{pathPoints:[[43, 19], [40, 19], [40, 13], [43, 13]], fillColor:[0, 0.84, 0.87], strokeColor:null}, "+ 

        "shape_1:{pathPoints:[[108, 19], [106, 19], [106, 13], [108, 13]], fillColor:[0, 0.84, 0.87], strokeColor:null}, "+ 

        "shape_0:{pathPoints:[[154, 19], [151, 19], [151, 13], [154, 13]], fillColor:[0, 0.84, 0.87], strokeColor:null}})"; 

        var w= new Window('palette','Spec Writer™',undefined,{closeButton:true}); w.margins=[5,3,5,8]; w.spacing=2; 

        var logoG=w.add('group'); 

            var logoP=logoG.add('panel',[0,0,184,40],'',{borderStyle: 'sunken'}); 

            logoP.onDraw=function(){ 

                drawFromObjString(logo, this); 

            } 

        var tabG=w.add('tabbedpanel'); 

            var controlsG=tabG.add('tab',undefined,'Controls'); 

                var unitsG=controlsG.add('group'); unitsG.orientation='row'; 

                    var unitsH=unitsG.add('statictext',undefined,'Units:'); 

                    var unitsDD=unitsG.add('dropdownlist',undefined,['in','mm','pt']); unitsDD.selection=unitsDD.items[0]; 

                var decimalsG=controlsG.add('group'); 

                    var decimalsH=decimalsG.add('statictext',undefined,'Decimals:'); 

                    var decimalsDD=decimalsG.add('dropdownlist',undefined,[0,1,2,3,4]); decimalsDD.selection=decimalsDD.items[3]; 

                var selObjG=controlsG.add('panel',undefined,'Target Object(s):'); selObjG.size=[150,140]; 

                    if(os=='Windows'){ 

                        selObjG.size=[150,120];  

                    } 

                    if(os=='Mac' && version<17){ 

                        selObjG.margins=[4,30,4,4]; 

                    } else { 

                        selObjG.margins=[4,20,4,4]; 

                    } 

                    var wG=selObjG.add('group'); 

                        var wH=wG.add('statictext',undefined,'Width'); 

                        var wE=wG.add('edittext',undefined,'',{readonly:true}); wE.characters=10; 

                    var hG=selObjG.add('group'); 

                        var hH=hG.add('statictext',undefined,'Height'); 

                        var hE=hG.add('edittext',undefined,'',{readonly:true}); hE.characters=10; 

                    var refreshBtn=selObjG.add('button',undefined,'Capture Object'); 

            var optsG=tabG.add('tab',undefined,'Options'); 

                var specArrowP=optsG.add('panel',undefined,"Arrows:"); specArrowP.orientation='row'; specArrowP.size=[164,90]; 

                    var arrowSelect=specArrowP.add('group',[0,10,20,60]); arrowSelect.orientation='column'; 

                        var type_1=arrowSelect.add('radiobutton',undefined); type_1.value=true; 

                        var type_2=arrowSelect.add('radiobutton',undefined); 

                        arrowSelect.addEventListener('mousedown',function(ev){ 

                            if(ev.target==type_1){ 

                                type_2.value=false; type_1.value=true; INFO.arrowType=1; 

                            } else if(ev.target==type_2){ 

                                type_1.value=false; type_2.value=true; INFO.arrowType=2; 

                            } 

                        }); 

                    var specArrowG=specArrowP.add('group'); specArrowG.size=[90,60]; 

                    if(os=='Windows'){ 

                        arrowSelect.margins=[2,3,2,2]; 

                        var windowsGroupShowingCrap=specArrowG.add('statictext',undefined,''); 

                    } 

                    var arrowPic=specArrowG.graphics; 

                    colorElements.pen=arrowPic.newPen(arrowPic.PenType.SOLID_COLOR,[1,0,0,1],3); 

 

 

                    specArrowG.onDraw=function(){ 

                        var myPen=colorElements.pen; 

                        drawArrows(arrowPic,myPen); 

                    } 

                var colorChoicesP=optsG.add('panel',undefined,'Colors'); 

                var colorChoicesG=colorChoicesP.add('group'); colorChoicesP.size=[164,100]; colorChoicesP.margins=[2,20,2,2]; 

                    if(os=='Windows'){colorChoicesP.size=[164,80];} 

                    var red=colorChoicesG.add('panel'); var redG=red.add('group'); red.margins=[0,0,0,0]; redG.size=[16,10]; 

                    red.graphics.backgroundColor=red.graphics.newBrush(red.graphics.BrushType.SOLID_COLOR,[1,0,0]); 

                    red.helpTip="CMYK Red: C: 0, M: 100, Y: 100, K: 0"; red.colortype='"CMYKColor"'; red.clr_1=0; red.clr_2=100; red.clr_3=100; red.clr_4=0; 

                    var cyan=colorChoicesG.add('panel'); var cyanG=cyan.add('group'); cyan.margins=[0,0,0,0]; cyanG.size=[16,10]; 

                    cyan.graphics.backgroundColor=cyan.graphics.newBrush(cyan.graphics.BrushType.SOLID_COLOR,[0,0.8,1]); 

                    cyan.helpTip="CMYK Cyan: C: 100, M: 0, Y: 0, K: 0"; cyan.colortype='"CMYKColor"'; cyan.clr_1=100; cyan.clr_2=0; cyan.clr_3=0; cyan.clr_4=0; 

                    var black=colorChoicesG.add('panel'); var blackG=black.add('group'); black.margins=[0,0,0,0]; blackG.size=[16,10]; 

                    black.graphics.backgroundColor=black.graphics.newBrush(black.graphics.BrushType.SOLID_COLOR,[0,0,0]); 

                    black.helpTip="CMYK Black: C: 0, M: 0, Y: 0, K: 100"; black.colortype='"CMYKColor"'; black.clr_1=0; black.clr_2=0; black.clr_3=0; black.clr_4=100; 

                    var yellow=colorChoicesG.add('panel'); var yellowG=yellow.add('group'); yellow.margins=[0,0,0,0]; yellowG.size=[16,10]; 

                    yellow.graphics.backgroundColor=yellow.graphics.newBrush(yellow.graphics.BrushType.SOLID_COLOR,[1,1,0]); 

                    yellow.helpTip="CMYK Yellow: C: 0, M: 0, Y: 100, K: 0"; yellow.colortype='"CMYKColor"'; yellow.clr_1=0; yellow.clr_2=0; yellow.clr_3=100; yellow.clr_4=0; 

                var defaultFill=colorChoicesP.add('button',undefined,"Current Fill Color"); 

                var colorChoices=[red,cyan,yellow,black]; 

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

                    var thisColor=colorChoices

                    thisColor.addEventListener('mousedown',function(){ 

                        var clr=this.graphics.backgroundColor.color; 

                        colorElements.pen=arrowPic.newPen(arrowPic.PenType.SOLID_COLOR,[clr[0],clr[1],clr[2],1],3); 

                        specArrowG.hide(); specArrowG.show(); 

                        INFO.colortype=this.colortype; 

                        INFO.clr_1=this.clr_1; INFO.clr_2=this.clr_2; INFO.clr_3=this.clr_3; INFO.clr_4=this.clr_4; 

                    }); 

                } 

        var specsBtn=w.add('button',undefined,"Put Specs"); 

//------------------------------------------ Event Handlers 

        uiStuff.wE=wE; 

        uiStuff.hE=hE; 

        colorElements.penParent=arrowPic; 

        colorElements.canvasG=specArrowG; 

        defaultFill.addEventListener('mousedown',function(){ 

            sendBTmsg(getDefaultFill, undefined, processDefaultFill, [colorElements, INFO]); 

        }); 

        unitsDD.addEventListener('change',function(){ 

            if(this.selection==null){ 

                this.selection=this.items[0]; 

            } 

        }); 

        decimalsDD.addEventListener('change',function(){ 

            if(this.selection==null){ 

                this.selection=this.items[0]; 

            } 

        }); 

        refreshBtn.addEventListener('mousedown',function(){ // REFRESH 

            INFO.unitsRatio=UNITS['_'+unitsDD.selection.text].ratio; 

            INFO.unitsName=UNITS['_'+unitsDD.selection.text].name; 

            INFO.procedure=asSourceString(returnRefresh); 

            INFO.decimals=decimalsDD.selection.text; 

            sendBTmsg(paletteToAI, INFO, processRefresh,[uiStuff]); 

        }); 

        specsBtn.addEventListener('mousedown',function(){ // Real Specs 

            INFO.unitsRatio=UNITS['_'+unitsDD.selection.text].ratio; 

            INFO.unitsName=UNITS['_'+unitsDD.selection.text].name; 

            INFO.decimals=decimalsDD.selection.text; 

            INFO.procedure=asSourceString(putSpecs); 

            sendBTmsg(paletteToAI, INFO, processRefresh,[uiStuff]); 

        }); 

        var windowObj={ 

            w: w, 

            show: function(){this.w.show();}, 

        } 

        return windowObj; 

    }(); 

    controlPalette.show(); 

#target illustrator 

#targetengine main 

main(); 

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
Explorer ,
Jan 05, 2016 Jan 05, 2016

Copy link to clipboard

Copied

Thanks, Mike. Is this script compatible with Windows 7 CS6; I got an "Error 25: Expected: ]. Line: 227"?

script-error.PNG

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 09, 2016 Jan 09, 2016

Copy link to clipboard

Copied

Sorry not sure as i did not write the script, but was working on windows last time I checked, but Ido dot have my windows system anymore to check for you as had too many computers.

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
Explorer ,
Jan 10, 2016 Jan 10, 2016

Copy link to clipboard

Copied

This is the script that i use to add dimensions. Could work for you.

Credit to adamdehaven.

/* ======================================

* https://github.com/adamdehaven/Specify

*

* Adam Dehaven ( @adamdehaven )

* http://adamdehaven.com/

*

* ======================================

*/

if (app.documents.length > 0) {

  // Create empty dialog window

  var specifyDialogBox = new Window('dialog', 'Specify');

  specifyDialogBox.frameLocation = [500,400];

  specifyDialogBox.size = [350,150];

  specifyDialogBox.intro = specifyDialogBox.add('statictext', [20,10,310,50] );

  specifyDialogBox.intro.text = 'Select which dimension to specify:';

  specifyDialogBox.where = specifyDialogBox.add('dropdownlist', [20,50,100,40] );

  specifyDialogBox.where.selection = specifyDialogBox.where.add('item', 'Top');

  specifyDialogBox.where.add('item', 'Right');

  specifyDialogBox.where.add('item', 'Bottom');

  specifyDialogBox.where.add('item', 'Left');

  specifyDialogBox.units = specifyDialogBox.add('checkbox', [140,54,300,90], 'Include units label');

  specifyDialogBox.units.value = true;

  specifyDialogBox.btn = specifyDialogBox.add('button', [140,100,280,140], 'Specify Object(s) ▸', 'spec');

  // document

  var doc = activeDocument;

  // count selected items

  var selectedItems = parseInt( doc.selection.length ) || 0;

  // spec layer

  try {

  var specsLayer = doc.layers['SPECS'];

  } catch(err) {

  var specsLayer = doc.layers.add();

  specsLayer.name = 'SPECS';

  }

  // measurement line and text color in RGB

  var color = new RGBColor;

  color.red = 255;

  color.green = 51;

  color.blue = 255;

  // gap between measurement lines and object

  var gap = 2;

  // size of perpendicular measurement lines.

  var size = 6;

  // number of decimal places in measurement

  var decimals = 3;

  // pixels per inch

  var dpi = 300;

  /**

  Start the spec

  */

  function startSpec() {

  if (selectedItems == 1) {

  specSingle( doc.selection[0].geometricBounds, specifyDialogBox.where.selection.text );

  } else if (selectedItems == 2) {

  specDouble( doc.selection[0], doc.selection[1], specifyDialogBox.where.selection.text );

  } else {

  alert('Please select at least 1 or 2 items.');

  }

  specifyDialogBox.close();

  }

  /**

  Spec the gap between 2 elements

  */

  function specDouble( item1, item2, where ) {

  var bound = new Array(0,0,0,0);

  var a =  item1.geometricBounds;

  var b =  item2.geometricBounds;

  if (where=='Top' || where=='Bottom') {

  if (b[0]>a[0]) { // item 2 on right,

  if (b[0]>a[2]) { // no overlap

  bound[0] =a[2];

  bound[2] = b[0];

  } else { // overlap

  bound[0] =b[0];

  bound[2] = a[2];

  }

  } else if (a[0]>=b[0]){ // item 1 on right

  if (a[0]>b[2]) { // no overlap

  bound[0] =b[2];

  bound[2] = a[0];

  } else { // overlap

  bound[0] =a[0];

  bound[2] = b[2];

  }

  }

  bound[1] = Math.max (a[1], b[1]);

  bound[3] = Math.min (a[3], b[3]);

  } else {

  if (b[3]>a[3]) { // item 2 on top

  if (b[3]>a[1]) { // no overlap

  bound[3] =a[1];

  bound[1] = b[3];

  } else { // overlap

  bound[3] =b[3];

  bound[1] = a[1];

  }

  } else if (a[3]>=b[3]){ // item 1 on top

  if (a[3]>b[1]) { // no overlap

  bound[3] =b[1];

  bound[1] = a[3];

  } else { // overlap

  bound[3] =a[3];

  bound[1] = b[1];

  }

  }

  bound[0] = Math.min(a[0], b[0]);

  bound[2] = Math.max (a[2], b[2]);

  }

  specSingle(bound, where );

  }

  /**

  spec a single object

  @param bound item.geometricBound

  @param where 'Top', 'Right', 'Bottom,' 'Left'

  */

  function specSingle( bound, where ) {

  specsLayer.locked = false;

  // width and height

  var w = bound[2]-bound[0];

  var h = bound[1]-bound[3];

  // a & b are the horizontal or vertical positions that change

  // c is the horizontal or vertical position that doesn't change

  var a = bound[0];

  var b = bound[2];

  var c = bound[1];

  // xy='x' (horizontal measurement), xy='y' (vertical measurement)

  var xy = 'x';

  // a direction flag for placing the measurement lines.

  var dir = 1;

  switch( where ) {

  case 'Top':

  a = bound[0];

  b = bound[2];

  c = bound[1];

  xy = 'x';

  dir = 1;

  break;

  case 'Right':

  a = bound[1];

  b = bound[3];

  c = bound[2];

  xy = 'y';

  dir = 1;

  break;

  case 'Bottom':

  a = bound[0];

  b = bound[2];

  c = bound[3];

  xy = 'x';

  dir = -1;

  break;

  case 'Left':

  a = bound[1];

  b = bound[3];

  c = bound[0];

  xy = 'y';

  dir = -1;

  break;

  }

  // create the measurement lines

  var lines = new Array();

  // horizontal measurement

  if (xy=='x') {

  // 2 vertical lines

  lines[0]= new Array( new Array(a, c+(gap)*dir) );

  lines[0].push ( new Array(a, c+(gap+size)*dir) );

  lines[1]= new Array( new Array(b, c+(gap)*dir) );

  lines[1].push( new Array(b, c+(gap+size)*dir) );

  // 1 horizontal line

  lines[2]= new Array( new Array(a, c+(gap+size/2)*dir ) );

  lines[2].push( new Array(b, c+(gap+size/2)*dir ) );

  // create text label

  if (where=='Top') {

  var t = specLabel( w, (a+b)/2, lines[0][1][1], color );

  t.top += t.height;

  } else {

  var t = specLabel( w, (a+b)/2, lines[0][0][1], color );

  t.top -= t.height;

  }

  t.left -= t.width/2;

  // vertical measurement

  } else {

  // 2 horizontal lines

  lines[0]= new Array( new Array( c+(gap)*dir, a) );

  lines[0].push ( new Array( c+(gap+size)*dir, a) );

  lines[1]= new Array( new Array( c+(gap)*dir, b) );

  lines[1].push( new Array( c+(gap+size)*dir, b) );

  //1 vertical line

  lines[2]= new Array( new Array(c+(gap+size/2)*dir, a) );

  lines[2].push( new Array(c+(gap+size/2)*dir, b) );

  // create text label

  if (where=='Left') {

  var t = specLabel( h, lines[0][1][0], (a+b)/2, color );

  t.left -= t.width;

  } else {

  var t = specLabel( h, lines[0][0][0], (a+b)/2, color );

  t.left += size;

  }

  t.top += t.height/2;

  }

  // draw the lines

  var specgroup = new Array(t);

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

  var p = doc.pathItems.add();

  p.setEntirePath ( lines );

  setLineStyle( p, color );

  specgroup.push( p );

  }

  group(specsLayer, specgroup );

  specsLayer.locked = true;

  }

  /**

  Create a text label that specify the dimension

  */

  function specLabel( val, x, y, color) {

  var t = doc.textFrames.add();

  t.textRange.characterAttributes.size = 8;

  t.textRange.characterAttributes.alignment = StyleRunAlignmentType.center;

  t.textRange.characterAttributes.fillColor = color;

  // Conversions : http://wwwimages.adobe.com/content/dam/Adobe/en/devnet/illustrator/sdk/CC2014/Illustrator%20Scriptin...

  // UnitValue object (page 230): http://wwwimages.adobe.com/content/dam/Adobe/en/devnet/scripting/pdfs/javascript_tools_guide.pdf

  var displayUnitsLabel = specifyDialogBox.units.value;

  var v = val;

  var unitsLabel = '';

  switch (doc.rulerUnits) {

  case RulerUnits.Picas:

  v = new UnitValue(v, "pt").as("pc");

  var vd = v - Math.floor (v);

  vd = 12*vd;

  v =  Math.floor(v)+'p'+vd.toFixed (decimals);

  break;

  case RulerUnits.Inches:

  v = new UnitValue(v, "pt").as("in");

  v = v.toFixed (decimals);

  unitsLabel = " in"; // add abbreviation

  break;

  case RulerUnits.Millimeters:

  v = new UnitValue(v, "pt").as("mm");

  v = v.toFixed (decimals);

  unitsLabel = " mm"; // add abbreviation

  break;

  case RulerUnits.Centimeters:

  v = new UnitValue(v, "pt").as("cm");

  v = v.toFixed (decimals);

  unitsLabel = " cm"; // add abbreviation

  break;

  case RulerUnits.Pixels:

  v = new UnitValue(v, "pt").as("px");

  v = v.toFixed (decimals);

  unitsLabel = " px"; // add abbreviation

  break;

  default:

  v = new UnitValue(v, "pt").as("pt");

  v = v.toFixed (decimals);

  unitsLabel = " pt"; // add abbreviation

  }

  if(displayUnitsLabel) {

  t.contents = v + unitsLabel;

  } else {

  t.contents = v;

  }

  t.top = y;

  t.left = x;

  return t;

  }

  function setLineStyle(path, color) {

  path.filled = false;

  path.stroked = true;

  path.strokeColor = color;

  path.strokeWidth = 0.5;

  return path;

  }

  /**

  * Group items in a layer

  */

  function group( layer, items, isDuplicate) {

  // create new group

  var gg = layer.groupItems.add();

  // add to group

  // reverse count, because items length is reduced as items are moved to new group

  for(var i=items.length-1; i>=0; i--) {

  if (items!=gg) { // don't group the group itself

  if (isDuplicate) {

  newItem = items.duplicate (gg, ElementPlacement.PLACEATBEGINNING);

  } else {

  items.move( gg, ElementPlacement.PLACEATBEGINNING );

  }

  }

  }

  return gg;

  }

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 ,
Nov 23, 2018 Nov 23, 2018

Copy link to clipboard

Copied

On ‎Friday‎, ‎November‎ ‎23‎, ‎2018‎ ‎04‎:‎07‎:‎15‎ ‎PM‎ ‎CET, Silly-V <forums_noreply@adobe.com> wrote:

|

Illustrator CS6 - Adding dimensional information to a drawing

Silly-V marked AimanFiqri's reply on Illustrator CS6 - Adding dimensional information to a drawing as helpful. View the full reply

Marked as helpful:

This is the script that i use to add dimensions. Could work for you.

Credit to adamdehaven.

 

 

 

/* ======================================

  • https://github.com/adamdehaven/Specify

*

  • Adam Dehaven ( @adamdehaven )

  • http://adamdehaven.com/

*

  • ======================================

*/

 

 

 

 

if (app.documents.length > 0) {

 

 

  // Create empty dialog window

  var specifyDialogBox = new Window('dialog', 'Specify');

  specifyDialogBox.frameLocation = ;

  specifyDialogBox.size = ;

 

 

  specifyDialogBox.intro = specifyDialogBox.add('statictext', );

  specifyDialogBox.intro.text = 'Select which dimension to specify:';

 

 

  specifyDialogBox.where = specifyDialogBox.add('dropdownlist', );

  specifyDialogBox.where.selection = specifyDialogBox.where.add('item', 'Top');

  specifyDialogBox.where.add('item', 'Right');

  specifyDialogBox.where.add('item', 'Bottom');

  specifyDialogBox.where.add('item', 'Left');

 

 

  specifyDialogBox.units = specifyDialogBox.add('checkbox', , 'Include units label');

  specifyDialogBox.units.value = true;

 

 

  specifyDialogBox.btn = specifyDialogBox.add('button', , 'Specify Object(s) ▸', 'spec');

 

 

  // document

  var doc = activeDocument;

 

 

  // count selected items

  var selectedItems = parseInt( doc.selection.length ) || 0;

 

 

  // spec layer

  try {

  var specsLayer = doc.layers['SPECS'];

  } catch(err) {

  var specsLayer = doc.layers.add();

  specsLayer.name = 'SPECS';

  }

 

 

 

 

 

 

  // measurement line and text color in RGB

  var color = new RGBColor;

  color.red = 255;

  color.green = 51;

  color.blue = 255;

 

 

  // gap between measurement lines and object

  var gap = 2;

 

 

  // size of perpendicular measurement lines.

  var size = 6;

 

 

  // number of decimal places in measurement

  var decimals = 3;

 

 

  // pixels per inch

  var dpi = 300;

 

 

  /**

  Start the spec

  */

  function startSpec() {

 

 

  if (selectedItems == 1) {

  specSingle( doc.selection[0].geometricBounds, specifyDialogBox.where.selection.text );

  } else if (selectedItems == 2) {

  specDouble( doc.selection[0], doc.selection[1], specifyDialogBox.where.selection.text );

  } else {

  alert('Please select at least 1 or 2 items.');

  }

 

 

  specifyDialogBox.close();

  }

 

 

 

 

 

 

 

 

  /**

  Spec the gap between 2 elements

  */

  function specDouble( item1, item2, where ) {

 

 

  var bound = new Array(0,0,0,0);

 

 

  var a =  item1.geometricBounds;

  var b =  item2.geometricBounds;

 

 

  if (where=='Top' || where=='Bottom') {

 

 

  if (b[0]>a[0]) { // item 2 on right,

 

 

  if (b[0]>a[2]) { // no overlap

  bound[0] =a[2];

  bound[2] = b[0];

  } else { // overlap

  bound[0] =b[0];

  bound[2] = a[2];

  }

  } else if (a[0]>=b[0]){ // item 1 on right

 

 

  if (a[0]>b[2]) { // no overlap

  bound[0] =b[2];

  bound[2] = a[0];

  } else { // overlap

  bound[0] =a[0];

  bound[2] = b[2];

  }

  }

 

 

  bound[1] = Math.max (a[1], b[1]);

  bound[3] = Math.min (a[3], b[3]);

 

 

  } else {

 

 

  if (b[3]>a[3]) { // item 2 on top

  if (b[3]>a[1]) { // no overlap

  bound[3] =a[1];

  bound[1] = b[3];

  } else { // overlap

  bound[3] =b[3];

  bound[1] = a[1];

  }

  } else if (a[3]>=b[3]){ // item 1 on top

 

 

  if (a[3]>b[1]) { // no overlap

  bound[3] =b[1];

  bound[1] = a[3];

  } else { // overlap

  bound[3] =a[3];

  bound[1] = b[1];

  }

  }

 

 

  bound[0] = Math.min(a[0], b[0]);

  bound[2] = Math.max (a[2], b[2]);

  }

  specSingle(bound, where );

  }

 

 

 

 

  /**

  spec a single object

  @param bound item.geometricBound

  @param where 'Top', 'Right', 'Bottom,' 'Left'

  */

  function specSingle( bound, where ) {

 

 

  specsLayer.locked = false;

 

 

  // width and height

  var w = bound[2]-bound[0];

  var h = bound[1]-bound[3];

 

 

  // a & b are the horizontal or vertical positions that change

  // c is the horizontal or vertical position that doesn't change

  var a = bound[0];

  var b = bound[2];

  var c = bound[1];

 

 

  // xy='x' (horizontal measurement), xy='y' (vertical measurement)

  var xy = 'x';

 

 

  // a direction flag for placing the measurement lines.

  var dir = 1;

 

 

  switch( where ) {

 

 

  case 'Top':

  a = bound[0];

  b = bound[2];

  c = bound[1];

  xy = 'x';

  dir = 1;

  break;

 

 

  case 'Right':

  a = bound[1];

  b = bound[3];

  c = bound[2];

  xy = 'y';

  dir = 1;

  break;

 

 

  case 'Bottom':

  a = bound[0];

  b = bound[2];

  c = bound[3];

  xy = 'x';

  dir = -1;

  break;

 

 

  case 'Left':

  a = bound[1];

  b = bound[3];

  c = bound[0];

  xy = 'y';

  dir = -1;

  break;

 

 

 

 

 

 

  }

 

 

  // create the measurement lines

  var lines = new Array();

 

 

  // horizontal measurement

  if (xy=='x') {

 

 

  // 2 vertical lines

  lines[0]= new Array( new Array(a, c+(gap)*dir) );

  lines[0].push ( new Array(a, c(gapsize)*dir) );

  lines[1]= new Array( new Array(b, c+(gap)*dir) );

  lines[1].push( new Array(b, c(gapsize)*dir) );

 

 

  // 1 horizontal line

  lines[2]= new Array( new Array(a, c(gapsize/2)*dir ) );

  lines[2].push( new Array(b, c(gapsize/2)*dir ) );

 

 

  // create text label

  if (where=='Top') {

  var t = specLabel( w, (a+b)/2, lines[0][1][1], color );

  t.top += t.height;

  } else {

  var t = specLabel( w, (a+b)/2, lines[0][0][1], color );

  t.top -= t.height;

  }

  t.left -= t.width/2;

 

 

  // vertical measurement

  } else {

 

 

  // 2 horizontal lines

  lines[0]= new Array( new Array( c+(gap)*dir, a) );

  lines[0].push ( new Array( c(gapsize)*dir, a) );

  lines[1]= new Array( new Array( c+(gap)*dir, b) );

  lines[1].push( new Array( c(gapsize)*dir, b) );

 

 

  //1 vertical line

  lines[2]= new Array( new Array(c(gapsize/2)*dir, a) );

  lines[2].push( new Array(c(gapsize/2)*dir, b) );

 

 

  // create text label

  if (where=='Left') {

  var t = specLabel( h, lines[0][1][0], (a+b)/2, color );

  t.left -= t.width;

  } else {

  var t = specLabel( h, lines[0][0][0], (a+b)/2, color );

  t.left += size;

  }

  t.top += t.height/2;

  }

 

 

  // draw the lines

  var specgroup = new Array(t);

 

 

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

  var p = doc.pathItems.add();

  p.setEntirePath ( lines );

  setLineStyle( p, color );

  specgroup.push( p );

  }

 

 

  group(specsLayer, specgroup );

 

 

  specsLayer.locked = true;

 

 

  }

 

 

 

 

  /**

  Create a text label that specify the dimension

  */

  function specLabel( val, x, y, color) {

 

 

  var t = doc.textFrames.add();

  t.textRange.characterAttributes.size = 8;

  t.textRange.characterAttributes.alignment = StyleRunAlignmentType.center;

  t.textRange.characterAttributes.fillColor = color;

 

 

  // Conversions : http://wwwimages.adobe.com/content/dam/Adobe/en/devnet/illustrator/sdk/CC2014/Illustrator% 20Scripting%20Guide.pdf

  // UnitValue object (page 230): http://wwwimages.adobe.com/content/dam/Adobe/en/devnet/scripting/pdfs/javascript_tools_gui de.pdf

 

 

  var displayUnitsLabel = specifyDialogBox.units.value;

  var v = val;

  var unitsLabel = '';

 

 

  switch (doc.rulerUnits) {

 

  case RulerUnits.Picas:

  v = new UnitValue(v, "pt").as("pc");

  var vd = v - Math.floor (v);

  vd = 12*vd;

  v =  Math.floor(v)'p'vd.toFixed (decimals);

  break;

 

 

  case RulerUnits.Inches:

  v = new UnitValue(v, "pt").as("in");

  v = v.toFixed (decimals);

  unitsLabel = " in"; // add abbreviation

  break;

 

 

  case RulerUnits.Millimeters:

  v = new UnitValue(v, "pt").as("mm");

  v = v.toFixed (decimals);

  unitsLabel = " mm"; // add abbreviation

  break;

 

 

  case RulerUnits.Centimeters:

  v = new UnitValue(v, "pt").as("cm");

  v = v.toFixed (decimals);

  unitsLabel = " cm"; // add abbreviation

  break;

 

 

  case RulerUnits.Pixels:

  v = new UnitValue(v, "pt").as("px");

  v = v.toFixed (decimals);

  unitsLabel = " px"; // add abbreviation

  break;

 

 

  default:

  v = new UnitValue(v, "pt").as("pt");

  v = v.toFixed (decimals);

  unitsLabel = " pt"; // add abbreviation

  }

 

 

  if(displayUnitsLabel) {

  t.contents = v + unitsLabel;

  } else {

  t.contents = v;

  }

  t.top = y;

  t.left = x;

 

 

  return t;

 

 

  }

 

 

  function setLineStyle(path, color) {

  path.filled = false;

  path.stroked = true;

  path.strokeColor = color;

  path.strokeWidth = 0.5;

 

 

  return path;

  }

 

 

 

 

  /**

 

  • Group items in a layer

  */

  function group( layer, items, isDuplicate) {

 

 

  // create new group

  var gg = layer.groupItems.add();

 

 

  // add to group

  // reverse count, because items length is reduced as items are moved to new group

  for(var i=items.length-1; i>=0; i--) {

 

 

  if (items!=gg) { // don't group the group itself

  if (isDuplicate) {

  newItem = items.duplicate (gg, ElementPlacement.PLACEATBEGINNING);

  } else {

  items.move( gg, ElementPlacement.PLACEATBEGINNING );

  }

  }

  }

 

 

  return gg;

  }

Following Illustrator CS6 - Adding dimensional information to a drawing in these streams: Inbox

This email was sent by Adobe Community because you are a registered user.

You may unsubscribe instantly from Adobe Community, or adjust email frequency in your email preferences

|

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 ,
Nov 23, 2018 Nov 23, 2018

Copy link to clipboard

Copied

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
Advocate ,
Nov 24, 2018 Nov 24, 2018

Copy link to clipboard

Copied

LATEST

Hello

I made a script already on CS2 that gives me satisfaction, just select the points, the unit is the one of the rules.

I can change it for other units or even consider the scale.

If interested consult me by mail see profile.cotation.PNG

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