Quantcast
Channel: Adobe Community : Popular Discussions - Illustrator Scripting
Viewing all articles
Browse latest Browse all 12845

Move and Place on Specific Layers

$
0
0

Morning!

 

Thanks to the helpfulness of everyone on the forums I have a script that will create layers with specific names, locks the bottom Layer!  I am hoping I can take this script even further if possible.

 

The script creates 5 new layers and I would love it if we could move elements by color to a specific layer

If "Color A" filled objects exist Select All "Color A" and move to Layer "A"

If "Color B" filled objects exist Select All "Color B" and move to Layer "B"

If "Color C" filled objects exist Select All "Color C" and move to Layer "C"

If "Color D" filled objects exist Select All "Color D" and move to Layer "D"

Then Delete all Empty Layers

 

var main = function(layerCount) {    
var doc, layers;    
if ( !app.documents.length ) {  
alert("This scripts needs an open document !");  
return;  
}    
//The doc  
doc = app.activeDocument;  
//Adding useful layers  
addLayers ( doc );  
}    
// WILL CREATE ANY NUMBER OF NAMED LAYERS === 'NAME', 
var addLayers = function ( doc ) {  
var layers = getLayersDB ( doc );  
var layerNames = [  
'A',  
'B',
'C',
'D',
'BASE',
],  
name;    
while ( name = layerNames.pop() )  !layers[name]  && addLayer ( doc, name );  
};    
var addLayer = function ( doc, name ) {  
doc.layers.add().name = name;  
}    
var getLayersDB = function ( doc ) {  
var db = {}, layers = doc.layers, n = layers.length, layer;    
while ( n-- ) {  
layer = layers[n];  
db[layer.name] = layer;  
}  
return db;  
}   
main();  


// LOCK BOTTOM LAYER -= ONLY WORKS IF THERE ARE MULTIPLE LAYERS EXIST =-
if (documents.length > 0) { 
countOfLayers = activeDocument.layers.length; 
}
if (countOfLayers > 1) { 
bottomLayer = activeDocument.layers[countOfLayers-1];
}
bottomLayer.locked = true;

 

 

As always thank you for your thoughts and support!


Viewing all articles
Browse latest Browse all 12845

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>