// 2020, use it at your own risk;
if (app.documents.length > 0) {
var thePaths = collectPaths ();
var ref4 = new ActionReference();
ref4.putProperty(stringIDToTypeID("property"), stringIDToTypeID("numberOfLayers"));
ref4.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
var docDesc = executeActionGet(ref4);
var theNumberOfLayers = docDesc.getInteger(stringIDToTypeID("numberOfLayers"));
// create groups;
for (var m = 0; m < thePaths.length; m++) {
var theName = thePaths[m][0];
// =======================================================
var idname = stringIDToTypeID( "name" );
var desc2 = new ActionDescriptor();
var ref1 = new ActionReference();
ref1.putClass( stringIDToTypeID( "layerSection" ) );
desc2.putReference( stringIDToTypeID( "null" ), ref1 );
var desc3 = new ActionDescriptor();
desc3.putString( idname, theName );
desc2.putObject( stringIDToTypeID( "using" ), stringIDToTypeID( "layerSection" ), desc3 );
desc2.putInteger( stringIDToTypeID( "layerSectionStart" ), theNumberOfLayers++ );
desc2.putInteger( stringIDToTypeID( "layerSectionEnd" ), theNumberOfLayers++ );
desc2.putString( idname, theName );
executeAction( stringIDToTypeID( "make" ), desc2, DialogModes.NO );
}
};
////// collect layers //////
function collectPaths () {
// the file;
var myDocument = app.activeDocument;
// get number of paths;
var ref = new ActionReference();
ref.putProperty(stringIDToTypeID("property"), stringIDToTypeID("numberOfPaths"));
ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
var applicationDesc = executeActionGet(ref);
var theNumber = applicationDesc.getInteger(stringIDToTypeID("numberOfPaths"));
// process the paths;
var thePaths = new Array;
for (var m = 0; m <= theNumber; m++) {
try {
var ref = new ActionReference();
ref.putIndex( stringIDToTypeID( "path" ), m);
var pathDesc = executeActionGet(ref);
var theName = pathDesc.getString(stringIDToTypeID('pathName'));
var theID = pathDesc.getInteger(stringIDToTypeID('ID'));
thePaths.push([theName, theID])
}
catch (e) {};
};
return thePaths
};