3 Replies Latest reply on Sep 11, 2015 5:01 AM by Qwertyfly...

    Script to move same colour value objects to a layer

    abspeed

      I have a range of objects coloured up in process colors, and i would like to script them being moved to individual layers.

       

      so the result would be to move all of the cyan items to layer CYAN, move all of the magenta items to layer Magenta, etc etc.

       

      Could anyone help please?

       

      Many thanks

        • 1. Re: Script to move same colour value objects to a layer
          Qwertyfly... Level 4

          something Like this will do the trick.

           

          REMEMBER: this can make a mess of your stacking order...

           

          function seperate_items_to_layers_by_colour(){
              var doc = app.activeDocument;
              var item = doc.pageItems;
              var C_lay = make_layer_if_needed("CYAN");
              var M_lay = make_layer_if_needed("MAGENTA");
              var Y_lay = make_layer_if_needed("YELLOW");
              var K_lay = make_layer_if_needed("BLACK");
              
              for(var i=0; i<item.length; i++){
                  if(item[i].fillColor.cyan == 100 && item[i].fillColor.magenta == 0 && item[i].fillColor.yellow == 0 && item[i].fillColor.black == 0){
                      item[i].move(C_lay, ElementPlacement.PLACEATBEGINNING);
                  }else if(item[i].fillColor.cyan == 0 && item[i].fillColor.magenta == 100 && item[i].fillColor.yellow == 0 && item[i].fillColor.black == 0){
                      item[i].move(M_lay, ElementPlacement.PLACEATBEGINNING);
                  }else if(item[i].fillColor.cyan == 0 && item[i].fillColor.magenta == 0 && item[i].fillColor.yellow == 100 && item[i].fillColor.black == 0){
                      item[i].move(Y_lay, ElementPlacement.PLACEATBEGINNING);
                  }else if(item[i].fillColor.cyan == 0 && item[i].fillColor.magenta == 0 && item[i].fillColor.yellow == 0 && item[i].fillColor.black == 100){
                      item[i].move(K_lay, ElementPlacement.PLACEATBEGINNING);
                  }
              }
          
          
              function make_layer_if_needed(layerName){
                  try{
                      return doc.layers.getByName(layerName);
                  }catch(err){
                      lay = doc.layers.add();
                      lay.name = layerName;
                      return lay;
                  }
              }
          }
          seperate_items_to_layers_by_colour();
          
          • 2. Re: Script to move same colour value objects to a layer
            abspeed Level 1

            Hi Qwertyfly many thanks, that does the job perfectly.

            • 3. Re: Script to move same colour value objects to a layer
              Qwertyfly... Level 4

              Edit:

              sorry thought i was was in a different post

               

              good to hear it works for you.