1

IN SUMMARY...MANUALLY all I need to do is ...select all...change width or height depending on which side is longer and constrain THAT'S IT >.<....SOUNDS SIMPLE RIGHT?

THE QUESTION IS THIS....Am I going through the wrong layers or selection objects? OR Is there a way to change the way the layers, objects, and component paths are organized so that I can resize the entire image correctly?

I have these EPS files that I want to Resize each layer to a certain dimension. The code pulls in a dimension in the filename. The filename is as follows order#_FOT_item#_dimension.eps

If the width is bigger than the height, then the program will change the width to the filename dimension and vice versa. It is supposed to constrain the entire image including all of it's layers, objects, etc

I'm fairly new to Illustrator and this script WORKS for most of the EPS files I have, but the problem is, sometimes the EPS file has so many layers, component paths, groups, etc, it is pulling in the wrong values. I have been trying to troubleshoot this problem for weeks now.

With ALL the steps ...again manually , you open the file > unlock layers if needed > unlock objects if needed > select all > change width or height according to filename dimension ... I need that value (width and height) to be the value for when I run my script / actionscripts

The javascript I have is below, I've created several alerts which can be commented out if needed. I've also attached the link below which contains my .AIA file for the action scripts I use with my javascript below. This javascript is to be inserted below "group" action. I also attached a link which contains sample files to test manually vs scripting. The set of tickets should work and output the same value manually and using the script. The sun and the dancer, I cannot figure out what the issue is. Ungrouping / grouping works for the sun, but I need an overall fix for all 3 files to work everytime I run this script.

Thank you!!!

AIA File

Sample Files

//Resizes according to Filename

doc = app.activeDocument;
doc_name = doc.name;

numberVars = doc_name.replace(/^\d+/g, '');
numArray = numberVars.split('_');
var2 = numArray[3];
var3 = var2.substring(0, var2.indexOf('.'));


    function main(){
        var toPixels=function(y){

        var unit={
                'in':72,

               },re = /(\d*[.]*\d+)(in)/i,m,u,rep;

            while(m=y.match(re)){
                u = m[2].toLowerCase();

                    rep = (m[1]*unit[u]);
                    y = y.replace(re,rep);

            }
            return y;
        }

    //app.executeMenuCommand('selectall');

    totLayers = doc.layers.length;

    for (var a=0;a<totLayers;a++)
    {
    //newGroup = app.activeDocument.groupItems.add();
    for(a=0; a<doc.selection.length; a++)
    {
    //obj = doc.selection[a]; 
    //alert(obj);
    obj = doc.selection[a];

    var x = "width,height";
    var currW = obj.width/72;
    alert("This is the current Width: " + currW);
    var currH = obj.height/72;
    alert("This is the current Height: " + currH);
    measureM = "in";

    if(currW>currH)
    {
    alert("The width is bigger than the height");
        ratioW = (currW)/var3;
    alert("This is the ratio of Width: " + ratioW);
        newW = var3.concat(measureM);
    alert("This is the new Width: " + newW);
        calcH= currH/ratioW;
    alert("This is the new height: " + calcH);
        calcH = calcH.toString();
        newH = calcH.concat(measureM);

    }

    else
    {
    alert("The height is bigger than the Width");
        ratioH = (currH)/var3;
    alert("This is the ratio of Width: " + ratioH);
        newH = var3.concat(measureM);
    alert("This is the new Height: " + newH);
        calcW = currW/ratioH;
    alert("This is the new width: " + calcW);
        calcW = calcW.toString();
        newW = calcW.concat(measureM);

    }

    var y = newW+","+newH;
    y = toPixels(y);


    var assign = function(x,y)
    {
        obj[x] = eval(y);
    }

        if(x.indexOf(',') !== -1)
        {  
            x =  x.split(',');
        }

        if(y.indexOf(',') !== -1)
        { 
            y= y.split(',');
        }

        for (var len=x.length,c=0;c<len;c++)
            {
                assign(x[c],typeof y !== 'string' ? y[c] : y);
            }
    }   
    }
    }
    main();
0

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.