5 Replies Latest reply on Apr 29, 2014 2:22 AM by Denis Lelong

    Place 2 objects into a new layer and rename that layer

    Dr.Graphic Level 1

      Hi All

       

      Have a little problem and need your help:

      - I have an ai with hundreds of objects in it. All in one layer.

      - There are two types of objects: blocks and textlayers (numbers). So each block has a number on it's top.

       

      http://i58.tinypic.com/mafmgg.jpg

       

      What I finally need is a new layer structure:

      - Each object+textlayer must be put in a separate layer AND that new layer must be renamed to the number which is inside that layer.Like that:

      http://i58.tinypic.com/2wejfup.jpg

       

      My first thought was to collect objects by it's position. For example: Position of the text object can be placed at x and y coordinates of the block, but + 2mm offset for margins. This would be the recognition point for the script to put them in the separate layer.

      Or look for overlapping objects and put them in a new layer.

       

      Also found something which can work with existing scripts if there can be written an additional one:

      Here is a script for converting groups into layers and retaining group names:

      http://forums.adobe.com/thread/892733

       

      Here is a script to make groups out of overlapping objects:

      http://js4ai.blogspot.be/2008/04/new-script-group-overlapping-objects.html

       

      In theory if there would be a script for changing group names to the textlayer names, then the problem would be fixed in those three steps.

       

      Does anyone know a solution for this? I'm not a developer, know almost nothing about coding.

       

      Thanks!

        • 1. Re: Place 2 objects into a new layer and rename that layer
          CarlosCanto Adobe Community Professional & MVP

          here you go,

           

          what is it for? just curious

           

          #target Illustrator
          
          //  script.name = moveText_n_Box_toNewLayer.jsx;
          //  script.description = custom script to move a path and its INSCRIBED label to a new layer
          //  script.requirement = CS5+ only, one open document, one artboard, some rectangles and text labels inside them.
          //  script.parent = carlos canto // 03/31/14
          //  script.elegant = false;
          
          
          //  http://forums.adobe.com/thread/1440702?tstart=0
          
          
          var idoc = app.activeDocument;
          var abRect = idoc.artboards[0].artboardRect;
          var tempAB = idoc.artboards.add(abRect);
          
          
          var tfs = []; // text frames container
          
          
          for (j=0; j<idoc.textFrames.length; j++) {
              tfs.push(idoc.textFrames[j]);
          }
          
          idoc.selection = null;
          
          
          for (i=0; i<tfs.length; i++) {
              itext = tfs[i];
              tempAB.artboardRect = itext.visibleBounds;
          
              var ilayer = idoc.layers.add();
              ilayer.move(idoc, ElementPlacement.PLACEATEND);
              ilayer.name = itext.contents;
          
              itext.move(ilayer, ElementPlacement.PLACEATEND);
              itext.locked = true;
          
          
              idoc.selectObjectsOnActiveArtboard();
          
          
              var sel = idoc.selection;
              for (a=0; a<sel.length; a++) {
                  sel[a].move (ilayer, ElementPlacement.PLACEATEND);
              }
          
          
              itext.locked = false;
          
              idoc.selection = null;
          }
          
          var activeAbIndex = idoc.artboards.getActiveArtboardIndex();
          idoc.artboards.remove (activeAbIndex);    
          
          
          tfs = null;
          
          • 2. Re: Place 2 objects into a new layer and rename that layer
            W_J_T Level 4

            Seems doable (I roughed a working version actually).

            Valeri Potchekailov wrote:

             

            - There are two types of objects: blocks and textlayers (numbers). So each block has a number on it's top.

            - Each object+textlayer must be put in a separate layer AND that new layer must be renamed to the number which is inside that layer.

            - In theory if there would be a script for changing group names to the textlayer names, then the problem would be fixed in those three steps.

             

            But questions:

             

            1.) So is the text and corresponding shape grouped together now or not, or just all individual items?

            2.) Regardless, do you want them grouped in the end or just each moved to their respective layer and not grouped?

             

            EDIT: CarlosCanto already beat me. My solution is quite similar.

            • 3. Re: Place 2 objects into a new layer and rename that layer
              CarlosCanto Adobe Community Professional & MVP

              Hi wjt, I had made a script before for a similar request, so I thought I might as well

              • 4. Re: Place 2 objects into a new layer and rename that layer
                Dr.Graphic Level 1

                CarlosCanto, thank you very much. This is exactly what I need! Works like a charm.

                 

                @W_J_T, thanks for your input. My explanation was not so clear, sorry. I didn't need groups, just objects in layers. Initially objects are not grouped, only if I would work with workarounds I would have to make them grouped to make existing script work. To group objects I would have used the script 'overlapping layers', the next step (no script for that) is to rename that group to a number and final step would be to use an existing script to create layers out of these groups (group becomes a layer with only objects in it) and retain the group name.

                 

                Apparantly it all can be done in one step which CarlosCanto has made. Thank you!

                 

                I use it in a project where I need to create a floorplan for a venue, but to make it work on web I must deliver a vector file with layer structure described above :s

                 

                Greetings

                • 5. Re: Place 2 objects into a new layer and rename that layer
                  Denis Lelong

                  Hi,

                   

                  Thanks a lot, I actually had a similar need and this definetely beats doing it by hand !

                   

                  Not knowing anything about scripting I'm now wondering if it'd also be possible to center align each number inside its block ?

                   

                  Thanks again.