[SOLVED] Need a simple attribute copy/duplicate script
Copy link to clipboard
Copied
Hello, looking to develop a simple attributes script for illustrator, as follows:
Loop through all atributes in all objects in the file
Based on the atributes value, make that many copies/duplicates of the object
If the atribute is 0, delete the object(s)
So say i had the expanded letter A with an atribute of 4, and expanded letter B with an atribute of 2, and C with 0 we would get
AAAABB
Alternatively id like to put all the atributes into a window prompt with a text box underneath each atribute to manually input copies, but thats for a later day,
Copies don't need to be non-overlapping either, just pasted on top of themselves is fine.
Thanks so much!
Explore related tutorials & articles
Copy link to clipboard
Copied
I don't have an answer for you, but I don't see your post when filtered with "Scripting" tag. If you add the tag to your post it may get a better response.
Copy link to clipboard
Copied
Thanks! I figured part of it out so far, it runs off of grouped objects with attributes, i found that using pathitem or pageitem can have differing results based on letters that are compound paths or regular paths and the code to check everything would get kind of bulky, progress so far is removal of the "0" copies letters in a repeating loop, did a repeater since you would have to run the script multiple times to get all of the objects in illustrators step-process time.
So in a nutshell, have a bunch of letters, set each letter to its own group, set all attributes in the file to 0, save as a template, then go back in and pick which letters you need in their sizes via >0 amount in the attribute note, working in between projects at work to figure it out, for work 🙂
if (app.documents.length > 0) {
var sourceDoc = app.activeDocument;
main();
function main() {
for (var i = 0; i < sourceDoc.groupItems.length; i++)
{
var artItem = sourceDoc.groupItems[i];
var copies = artItem.note;
if (copies != 0)
{
//duplicate artItem by the copies variable amount
}
else{artItem.remove();
main();
}
}
}
}
Copy link to clipboard
Copied
Heres the solution, running two functions with 3 loops, group all of your shapes first and set a copy amount in the attributes panel, works on anything i think, might be a cleaner way, but this is pretty fast.
/*
This is a real simple script to create duplicates of a grouped object or objects, and delete the others that have no copies listed, to use it do as follows:
1. create your template file, we used letters for ours
2. ctrl-g or group each individual letter
3. open window>attributes
4. select all the groups
5. type 0 in the attributes note panel (the big white box)
6. select the objects individually that you want copies of and set their copy amount, 1 is equal to no copies, 0 is equal to deletion, 2 is 2 copies etc
7. enjoy
** Ivan D Popov, Valley Signs 2019*/
if (app.documents.length > 0) { //if an open document exists
var sourceDoc = app.activeDocument; //set the focus of the script to the open window on top
removeit(); // run the 0 copy remover
main(); // run the duplicator
function main() {// duplicator will create copies of the grouped objects
for (i = 0; i < sourceDoc.groupItems.length; i++) { //get all grouped items
var artItem = sourceDoc.groupItems[i]; //set a variable to grouped items
var copies = artItem.note; // get all grouped items note contents
if (copies != 0) { //if note contents do not equal zero
for (j = 1; j < copies; j++) { //loop the function by number of copies minus one, the original object
artItem.duplicate(); // duplicate the item
}
}
}
return 0; //return 0 to keep it clean
}
function removeit() { //remover will get rid of the 0 copy objects in a loop until it finds none
for (k = 0; k < sourceDoc.groupItems.length; k++) { //get all group items
var remItem = sourceDoc.groupItems[k]; //set variable to items
var remcopy = remItem.note; //get all grouped items note contents
if (remcopy == 0) { //if the contents are EQUAL to zero
remItem.remove(); //get rid of it
removeit(); // run this function again just to be sure
}
}
return 0; //return 0 to keep it clean
}
}

