0

The area selected in the illustrator script does not have a bottom center line. What could be the problem.

var aDoc = app.activeDocument;  
var aSel = aDoc.selection;  
var len = 10;  
var line = null;  
for (i=0; i<=aSel.length-1; i++)   
{  
    var pI = new Array (2);  
    pI[0] = aSel[i].left + aSel[i].width/2,0;  
    pI[1] = aSel[i].top - aSel[i].height/2,0;  

    line = aDoc.pathItems.add();  
    line.setEntirePath ( new Array( new Array ( pI[0], pI[1] ), new Array( pI[0]+len, pI[1]+len )));  

    line.pathPoints[1].rightDirection = new Array( pI[0]+len, pI[1]+len);  
    //line.pathPoints[1].anchor = new Array( pI[0]+len*1.2, pI[1]+len*0.8);  


    line.rotate(45-i, true, true, true, true, Transformation.BOTTOMLEFT);



    line.filled = false;  
    line.stroked = true;  
    line.strokeWidth = 1;  
    line.strokeColor = aDoc.swatches[1].color;  
} 
  • Instead of ne array everywhere you can just use btackets line.setEntirePath ( [[ pI[0], pI[1] ], [ pI[0]+len, pI[1]+len ]]); is slightly more readable because it fits in smaller area. – joojaa Feb 3 at 7:47
0

I reduced the code a little. my problem is still going on. It's not exactly central. There's a very small deviation.

var aDoc = app.activeDocument;
var aSel = aDoc.selection;
var len = 10;
var line = null;

for (i=0; i<=aSel.length-1; i++)
{
var pI = new Array (2);
pI[0] = aSel[i].left + aSel[i].width/2,0;
pI[1] = aSel[i].top - aSel[i].height/2,0;

line = aDoc.pathItems.add();
line.setEntirePath ( [[ pI[0], pI[1] ], [ pI[0]+len, pI[1]+len ]]);

line.rotate(45-i, true, true, true, true, Transformation.BOTTOMLEFT);

line.filled = false;
line.stroked = true;
line.strokeWidth = 1;
line.strokeColor = aDoc.swatches[1].color;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.