Charu,
Please find attached an example as well as the modified scripts
Change ext to zip
Hi @syntanjey
The above script that I have shared only works with the path items. Here is another version of the script which will be much faster and a better approach
1. Case 1: When you don't want to group all items that are move to the new layer.
function main() {
var doc = app.activeDocument;
var R = 255;
var G = 128;
var B = 0
var layerName = "+Doors";
try {
var _layer = doc.layers[layerName];
} catch (e) {
alert("No layer exists with name " + layerName);
}
app.executeMenuCommand("deselectall");
//Create temp pathitem to find out the all items with same stroke color
var _tempItem = doc.pathItems.add();
_tempItem.stroked = true;
_tempItem.strokeColor.red = R;
_tempItem.strokeColor.green = G;
_tempItem.strokeColor.blue = B;
_tempItem.selected = true;
app.executeMenuCommand("Find Stroke Color menu item");
var _allItems = app.selection;
for (var i = 0; i < _allItems.length; i++) {
_allItems[i].move(_layer, ElementPlacement.PLACEATEND);
}
_tempItem.remove();
}
main();
Case 2: If it is ok to have all items to be grouped.
function main() {
var doc = app.activeDocument;
var R = 255;
var G = 128;
var B = 0
var layerName = "+Doors";
try {
var _layer = doc.layers[layerName];
} catch (e) {
alert("No layer exists with name " + layerName);
}
app.executeMenuCommand("deselectall");
//Create temp pathitem to find out the all items with same stroke color
var _tempItem = doc.pathItems.add();
_tempItem.stroked = true;
_tempItem.strokeColor.red = R;
_tempItem.strokeColor.green = G;
_tempItem.strokeColor.blue = B;
_tempItem.selected = true;
app.executeMenuCommand("Find Stroke Color menu item");
//Use Below code if it is ok to be group
app.executeMenuCommand("group");
app.selection[0].move(_layer, ElementPlacement.PLACEATEND);
_tempItem.remove();
}
main();
The approach that I am using in the updated versions of the script is :
1. Create a temporary path item with required stroke color
2. Select the item. By this we are not traversing all pageitems and no need to check type of pageitem too.
3. Run the command to select all items with same stroke color
4. Group all selected items and then move to the required layer.
OR
4. Move all selected items one by one to the required layer.
(Choose step 4 depending upon requirements)
5. After that we can remove the temporray item.
I hope this will work in your all scenarios.