How to Group all Objects on a document in Illustrator CC with Javascript? I try to make a script and I need to group all the objects in the document without errors and correctly. In the official guideline I did not find such a function. The code below does not correctly group objects. Objects change places and move to the foreground or to the background. Who can help me?
function group(){
var docRef = app.activeDocument;
var layerRef = docRef.layers[0];
layerRef.hasSelectedArtwork=true;
docSelection = app.activeDocument.selection;
newGroup = app.activeDocument.groupItems.add();
for ( i = 0; i < docSelection.length; i++ ) {
newItem = docSelection[i];
newItem.moveToBeginning( newGroup );
}
}