function separateFillsByColor() {
    var sourceDoc = app.activeDocument;
    var targetLayerName = "A-AREA-PATT"
    var targetLayer = sourceDoc.layers[targetLayerName];
    var items = targetLayer.pageItems;
    var box = new Window('dialog', "Some title"); 
    var myLayer = targetLayer;
    var group = targetLayer.groupItems;
    var colorList = []
    var strokeColor = new RGBColor();
    strokeColor.red = 0
    strokeColor.blue = 0
    strokeColor.green = 0
    
    $.writeln("Test colour ",targetLayer.groupItems.length)

 //Ungroup each area color fill
    for (d=0;d<targetLayer.groupItems.length;d++){
    var mygroups = group[d];
          for (i=mygroups.pageItems.length-1; i>=0; i--)
               mygroups.pageItems[i].move(myLayer, ElementPlacement.PLACEATBEGINNING);
     }
 
    //Hide other layers than the target layer
    for(var i = 0; i < sourceDoc.layers.length; i++) {
            var layer = sourceDoc.layers[i];
            
            if (layer.name != targetLayerName)
            {
                layer.visible = false;
            }
    }

//Get all fill colors
   $.writeln("Test colour ",targetLayer.pathItems.length)
   
   for(var i = 0; i < targetLayer.pathItems.length; i++) {
            var item = targetLayer.pathItems[i];
            colorList.push(item.fillColor.spot.name)
            $.writeln("Test colour ",item.fillColor.spot.colorType)
    }

//Get unique fill colors
var uniqueColors = uniques(colorList)
$.writeln("Unique Color List: ",uniqueColors)

$.writeln("Number of Unique Colors",uniqueColors.length)

//Create new layers for each unique color
   for(var i = 0; i < uniqueColors.length; i++) {
        
        var myLayer = sourceDoc.layers.add();
        
        myLayer.name = uniqueColors[i]
            
            //Add items with matching colors to the newly created layer
           for(var x = 0; x < targetLayer.pathItems.length; x++) {
                var item = targetLayer.pathItems[x];
                
                if (item.fillColor.spot.name === myLayer.name)
                {
                        item.move(myLayer, ElementPlacement.PLACEATEND);
                        item.stroked = true;  
                        item.strokeColor = strokeColor;  
                        item.strokeWidth = 2;
                        $.writeln("Target layer path item match: ", item.fillColor.spot.name + " - " + myLayer.name)
                        //Optional code below to apply rounded corners to the object
                        //Stylize > Round Corners:
                        //app.executeMenuCommand('Live Adobe Round Corners');
                        //myPlainTextObjectStyle.applyTo(item);
                }
            else {
                $.writeln("Layer colors do not match:   " + item.fillColor.spot.name , "-" + myLayer.name)
                }
            }
   }

//While statement to ensure that items are placed on the matching layer - loose repeat of the method above

//Loop over remaining path items on the target layer
while (targetLayer.pathItems.length != 0) {
    for(var x = 0; x < targetLayer.pathItems.length; x++) {
                    var item = targetLayer.pathItems[x];
                    
                    //Match the remaining items against all existing layer names
                    for (var y = 0; y < sourceDoc.layers.length; y++){
                            if (item.fillColor.spot.name === sourceDoc.layers[y].name)
                            {
                                    $.writeln("Target layer path item second round match: ", item.fillColor.spot.name + " - " + sourceDoc.layers[y].name)
                                    item.move(sourceDoc.layers[y], ElementPlacement.PLACEATEND);
                                    item.stroked = true;  
                                    item.strokeColor = strokeColor;  
                                    item.strokeWidth = 2;
                            }
                        }
                }
        }

//Get compound path items on the target layer
while (targetLayer.compoundPathItems.length != 0) {
    for(var x = 0; x < targetLayer.compoundPathItems.length ; x++) {
                    var itemIndex = targetLayer.compoundPathItems[x];
                    var item = itemIndex.pathItems[0]
                    //var item = itemIndex.index
                    
                    //Match the remaining items against all existing layer names
                    for (var y = 0; y < sourceDoc.layers.length; y++){
                            if (item.fillColor.spot.name === sourceDoc.layers[y].name)
                            {
                                    $.writeln("Target layer path item second round match: ", item.fillColor.spot.name + " - " + sourceDoc.layers[y].name)
                                    targetLayer.compoundPathItems[x].move(sourceDoc.layers[y], ElementPlacement.PLACEATEND);
                            }
                        }
                }
        }
    
//Print out item attributes on remaining layer
for(var x = 0; x < targetLayer.pathItems.length; x++){
    $.writeln("Remaining Items: ", targetLayer.pathItems[x].fillColor.spot.name)
    }


//Create Key Layer with text boxes
var keyLayer = sourceDoc.layers.add();
        keyLayer.name = "Key"

}
//Separate Filled Area Colors to separate layers
Separate Filled Area Colors to separate layers
Separate Filled Area Colors to separate layers
function separateFillsByColor() {
    var sourceDoc = app.activeDocument;
    var targetLayerName = "A-AREA-PATT"
    var targetLayer = sourceDoc.layers[targetLayerName];
    var items = targetLayer.pageItems;
    var box = new Window('dialog', "Some title"); 
    var myLayer = targetLayer;
    var group = targetLayer.groupItems;
    var colorList = []
    var strokeColor = new RGBColor();
    strokeColor.red = 0
    strokeColor.blue = 0
    strokeColor.green = 0
    $.writeln("Test colour ",targetLayer.groupItems.length)
    for (d=0;d<targetLayer.groupItems.length;d++){
    var mygroups = group[d];
          for (i=mygroups.pageItems.length-1; i>=0; i--)
               mygroups.pageItems[i].move(myLayer, ElementPlacement.PLACEATBEGINNING);
     }
    for(var i = 0; i < sourceDoc.layers.length; i++) {
            var layer = sourceDoc.layers[i];
            if (layer.name != targetLayerName)
            {
                layer.visible = false;
            }
    }
   $.writeln("Test colour ",targetLayer.pathItems.length)
   for(var i = 0; i < targetLayer.pathItems.length; i++) {
            var item = targetLayer.pathItems[i];
            colorList.push(item.fillColor.spot.name)
            $.writeln("Test colour ",item.fillColor.spot.colorType)
    }
var uniqueColors = uniques(colorList)
$.writeln("Unique Color List: ",uniqueColors)
$.writeln("Number of Unique Colors",uniqueColors.length)
   for(var i = 0; i < uniqueColors.length; i++) {
        var myLayer = sourceDoc.layers.add();
        myLayer.name = uniqueColors[i]
           for(var x = 0; x < targetLayer.pathItems.length; x++) {
                var item = targetLayer.pathItems[x];
                if (item.fillColor.spot.name === myLayer.name)
                {
                        item.move(myLayer, ElementPlacement.PLACEATEND);
                        item.stroked = true;  
                        item.strokeColor = strokeColor;  
                        item.strokeWidth = 2;
                        $.writeln("Target layer path item match: ", item.fillColor.spot.name + " - " + myLayer.name)
                }
            else {
                $.writeln("Layer colors do not match:   " + item.fillColor.spot.name , "-" + myLayer.name)
                }
            }
   }
while (targetLayer.pathItems.length != 0) {
    for(var x = 0; x < targetLayer.pathItems.length; x++) {
                    var item = targetLayer.pathItems[x];
                    for (var y = 0; y < sourceDoc.layers.length; y++){
                            if (item.fillColor.spot.name === sourceDoc.layers[y].name)
                            {
                                    $.writeln("Target layer path item second round match: ", item.fillColor.spot.name + " - " + sourceDoc.layers[y].name)
                                    item.move(sourceDoc.layers[y], ElementPlacement.PLACEATEND);
                                    item.stroked = true;  
                                    item.strokeColor = strokeColor;  
                                    item.strokeWidth = 2;
                            }
                        }
                }
        }
while (targetLayer.compoundPathItems.length != 0) {
    for(var x = 0; x < targetLayer.compoundPathItems.length ; x++) {
                    var itemIndex = targetLayer.compoundPathItems[x];
                    var item = itemIndex.pathItems[0]
                    for (var y = 0; y < sourceDoc.layers.length; y++){
                            if (item.fillColor.spot.name === sourceDoc.layers[y].name)
                            {
                                    $.writeln("Target layer path item second round match: ", item.fillColor.spot.name + " - " + sourceDoc.layers[y].name)
                                    targetLayer.compoundPathItems[x].move(sourceDoc.layers[y], ElementPlacement.PLACEATEND);
                            }
                        }
                }
        }
for(var x = 0; x < targetLayer.pathItems.length; x++){
    $.writeln("Remaining Items: ", targetLayer.pathItems[x].fillColor.spot.name)
    }
var keyLayer = sourceDoc.layers.add();
        keyLayer.name = "Key"
}
function separateFillsByColor ( ) { var sourceDoc = app . activeDocument ; var targetLayerName = "A-AREA-PATT" var targetLayer = sourceDoc . layers [ targetLayerName ] ; var items = targetLayer . pageItems ; var box = new Window ( 'dialog' , "Some title" ) ; var myLayer = targetLayer ; var group = targetLayer . groupItems ; var colorList = [ ] var strokeColor = new RGBColor ( ) ; strokeColor . red = 0 strokeColor . blue = 0 strokeColor . green = 0 $ . writeln ( "Test colour " , targetLayer . groupItems . length ) for ( d = 0 ; d < targetLayer . groupItems . length ; d ++ ) { var mygroups = group [ d ] ; for ( i = mygroups . pageItems . length - 1 ; i >= 0 ; i -- ) mygroups . pageItems [ i ] . move ( myLayer , ElementPlacement . PLACEATBEGINNING ) ; } for ( var i = 0 ; i < sourceDoc . layers . length ; i ++ ) { var layer = sourceDoc . layers [ i ] ; if ( layer . name != targetLayerName ) { layer . visible = false ; } } $ . writeln ( "Test colour " , targetLayer . pathItems . length ) for ( var i = 0 ; i < targetLayer . pathItems . length ; i ++ ) { var item = targetLayer . pathItems [ i ] ; colorList . push ( item . fillColor . spot . name ) $ . writeln ( "Test colour " , item . fillColor . spot . colorType ) } var uniqueColors = uniques ( colorList ) $ . writeln ( "Unique Color List: " , uniqueColors ) $ . writeln ( "Number of Unique Colors" , uniqueColors . length ) for ( var i = 0 ; i < uniqueColors . length ; i ++ ) { var myLayer = sourceDoc . layers . add ( ) ; myLayer . name = uniqueColors [ i ] for ( var x = 0 ; x < targetLayer . pathItems . length ; x ++ ) { var item = targetLayer . pathItems [ x ] ; if ( item . fillColor . spot . name === myLayer . name ) { item . move ( myLayer , ElementPlacement . PLACEATEND ) ; item . stroked = true ; item . strokeColor = strokeColor ; item . strokeWidth = 2 ; $ . writeln ( "Target layer path item match: " , item . fillColor . spot . name + " - " + myLayer . name ) } else { $ . writeln ( "Layer colors do not match:   " + item . fillColor . spot . name , "-" + myLayer . name ) } } } while ( targetLayer . pathItems . length != 0 ) { for ( var x = 0 ; x < targetLayer . pathItems . length ; x ++ ) { var item = targetLayer . pathItems [ x ] ; for ( var y = 0 ; y < sourceDoc . layers . length ; y ++ ) { if ( item . fillColor . spot . name === sourceDoc . layers [ y ] . name ) { $ . writeln ( "Target layer path item second round match: " , item . fillColor . spot . name + " - " + sourceDoc . layers [ y ] . name ) item . move ( sourceDoc . layers [ y ] , ElementPlacement . PLACEATEND ) ; item . stroked = true ; item . strokeColor = strokeColor ; item . strokeWidth = 2 ; } } } } while ( targetLayer . compoundPathItems . length != 0 ) { for ( var x = 0 ; x < targetLayer . compoundPathItems . length ; x ++ ) { var itemIndex = targetLayer . compoundPathItems [ x ] ; var item = itemIndex . pathItems [ 0 ] for ( var y = 0 ; y < sourceDoc . layers . length ; y ++ ) { if ( item . fillColor . spot . name === sourceDoc . layers [ y ] . name ) { $ . writeln ( "Target layer path item second round match: " , item . fillColor . spot . name + " - " + sourceDoc . layers [ y ] . name ) targetLayer . compoundPathItems [ x ] . move ( sourceDoc . layers [ y ] , ElementPlacement . PLACEATEND ) ; } } } } for ( var x = 0 ; x < targetLayer . pathItems . length ; x ++ ) { $ . writeln ( "Remaining Items: " , targetLayer . pathItems [ x ] . fillColor . spot . name ) } var keyLayer = sourceDoc . layers . add ( ) ; keyLayer . name = "Key" }
Separate Filled Area Colors to separate layers
Separate Filled Area Colors to separate layers
//Ungroup each area color fill //Hide other layers than the target layer //Get all fill colors //Get unique fill colors //Create new layers for each unique color //Add items with matching colors to the newly created layer //Optional code below to apply rounded corners to the object //Stylize > Round Corners: //app.executeMenuCommand('Live Adobe Round Corners'); //myPlainTextObjectStyle.applyTo(item); //While statement to ensure that items are placed on the matching layer - loose repeat of the method above //Loop over remaining path items on the target layer //Match the remaining items against all existing layer names //Get compound path items on the target layer //var item = itemIndex.index //Match the remaining items against all existing layer names //Print out item attributes on remaining layer //Create Key Layer with text boxes