5 Replies Latest reply on Dec 8, 2012 12:14 PM by Muppet Mark

    Is it possible to copy and duplicate (only) text to multiple layers?

    wimkees Level 1

      Hallo.

       

      Explanation of my question:

       

      I have an Illustrator document with one layer (named Layer 1).

      In that layer are lines, rectangles and text.

       

      Is it possible (in script) to:

      1. make 3 additional layers named NL, EN and GE
      2. select and cut all the text in Layer 1
      3. paste that text in the same place in the layers NL, EN and GE

       

      (Step 2: select all text items and Ctrl-X)

      (Step 3: select proper layer and Paste in Place in that layer)

       

      I know this can be done with an action (I did that allready) but the reason I want to script this is because I have to combine this with another script which takes care of colorizing stuff.

       

      Hope someone can help me with this...

       

      Wim

        • 1. Re: Is it possible to copy and duplicate (only) text to multiple layers?
          Muppet Mark Level 5

          Yes script can easily do this for you… You have no need for selection in this process… Script would loop all your layer text frames dupicating them and moving dupe to new layer… In script you would not use copy and paste methods for this… You say you have one layer but are all the text frames in this or are there sub-layers and groups to deal with…?

          • 2. Re: Is it possible to copy and duplicate (only) text to multiple layers?
            wimkees Level 1

            Since the original placed file in Layer 1 is a SVG file: yes the text is in groups / in groups / in groups (can be deeply nested). There are no sublayers.

            After pasting in the new layers this structure is not important to keep intact...

             

            Did manage to script the layers: for (var i = 0; i<3;i++) { app.activeDocument.layers.add(); } activeDocument.layers[0].name = "GE"; activeDocument.layers[1].name = "EN"; activeDocument.layers[2].name = "NL"; Message was edited by: wimkees

            1 person found this helpful
            • 3. Re: Is it possible to copy and duplicate (only) text to multiple layers?
              Muppet Mark Level 5

              Well I made a simple-ish test file and this appears to work here…

              #target illustrator
              
              languageLayers();
              
              function languageLayers() {
                
                        var i, doc, txt, count, nl, en, ge;
                
                        doc = app.activeDocument;
                
                        txt = doc.textFrames;
                
                        count = txt.length;
                
                        nl = doc.layers.add(); nl.name = 'NL';
                
                        nl.move( doc, ElementPlacement.PLACEATEND );
                
                        en = doc.layers.add(); en.name = 'EN';
                
                        en.move( doc, ElementPlacement.PLACEATEND );
                
                        ge = doc.layers.add(); ge.name = 'GE';
                
                        ge.move( doc, ElementPlacement.PLACEATEND );
              
                        for ( i = count-1; i >= 0; i-- ) {
                
                                  txt[i].duplicate( nl, ElementPlacement.PLACEATBEGINNING );
                
                                  txt[i].duplicate( en, ElementPlacement.PLACEATBEGINNING );
                
                                  txt[i].duplicate( ge, ElementPlacement.PLACEATBEGINNING );
              
              
                        };
                
              };
              
              • 4. Re: Is it possible to copy and duplicate (only) text to multiple layers?
                wimkees Level 1

                Hi,

                 

                You're SUPER!

                Tested the script and it's working exept for one thing: the text should be removed from the layer 1 it was in at the beginning.

                I fixed that by changing the duplicate command to move...

                txt[i].move( nl, ElementPlacement.PLACEATBEGINNING );

                 

                Thx for helping me!

                 

                Wim

                • 5. Re: Is it possible to copy and duplicate (only) text to multiple layers?
                  Muppet Mark Level 5

                  No problem… glad you sorted it… you will notice a couple of things I did here… when moving or duplicating objects to another container ( layer in this case ) if you loop forward then placement to end preserves object order looping backward as I did here placement to beginning preserves object order. New layers by default add to the top but I moved them after the original layer… this was to put the duplicate text frames's index out of range of the loop…