here the code. it's not working:
// remove all swatches not defined in breakdowns object
var swatch,
counter = 0;
for (var i = doc.swatches.length - 1; i >= 0; i--) {
doc.swatches[i].remove();
counter++;
}
}
}
alert("Deleted " + counter + " swatches.");
// remove any left over swatch groups
var swatchGroup,
counter = 0;
for (var i = doc.swatchGroups.length - 1; i >= 0; i--) {
swatchGroup = doc.swatchGroups[i];
if (swatchGroup.getAllSwatches().length == 0) {
swatchGroup.remove();
counter++;
}
}
alert("Deleted " + counter + " empty swatch groups.");
Here's the entire script and it works fine for me (see the screencast video).

/**
* Change the color model and breakdown
* of spot colors in active document.
* @discussion https://community.adobe.com/t5/illustrator-discussions/stroke-to-new-layer/m-p/13725064
*/
(function () {
var breakdowns = {
CutContour: [255, 0, 0],
Big: [0, 255, 0],
Pnimi: [0, 0, 255],
};
var doc = app.activeDocument,
counter = 0;
// get the colors
for (var swatchName in breakdowns) {
try {
setSwatchSpotColor(doc.swatches.getByName(swatchName), breakdowns[swatchName]);
counter++;
} catch (error) {}
}
alert("Changed " + counter + " spot colors.");
// make a new layer to hold the items
layer = app.activeDocument.layers.add();
layer.name = "MOVED HERE";
// iterate over all path items and check if their stroke, if it matches
// any of the items in 'breakdowns' then move that path to the new layer
var item,
counter = 0;
for (var i = 0; i < doc.pathItems.length; i++) {
item = doc.pathItems[i];
if (
item.stroked &&
item.strokeColor.typename == "SpotColor" &&
breakdowns.hasOwnProperty(item.strokeColor.spot.name)
) {
item.move(layer, ElementPlacement.PLACEATEND);
counter++;
}
}
alert("Moved " + counter + " path items.");
// remove all swatches not defined in breakdowns object
counter = 0;
for (var i = doc.swatches.length - 1; i >= 0; i--) {
doc.swatches[i].remove();
counter++;
}
alert("Deleted " + counter + " swatches.");
// remove any left over swatch groups
var swatchGroup,
counter = 0;
for (var i = doc.swatchGroups.length - 1; i >= 0; i--) {
swatchGroup = doc.swatchGroups[i];
if (swatchGroup.getAllSwatches().length == 0) {
swatchGroup.remove();
counter++;
}
}
alert("Deleted " + counter + " empty swatch groups.");
})();
/**
* Sets the color of a spot color swatch
* based on the breakdown supplied.
* @7111211 m1b
* @version 2023-04-17
* @9397041 {Swatch} swatch - an Illustrator Swatch.
* @9397041 {Array<Number>} breakdown - the color breakdown [R, G, B] or [C, M, Y, K].
*/
function setSwatchSpotColor(swatch, breakdown) {
if (swatch.color.typename !== "SpotColor") return;
var newColor;
if (breakdown.length === 3) {
newColor = new RGBColor();
newColor.red = breakdown[0];
newColor.green = breakdown[1];
newColor.blue = breakdown[2];
} else if (breakdown.length === 4) {
newColor = new CMYKColor();
newColor.cyan = breakdown[0];
newColor.magenta = breakdown[1];
newColor.yellow = breakdown[2];
newColor.black = breakdown[3];
}
swatch.color.spot.color = newColor;
}