Quantcast
Channel: Adobe Community : Popular Discussions - Illustrator Scripting
Viewing all 12845 articles
Browse latest View live

How do I get the position of the selected PathItem in pixels ?

$
0
0

Hi,

 

I have a simple problem, but can't seem to find my way around it:

 

I have PathItem and Illustrator points out that it is at position (781px,250px).

How can I get those values in jsx ?

 

I've noticed that the PathItem inherits the position property from PageItem, and position

is a point, but when I try prining the values, I get undefined:

 

$.writeln(app.activeDocument.selection[0].position.x);

 

If I leave out .x from the line above I get this printed in the console:

 

521,510

 

What are these values ? Are they x,y coordinates ? In what unit ? How can I convert to pixels ?

Why can I not access x,y/top,left properties (always get undefined) ?

 

I'm using Illustrator CS5.


How to divide all textFrames in one-character-per-textFrame?

$
0
0

Hello:

 

How to divide all textFrames in one-character-per-textFrame?

 

Example: the textFrame "Letters" will be divided in 7 textFrames: "L", "e", "t", "t", "e", "r", "s".

 

Help, please.

Exporting Adobe Illustrator XMP Data

$
0
0

Hello,

 

My biggest problem is that doesn't know how to write script. Can anyone kind enough to enlighten me with a ExtendScript to export Adobe illustrator XMP data into a xml file please?


Regards,

Jeno

changing or scaling gradient length in javascript

$
0
0

Hi,

I am trying to scale or change the length of a gradient fill. I managed to rotate it using the trick with .rotate without changing the shape, but I can't get the equivalent working with changing the length of the gradient - it just doesn't do anything!

I am on Illustrator 18 using JavaScript.

pathItem.fillColor.length doesn't work, and neither does .resize!

Retreiving Embedded Images Information

$
0
0

I have a two-part question.  One, I need to know why Illustrator displays embedded images at 72 dpi.  Two, how can I retreive an image's correct size and/or resolution?  Illustrator has the information contained somewhere, I see it being displayed in this window:

 

screenshot.jpg

 

Is there a reason it returns the incorrect "Dimensions" when I ask for the width of a rasterItem?

 

I'm using ExtendscriptToolkit 2 to write jsx to control Illustrator CS4.

 

Thank you!!!

UI (Window, dialog, palette etc) reference info for AI scripting

$
0
0

I'm looking for standard reference info on UI elements like popup windows (dialogs, palettes etc). I've been through the Illustrator CS6 Javascript Scripting reference guide and also the CS6 Scripting guide, checking every mention of the words "Window", "Dialog", "Palette" etc (there aren't many), plus related terms like "edittext" and "slider" (which seemingly don't exist in these documents at all), and can't find what I'm looking for.

 

----------

 

I'm trying to script a simple info box that contains information generated by a script that doesn't need to be closed before the user continues working.

 

All I'm trying to find out is the basics. From looking at other scripts I've figured out that you can create a popup box like this:

 

var box = new Window('dialog', 'Some title');

var panel = box.add(panel, undefined, 'Panel title');
panel.add('edittext', undefined, 'Default value');
panel.add('slider', undefined, /*Default numeric value*/,/*min*/,/*max*/);

var group = box.add(group, undefined, 'Group title');
group = area_len_box.add('group', undefined, 'Title (not displayed)');
group.orientation='row';
group.closeBtn = group.add('button',undefined, 'Close', {name:'close'});
group.closeBtn.onClick = function(){
  box.hide();  return false;
}

...which is enough for a very rudimentary input system, but one which has to be closed before the user can return to their work - and I can't find any resource that gives the full options:

 

  • What are the other options for 'new Window'? I'm aware of 'palette' which appears to need an array of four co-ordinates like [20,20,100,100], but it clearly needs something else too as every palette I've made instantly closes. And what else is there beyond Window and Palette?
  • What other input devices are there beyond edittext and slider, and what parameters do they each need?
  • What can go in the "undefined"s I see everywhere these are used?
  • etc etc

 

There must be a reference to this somewhere, but I can't find it.

Radial Gradient Aspect Ratio

$
0
0

Just a few hours ago i asked about identifying a gradients type (linaer vs radial) and thatnks to Carlos I'm set with that, but I can't find a way to access the Aspect Ratio of a gradient in javascript. Is this even possible?

 

I had zero luck looking for it in the refrence guide.

Now draw your own ScriptUIGraphics graphics! (1st testing)

$
0
0

Hey everyone, I've made this little system of drawing ScriptUIGraphics from your illustrator document.  Please be advised, the graphics resulting from this are not anti-aliased and look bad at medium sizes --> terrible at small sizes, but they may help with making some dynamic icons for some really specific scriptUI purposes.

 

 

Basically, you just draw something in an AI doc, run this window and use the function from it as well as the object resource string to recreate that drawing in your own scriptUI windows.

This method only uses straight lines and ellipses when it detects ellipses.  After seeing the quality of these drawings, I'm thinking for the prettier icons you'd surely want to embed images into your UI, but there may come a very very rare time when there exists a need for some dynamic image with many states, so this may be what it may end up perhaps being useful for.

 

Attached are screenshots with original drawing (artboard is 100x100px), the captured image drawn in window and last, pretty much the same- is the result drawn from object resource string.  The screenshots JPEGs have smoothed out the little icons, making them look actually better than they really are!

 

Edit: 

     Oh yes, I did need to mention: the colors used can be any color, spot/Lab included!  They just get changed to some version of RGB for rendering.

// ScriptUI Graphics Display by Vasily


function graphicsDisplay(){
    function itemShape(myShape){        // Going to test for circles.        var shapeKind={            isrectangle: null,            iscircle: null,            isellipse: null        };        if(myShape.typename=='PathItem' && myShape.pathPoints.length == 4){ // RECTANGLE CHECKER            //--------------------2 diagonals-------------------------            var recEquaDistOne = parseInt(Math.pow((myShape.pathPoints[0].anchor[0] - myShape.pathPoints[2].anchor[0]),2) +            Math.pow((myShape.pathPoints[0].anchor[1] - myShape.pathPoints[2].anchor[1]),2)); // diagonal            var recEquaDistTwo = parseInt(Math.pow((myShape.pathPoints[1].anchor[0] - myShape.pathPoints[3].anchor[0]),2) +            Math.pow((myShape.pathPoints[1].anchor[1] - myShape.pathPoints[3].anchor[1]),2)); // diagonal            //---------------------4 sides of rectangle---------------            var sideA = parseInt(Math.pow((myShape.pathPoints[0].anchor[0] - myShape.pathPoints[1].anchor[0]),2) +            Math.pow((myShape.pathPoints[0].anchor[1] - myShape.pathPoints[1].anchor[1]),2));             var sideB = parseInt(Math.pow((myShape.pathPoints[1].anchor[0] - myShape.pathPoints[2].anchor[0]),2) +            Math.pow((myShape.pathPoints[1].anchor[1] - myShape.pathPoints[2].anchor[1]),2));             var sideC = parseInt(Math.pow((myShape.pathPoints[2].anchor[0] - myShape.pathPoints[3].anchor[0]),2) +            Math.pow((myShape.pathPoints[2].anchor[1] - myShape.pathPoints[3].anchor[1]),2));             var sideD = parseInt(Math.pow((myShape.pathPoints[3].anchor[0] - myShape.pathPoints[0].anchor[0]),2) +            Math.pow((myShape.pathPoints[3].anchor[1] - myShape.pathPoints[0].anchor[1]),2));             if(recEquaDistOne == recEquaDistTwo){ // If two diagonals connecting opposite points are same length, it's a 90 degree box                               if((sideA == sideC) && (sideB == sideD)){                    for(var j=0; j<4; j++){                        var point = myShape.pathPoints[j];                                         if((point.leftDirection[0] == point.anchor[0]) &&                                (point.anchor[0] == point.rightDirection[0]) &&                                (point.leftDirection[1] == point.anchor[1]) &&                                (point.anchor[1] == point.rightDirection[1])){                                                                                   shapeKind.isrectangle = true;                            } else {                                shapeKind.isrectangle = false;                                break;                            }                        }                    }                }            }            if(myShape.pathPoints.length == 4){  // CIRCLE CHECKER                if(shapeKind.isrectangle == false || shapeKind.isrectangle == null){                    var circlePts = new Array();                    var circleSlopes = new Array();                    for (k=0; k<4; k++){                    var point = myShape.pathPoints[k];                     var leftHandleDist = parseInt(Math.pow((point.leftDirection[0] - point.anchor[0]),2) +                    Math.pow((point.leftDirection[1] - point.anchor[1]),2));                    var rightHandleDist = parseInt(Math.pow((point.rightDirection[0] - point.anchor[0]),2) +                    Math.pow((point.rightDirection[1] - point.anchor[1]),2));                    circlePts.push(leftHandleDist, rightHandleDist);                    var leftHandleSlope = ((point.leftDirection[0] - point.anchor[0])/(point.leftDirection[1] - point.anchor[1])).toFixed(2);                    var rightHandleSlope = ((point.rightDirection[0] - point.anchor[0])/(point.rightDirection[1] - point.anchor[1])).toFixed(2);                    circleSlopes.push(leftHandleSlope, rightHandleSlope);                }                for(var f=0; f<8; f++){ // Allows non-rotated circles.                    if(circleSlopes[f] == "-0.00"){                        circleSlopes[f] = "0.00";                    }                    if(circleSlopes[f] == "-Infinity"){                        circleSlopes[f] = "Infinity";                    }                }                var cirEquaDistOne = parseInt(Math.pow((myShape.pathPoints[0].anchor[0] - myShape.pathPoints[2].anchor[0]),2) +                Math.pow((myShape.pathPoints[0].anchor[1] - myShape.pathPoints[2].anchor[1]),2));                var cirEquaDistTwo = parseInt(Math.pow((myShape.pathPoints[1].anchor[0] - myShape.pathPoints[3].anchor[0]),2) +                Math.pow((myShape.pathPoints[1].anchor[1] - myShape.pathPoints[3].anchor[1]),2));                if(circleSlopes[0] != "NaN"){ // Filters out asymmetric rhombus  <><><>^^^^^^<><><>                    if((circlePts[0] == circlePts[1]) && // Filters out shapes with control handles not of equal distance from anchor point.                        (circlePts[1] == circlePts[2]) &&                        (circlePts[2] == circlePts[3]) &&                        (circlePts[3] == circlePts[4]) &&                        (circlePts[4] == circlePts[5]) &&                        (circlePts[5] == circlePts[6]) &&                        (circlePts[6] == circlePts[7]) &&                        (circlePts[7] == circlePts[0])){                        if((circleSlopes[0] == circleSlopes[1]) && // Filters out the equadistant 4-pointed Star shape (dismisses negative slopes).                            (circleSlopes[2] == circleSlopes[3]) &&                            (circleSlopes[4] == circleSlopes[5]) &&                            (circleSlopes[6] == circleSlopes[7])){                            if(cirEquaDistOne == cirEquaDistTwo){ // Filters out Ellipses (non-equadistant circles).                                // Filters out the very RARE 4-pointed star which has all control points in its center on top of each other!                                if(((myShape.pathPoints[0].leftDirection[0]).toFixed(2) != (myShape.pathPoints[1].leftDirection[0]).toFixed(2)) &&                                    ((myShape.pathPoints[0].leftDirection[1]).toFixed(2) != (myShape.pathPoints[1].leftDirection[1]).toFixed(2))){                                    shapeKind.iscircle = true;                                } else {                                    shapeKind.iscircle = false;                                }                            }                        }                    } else {                        if((circlePts[0]==circlePts[1]) &&                            (circlePts[2]==circlePts[3]) &&                            ((circlePts[4]==circlePts[5]) && (circlePts[4]==circlePts[1]) && (circlePts[5]==circlePts[1])) &&                            ((circlePts[6]==circlePts[7]) && (circlePts[6]==circlePts[2]) && (circlePts[7]==circlePts[3]))){                            shapeKind.isellipse=true;                        }    //~                     $.writeln(circlePts[0]+'\r'+circlePts[1]+'\r'+circlePts[2]+'\r'+circlePts[3]+'\r'+    //~                     circlePts[4]+'\r'+circlePts[5]+'\r'+circlePts[6]+'\r'+circlePts[7]);                    }                }            }        }        return shapeKind;    }    if(app.name=='Adobe Illustrator' && app.documents.length>0){        function round2(num){            return Math.round(num*100)/100;        }        function convertToUIRGB(color){            if(color=='[CMYKColor]'){                var c=color.cyan, m=color.magenta, y=color.yellow, k=color.black;                return [                    round2((1-(c/100))*(1-(k/100))),                    round2((1-(m/100))*(1-(k/100))),                    round2((1-(y/100))*(1-(k/100)))                ];            } else if(color=='[GrayColor]'){                var k=color.gray;                var grayValue=1-(Math.round(((k/100)*255)*100)/100)/255;                return [grayValue,grayValue,grayValue];            } else if(color=='[GradientColor]'){                $.writeln('Sorry, no gradient colors please.');                return [0,0,0];            } else if(color=='[PatternColor]'){                $.writeln('Sorry, no pattern colors please.');                return [0,0,0,];            } else if(color=='[SpotColor]'){                var clr=color.spot.getInternalColor();                if(color.spot.spotKind==SpotColorKind.SPOTCMYK){                    var c=clr[0], m=clr[1], y=clr[2], k=clr[3];                    return [                        round2((1-(c/100))*(1-(k/100))),                        round2((1-(m/100))*(1-(k/100))),                        round2((1-(y/100))*(1-(k/100)))                    ];                } else if(color.spot.spotKind==SpotColorKind.SPOTRGB){                    return [round2(clr[0]/255), round2(clr[1]/255), round2(clr[2]/255)];                } else if(color.spot.spotKind==SpotColorKind.SPOTLAB){                    var clr=color.spot.getInternalColor();                    var whiteRef={                        D65: {X: 95.047,Y: 100, Z: 108.883},                        D50: {X: 96.422,Y: 100, Z: 82.521},                    };                    var illuminant='D65';                    var Y = (clr[0]+16)/116;                    var X = clr[1]/500+Y;                    var Z = Y-clr[2]/200;                    if(Math.pow(Y,3) > 0.008856){Y=Math.pow(Y,3);}                    else {Y = (Y-16/116)/7.787;}                    if(Math.pow(X,3) > 0.008856){X=Math.pow(X,3);}                    else {X = (X-16/116)/7.787;}                    if(Math.pow(Z,3) > 0.008856){Z=Math.pow(Z,3);}                    else {Z = (Z-16/116)/7.787;}                    X*=whiteRef[illuminant].X,Y*=whiteRef[illuminant].Y,Z*=whiteRef[illuminant].Z;                    //alert(X+" "+Y+" "+Z);                    X/=100,Y/=100,Z/=100;                    R=X*3.2406+Y*-1.5372+Z*-0.4986;                    G=X*-0.9689+Y*1.8758+Z*0.0415;                    B=X*0.0557+Y*-0.2040+Z*1.0570;                    //alert(R+" "+G+" "+B);                    if(R > 0.0031308){R=(1.055*(Math.pow(R,(1/2.4))))-0.055;}                    else {R*= 12.92;}                    if(G > 0.0031308){G=(1.055*(Math.pow(G,(1/2.4))))-0.055;}                    else {G*= 12.92;}                    if(B > 0.0031308){B=(1.055*(Math.pow(B,(1/2.4))))-0.055;}                    else {B*= 12.92;}                    if(R<0){R=0} else if(R>1){R=1};                    if(G<0){G=0} else if(G>1){G=1};                    if(B<0){B=0} else if(B>1){B=1};                    return [round2(R),round2(G),round2(B)];                }            } else if(color=='[RGBColor]'){                return [round2(color.red/255), round2(color.green/255), round2(color.blue/255)];            }        }        function drawFromObjString(objString, canvasArea){           function round2(num){               return Math.round(num*100)/100;           }            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];                        if(thisShp.ellipsePath!=true){                            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[j];                                var x=thisAnchor[0], y=thisAnchor[1];                                canvas.lineTo(x,y);                            }                            if(thisShp.closed==true){                                canvas.closePath();                            }                        } else {                            var cirPts=thisShp.pathPoints;                            canvas.newPath();                            canvas.ellipsePath(cirPts[0], cirPts[1], cirPts[2], cirPts[3]);                            canvas.closePath();                        }                        if(thisShp.fillColor!=null){                            var clr=thisShp.fillColor;                            var myBrush=canvas.newBrush(canvas.BrushType.SOLID_COLOR,clr);                            canvas.fillPath(myBrush);                        }                        if(thisShp.strokeColor!=null){                            var clr=thisShp.strokeColor;                            var myPen=canvas.newPen(canvas.PenType.SOLID_COLOR,[clr[0],clr[1],clr[2],1], thisShp.strokeWidth);                            canvas.strokePath(myPen);                        }                    }                }                counter-=1;            }        }        var doc=app.activeDocument;        if(doc.height<=400 && doc.width<=600){            doc.rulerOrigin=[0,doc.height];            doc.coordinateSystem=CoordinateSystem.DOCUMENTCOORDINATESYSTEM;            var wDims=function(){                var dims={width: '', height: ''};                if(doc.width>220){                    dims.width = Math.round(doc.width);                } else {                    dims.width = 220;                }                if(doc.height>20){                    dims.height = Math.round(doc.height);                } else {                    dims.height = 20;                }                return dims;            }();            function drawCapture(vectors, dataDisplay, graphicDisplay){                // draws a preview and creates a drawing data object resource.                var drawData={total:0}; //Put drawing shapes here.  Properties: stroke (rgb color | null), fill (rgb color | null), pathPoints                var canvas=graphicDisplay.graphics;                for(var i=vectors.length-1; i>-1; i--){                    var thisShp=vectors[i];                    if((thisShp.filled || thisShp.stroked) && thisShp.editable==true){                        drawData.total++;                        drawData['shape_'+i]={};                        drawData['shape_'+i].fillColor=null;                        drawData['shape_'+i].strokeColor=null;                        drawData['shape_'+i].pathPoints=[];                        drawData['shape_'+i].ellipsePath=false;                        if(itemShape(thisShp).iscircle==true || itemShape(thisShp).isellipse==true || thisShp.name=='ellipse' ||                            thisShp.name=='circle' || thisShp.name=='cir'){                            drawData['shape_'+i].ellipsePath=true;                            drawData['shape_'+i].pathPoints=[thisShp.left, -thisShp.top, thisShp.width, thisShp.height];                            canvas.newPath();                            canvas.ellipsePath(thisShp.left, -thisShp.top, thisShp.width, thisShp.height);                        } else {                            var vectorPts=thisShp.pathPoints;                            canvas.newPath(); canvas.moveTo(Math.round(vectorPts[0].anchor[0]),-Math.round(vectorPts[0].anchor[1]));                            for(var j=0; j<vectorPts.length; j++){                                var thisAnchor=vectorPts[j].anchor;                                var x=Math.round(thisAnchor[0]), y=-Math.round(thisAnchor[1]);                                drawData['shape_'+i].pathPoints.push([x,y]);                                canvas.lineTo(x,y);                            }                        }                        if(thisShp.closed || drawData['shape_'+i].ellipsePath==true){                            drawData['shape_'+i].closed=true;                            if(drawData['shape_'+i].ellipsePath!=true){                                canvas.closePath();                            }                        } else {                            drawData['shape_'+i].closed=false;                        }                        if(thisShp.filled){                            var clr=thisShp.fillColor;                            var colorArray=convertToUIRGB(clr);                            var myBrush=canvas.newBrush(canvas.BrushType.SOLID_COLOR,colorArray);                            drawData['shape_'+i].fillColor=colorArray;                            canvas.fillPath(myBrush);                        }                        if(thisShp.stroked){                            var clr=thisShp.strokeColor;                            var colorArray=convertToUIRGB(clr);                            var myPen=canvas.newPen(canvas.PenType.SOLID_COLOR,[colorArray[0],colorArray[1],colorArray[2],1], Math.round(thisShp.strokeWidth));                            drawData['shape_'+i].strokeColor=colorArray;                            drawData['shape_'+i].strokeWidth=Math.round(thisShp.strokeWidth);                            canvas.strokePath(myPen);                        }                    }                }                return drawData;            }            function showDrawerFunc(objStringDisplay, wDims){                var w2=new Window('dialog','Drawer Function');                var containerG=w2.add('tabbedpanel');                    var funcG=containerG.add('tab',undefined,'Drawer Function');                        var dispE=funcG.add('edittext',undefined,funcSrc,{multiline:true}); dispE.size=[580,200];                        var selBtn=funcG.add('button',undefined,'Select All');                    var drawingG=containerG.add('tab',undefined,'Drawing:');                        var drawG=drawingG.add('group');                            var drawP=drawG.add('panel',undefined,''); drawP.size=[wDims.width, wDims.height];                var msgCntr=w2.add('panel',undefined,'Message Center:');                    var msgE=msgCntr.add('edittext',undefined,'',{multiline:true});msgE.size=[560,40];                var btnG=w2.add('group');                    var okBtn=btnG.add('button',undefined,'Ok',{name: 'ok'});                selBtn.onClick=function(){                    dispE.active=false; dispE.active=true;                }                drawG.onDraw=function(){                    if(objStringDisplay.text!=''){                        try{                            drawFromObjString(objStringDisplay.text, this);                        } catch(e){                            msgE.text=("Something isn't right:\r"+e);                        }                    } else {                        msgE.text=('You must first put a valid object string into the object string display area--> "Get Source Object String" button, 1st window, 1st tab.');                    }                }                w2.show();            }            function instructions(){                var w3=new Window('dialog','instructions');                var instructions=w3.add('edittext',undefined,'',{multiline:true}); instructions.size=[400,100];                instructions.text="1)  Have a document open, smaller than 600x400.\r\r"+                    "2)  Draw some stuff- use paths only, straight lines or ellipses only. To have script explicitly recognize ellipse, "+                    "label the path 'cir', 'circle', or 'ellipse'. Right now there's a function to detect ellipses, but it is coarse.\r\r"+                    "3)  Run this script and see if your drawing was captured below this box.\r\r"+                    "4)  Click the 'Get Object String' button and see the drawing instruction string appear.\r\r"+                    "5)  Click the 'View Drawer Function/Drawing' button to see the function used to draw scriptUI picture from"+                    " the object string and use other tab to see the drawing made with this function from that object string.\r\r"+                    "6)  Edit your string to see your picture change if needed!";                var okBtn=w3.add('button',undefined,'OK');                w3.show();            }            var funcSrc=drawFromObjString.toSource();            var dispWindow=function(){                var drawData;                var w=new Window('dialog','ScriptUI Graphics Display');                var panel=w.add('panel',undefined,''); panel.size=[wDims.width+6,wDims.height+6];                var list=w.add('edittext',undefined,'',{multiline:true}); list.size=[wDims.width,150];                var btnsG=w.add('group');                    var clickBtn=btnsG.add('button',undefined,'Get Source Object String');                    var selectBtn=btnsG.add('button',undefined,'Select All');                var btnG2=w.add('group');                    var funcBtn=btnG2.add('button',undefined,'See Drawer Function/Drawing');                    funcBtn.helpTip='Uses the Object String picture info to draw using ScriptUIGraphics lineTo commands.';                    var helpBtn=btnG2.add('button',undefined,'?'); helpBtn.size=[25,25];                panel.onDraw=function(){                    drawData=drawCapture(doc.pathItems, list, this);                }                clickBtn.addEventListener('mousedown',function(){                    list.text=drawData.toSource();                });                funcBtn.onClick=function(){                    showDrawerFunc(list, wDims);                };                helpBtn.onClick=function(){                    instructions();                }                selectBtn.onClick=function(){                    list.active=false; list.active=true;                }                var okBtn=w.add('button',undefined,'OK');                w.show();            }();        } else {            alert('Please use a document with main artboard no larger than 600x400.');        }    } else {        alert('Must run in Illustrator with at least 1 document open.');    }
}


graphicsDisplay();

Biohaz Drawing.JPGBiohaz Drawing-scriptUI.JPGBiohaz Drawing-scriptUI-result.JPG


break long process in CC 2014 (Mac OS)

$
0
0
var win = new Window("palette", "SnpCreateProgressBar", undefined);
win.pnl = win.add("panel", undefined, "Script Progress");
win.pnl.progBarLabel = win.pnl.add("statictext", undefined, "0%");

var btn = win.pnl.add ("button", undefined, "Cancel");
btn.onClick = function() { win.close(0); }

win.show();

var i = 0;
while(i < 200) {   win.pnl.progBarLabel.text = i + "%";   $.sleep(30);   win.update();   i++;
//   activeDocument.textFrames[0].contents = i + "";   redraw();
}

alert('Done!');

win.close();

 

button not work

MacOS

Giveway tothe user to break the script


ScriptUI: How to update Listbox values? (CC2014)

$
0
0

Is there way to update listbox element that filled with JS array elements. If I push more elements to the array, how I can re-render it in ScriptUI? Is there way to do this.

 

I know there is way just to add elements to listbox like in Peter Kahrel's PDF. But this isn't so dynamic:

 

var w = new Window ("dialog");
var myList = w.add ("listbox", undefined, ["one", "two", "three"]);
var b = w.add ("button", undefined, "Add");
b.onClick = function () {myList.add ("item", "zero", 0)}
w.show ();

 

How about if I wan't to update listbox when I have changed my arrays, like below:

 

// Create example array
var testArr = ['item1', 'item2']
$.writeln(testArr.length);

startGUI();
function startGUI() {
       // Window    var win = new Window( "palette", script_name, undefined, { resizeable:true } );    win.orientation = "column";    win.alignChildren = ["fill", "fill"];       // Listbox    var myListbox = win.add ("listbox", undefined, testArr,         {         numberOfColumns: 1,         showHeaders: true,         columnTitles: ['Name']    });    // Add Item To Array    var addItem = win.add("button", undefined, "Add Item");    addItem.onClick = function() {          testArr.push ('item3');        $.writeln(testArr.length);    }     // Quit BTN    win.quitBtn = win.add("button", undefined, "Close");    win.quitBtn.onClick = function() {          win.close();      }    win.show();
}

 

Maybe there is some update funtion on ScriptUI. I tried to search solution without success. Any help?

Illustrator Macros/Scripting

$
0
0
Hey guys is it possible to create macros in illustrator, or how would this be achieved via the scripting.

Basically i have a c# application that contains alot of pictureboxes all with images in them. i want to be able to right click an image and select vectorise. Which will send the image to illustrator live trace the image, resize it, then copy the resulting image back into my c# app.

How would this be best done

thanks
r

Batch replace color without using swatch as source

$
0
0

I've searched these forums and the rest of the web trying to find a method to do this... Actions don't cut it (if Actions were able to record the "replace color" dialoge it would be fine) so I've turned to scripts, but I have almost no knowlege on this.

 

I checked out this thread:

http://forums.adobe.com/message/2588737

 

and it is very close, except that it assumes that there is a named swatch as the source color - which there isn't.

 

The script I tried was .JS

 

I'm trying to have the script run on a bunch of .eps files in a folder:

- Select object which has specified CMYK value (0,7,34,10)

- Replace fill color of the selected object with another CMYK value (5,19,36,0)

- Save over the existing .eps

- Close

- Make coffee (optional)

 

Also, any books you can recommend for learning this stuff? For a noob.

Calling an applescript inside a Javascript, waiting for it to complete before moving on.

$
0
0

I've got a handly little applescript compiled as an app that performs an Adobe Illustrator action which exports the current file's artboard #1 to a specific location at 300ppi. I can even call it from a javascript... which is great because I want a javascript that will loop x times, changing text and exporting on each each loop. But, each loop will export a file with the same name... not a problem, I'll rename the file after each loop, and javascript will wait patiently for me the export to complete before moving on to the next step, right? Wrong! Javascript just keeps moving through the script.

 

So, how do I get Javascript to wait until the AppleScript completes the export? I can't have it wait a specific amount of time...export might take between 2 and 180 seconds.

 

My ideas:

1) can the applescript fire some sort of event letting Javascript know to move on?

2) Is there a Javascript equivalent to AppleScripts "do javavscript " command, which would allow me to move the Applescript code into my core javascript?

3) I could kludge a stopwatch on the first loop, checking every 10 milliseconds to see if the exported jpg file has been written... then using that as a baseline timer to pause later loops (not great, because the file will exist while AI writes it, and JS may rename it and try to export the second loop before the first is done).

 

 

 

for (z =0; z<copyArray.length; z++) {

var jpgExt = "-01.jpg";

var newExt = ([z] + jpgExt);

var exportASfile = File('/Applications/Adobe Illustrator CS5.1/Presets.localized/en_US/Scripts/VCS_Specialty Scripts/StandardExport.app');

exportASfile.execute();  // export the file

 

renamedFile = new File(exportFile); //variable exportFile is a reference to the jpg being written by the export

renamedFile.rename (exportFile.name.replace(jpgExt, newExt)   ); // replaces part of the filename with a new

 

}

Execute Action from Javascript in CS6

$
0
0

I've seen on this forum a lot people saying that in CS6 you can now call an action from JavaScript. However, I haven't been able to find what the syntax is to do that in the reference or the guide. Can you actually do this now with Javascript? And if so, how?

applying a swatch to a pathitem

$
0
0

I am trying to apply a swatch to all pathItems on a certain layer. I have the code written to access the layer I want but I am not sure how to apply a specific swatch name to the pathItems on the layer that I want. In my code if the pathItem is on a layer named "651(Highways)" I want the swatch in my document labeled "651 (Blue Gray)" to be applied to all those pathItems.

Anyone help me out with that? I am sure it is simple but I have never done it before and not much luck Google'n it.

Here is my code....

#target illustrator
var doc = app.activeDocument;
var allLayers = doc.layers;
var allLines = doc.pathItems;
var allSwatches = doc.swatches;


// CHECK TO SEE WHAT LAYER PATH ITEMS ARE ON
for (var i = allLines.length-1; i >= 0; i--){  if (allLines[i].layer == "[Layer Rails/Feather Bars]"){  allLines[i].filled = false;  lineFormat();  blackStroke();  allLines[i].strokeWidth = 2.0;  }  else if (allLines[i].layer == "[Layer 651 (Highways)]"){  lineFormat();  allLines[i].strokeWidth = 1.1;  }
else {  //alert("Found line on " + allLines[i].layer);  }
}
function lineFormat(){  allLines[i].filled = false;  allLines[i].strokeWidth = 1.6;  allLines[i].strokeJoin = StrokeJoin.MITERENDJOIN;  allLines[i].strokeCap = StrokeCap.BUTTENDCAP;  }
function blackStroke(){  var blackLine = new GrayColor();  blackLine.gray = 100;  allLines[i].stroked = true;  allLines[i].strokeColor = blackLine;  }

All Group to Ungroup Script

Rounding stroke thickness to nearest decimal?

$
0
0

I have a project where many objects have been scaled up and down during the creation of the artwork. And I'm left with some lines that are .9581 pts and some that are 1.039 pts.

 

Just because I'm a neat freak, is there a script that would round the stroke thickness to the nearest .1 decimal? Or whole number? Or user selectable amount of decimals?

Does exist a script to replace text in name or rename visible SubLayers, or, better, SubLayers of the selected Layer?

$
0
0

Hi!

"Batch Rename Visible Layers ILL.jsx" can rename several layers, number them. But no replacement, and most important, it doesn't treat sub layers :=(

Can you help me as I am not so good as you in scripting?

What I have :

Origin.jpg

What I want with 2 replacements : "Calque" -> "Cloche Arrière" and "CA D" -> "Cloche Arrière Droite" :

Result.jpg

Thanks a lot for attention, ETn

Can I get all objects/path items inside an artboard?

$
0
0

I've got a document with multiple artboards. I want to go through each artboard and note the positions of all pathItems inside. It's important to note the items in each artboard separately. Is there a way to do this?

Applescript: Removing Groups and Layers

$
0
0

This should be a simple task, but I still haven't figured out how to do it.

 

I have a set of page items, and the are contained in groups inside of layers inside of layer inside of layers.

How can I remove the layers easily?

I looked at the reference guide, and attached the screenshot where it explains how to use the "delete" command to remove containers of objects.

But I still dont' understand how to order the command correctly:

delete page item of layer?

delete layer of page item?

delete page item of layer of page item?

None of these work.

For now, I've just used an action, but it would be helpful if I could do it within a script.

 

Any help is appreciated.

Thanks,

 

Ben

Screen shot 2009-12-21 at 10.08.25 PM.png

Viewing all 12845 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>