Don’t litter in layers

Dec 11, 2021


If the script creates similar objects every time you run it, then it becomes difficult to navigate in the Layers panel. For further work, the user will have to deal with it.

The script added a lot of objects

How to get rid of chaos:

  • Create a new layer for objects. But this may disrupt the user’s layer system
  • Group the created objects on the current layer.


var newGroup = addGroup('MARKERS');
for (var i = 0; i < selection.length; i++) {
selection[i].move(newGroup, ElementPlacement.PLACEATBEGINNING);
function addGroup(name) {
var lblGroup;
try {
lblGroup = activeDocument.groupItems.getByName(name);
} catch (e) {
lblGroup = activeDocument.activeLayer.groupItems.add(); = name;
return lblGroup;

The try...catch construct is needed so that when you run the script again, you don’t possibly duplicate an already existing group.

In my NumeratesPoints script, markers and numbers are added to separate groups




Sergey Osokin. Product Illustrator, Icon Designer, Script Developer (Ai, Ps). Writing about bugs and tricks in Adobe Illustrator scripts