Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

[SOLVED] Need a simple attribute copy/duplicate script

Community Beginner ,
Oct 22, 2019 Oct 22, 2019

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!

TOPICS
Scripting
1.0K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
LEGEND ,
Oct 22, 2019 Oct 22, 2019

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 22, 2019 Oct 22, 2019

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();
                }
    }

  }
}

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 22, 2019 Oct 22, 2019
LATEST

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

    }
}

 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines