Quantcast
Channel: Adobe Community: Message List
Viewing all articles
Browse latest Browse all 173476

Re: Re: How do I flatten the layers in an illustrator document using extendscript

$
0
0
I can't get this to work. Is this because I have to form a GroupItem and move everything into that then move the group item to a different layer first?

you could make a group first, but why create an extra step? moving items into a group takes the exact same effort as moving them into a Layer

 

this is not good

var contents=currentLayer.hasSelectedArtwork = true;

 

the contents variable has a value of "true"; not the actual selected objects, causing the next line to break the script.

 

you have to move every item in the Layer, one by one...and there's no need to select them first.

 

var doc = activeDocument;
var destination=app.activeDocument.layers[1]
$.writeln(destination.name);

// loop backwards, to keep items in the right stacking order
for (var i = doc.layers.length-1; i>=0; i--) {     var currentLayer = app.activeDocument.layers[i];     $.writeln(currentLayer.name)     if(currentLayer.name!="Contents") {         var itemcount = currentLayer.pageItems.length;                 // loop through all items...backwards, each time you move an item out of the layer         // the remaining items get re-indexed         for (var a=itemcount-1; a>=0; a--) {            var pgItem = currentLayer.pageItems[a];                       // moveTo() method is deprecated, use move() instead            pgItem.move(destination, ElementPlacement.PLACEATBEGINNING);        }     }
}

Viewing all articles
Browse latest Browse all 173476

Trending Articles



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