Copy link to clipboard
Copied
PLEASE HELP
I'm newer to AI Scripting.
I need to create 30 arrow like objects (d0,d1,...,d29) with various lengths. I can store the lengths in an array ('mylength[]') - but do i need to copy the same code over and over 30 times? Can I create an object where the name of the object is a member of another array? If i could I could run a for loop to create all 30 arrows.
This is the code i have -
var d0 = peoplelayer.pathItems.add(); d0.closed = true;
d0.setEntirePath([[0,0], [-16, 12], [-16, 8], [-mylength[0], 8],[-mylength[0],-8],[-16,-8],[-16,-12]]);
This code has the idea but it doesnt work -
var arrownames = ["d0","d1","d2",...,"d29"]
var arrownames[0] = peoplelayer.pathItems.add(); arrownames[0].closed = true;
arrownames[0].setEntirePath([[0,0], [-16, 12], [-16, 8], [-mylength[0], 8],[-mylength[0],-8],[-16,-8],[-16,-12]]);
Have something that might?
Hi theBGF.
var mylength = [5,10,15,20,25,30,35,40,45,50,55,60,65,70,75,80,85,90,95,100,105,110,115,120,125,130,135,140,145,150,155];
var d = new Array();
for (i=0;i<30;i++){
d = app.activeDocument.layers[0].pathItems.add();
d.setEntirePath([[0,0], [-16, 12], [-16, 8], [-mylength, 8],[-mylength,-8],[-16,-8],[-16,-12]]);
d.closed = true;
}
Try this script.
You can access arrow object (pathItems) are d[1] to d[30].
Copy link to clipboard
Copied
Hi theBGF.
var mylength = [5,10,15,20,25,30,35,40,45,50,55,60,65,70,75,80,85,90,95,100,105,110,115,120,125,130,135,140,145,150,155];
var d = new Array();
for (i=0;i<30;i++){
d = app.activeDocument.layers[0].pathItems.add();
d.setEntirePath([[0,0], [-16, 12], [-16, 8], [-mylength, 8],[-mylength,-8],[-16,-8],[-16,-12]]);
d.closed = true;
}
Try this script.
You can access arrow object (pathItems) are d[1] to d[30].
Copy link to clipboard
Copied
Just an alternative… If I understood…
for (var i = 0, l = 5; i < 30; i++, l += 5) { //$.writeln(i+' '+l); var a = app.activeDocument.layers[0].pathItems.add(); a.name = 'Arrow '+i; a.setEntirePath([[0,0],[-16, 12],[-16, 8],[-l, 8],[-l,-8],[-16,-8],[-16,-12]]); a.closed = true; } app.activeDocument.layers[0].pathItems.getByName('Arrow 10');
Copy link to clipboard
Copied
I think some situation, name property is very useful.
Thanks Mark! (^_^;
Copy link to clipboard
Copied
Awesome - this worked perfectly. Thank you.
Copy link to clipboard
Copied
No problem… I saw no point in storing an Array for later access… You already have one the relative 'path items collection'… Naming items is the easiest method you can also use notes or better still tags (a single item can have numerous tags) very handy. No need to have a list of incrementing values when you can make them as you go… someObject.getByName(someString); will return you the 'first' object that matches your query… so make each unique…