Copy link to clipboard
Copied
Hello
I have objects with a certain spot color, I need to move them to a new layer
)which does not exist.)
//author: William Dowling
//adobe forum username: Disposition_Dev
//email: illustrator.dev.pro@gmail.com
//linkedin: https://www.linkedin.com/in/william-dowling-4537449a/
//Adobe Discussion Forum Post about this function: https://community.adobe.com/t5/illustrator-discussions/moving-objects-with-spot-color-to-a-new-layer-javascript/td-p/13584610
//*******//
//Did you find this useful? Would you like to buy me a cup of coffee to say thanks?
//paypal.me/illustratordev
//<3
//*******//
//Move
...
How about changing this
doc.selection = null;
doc.defaultFillColor = mySpotSwatch.color;
doc.defaultStrokeColor = mySpotSwatch.color;
//get filled items matching the spot color
app.executeMenuCommand( "Find Fill Color menu item" );
for ( var s = 0; s < doc.selection.length; s++ )
{
doc.selection[ s ].moveToBeginning( myLayer );
}
//get stroked items matching the spot color
doc.selection = null;
app.executeMenuCommand( "Find Stroke Color menu i
...
Copy link to clipboard
Copied
//author: William Dowling
//adobe forum username: Disposition_Dev
//email: illustrator.dev.pro@gmail.com
//linkedin: https://www.linkedin.com/in/william-dowling-4537449a/
//Adobe Discussion Forum Post about this function: https://community.adobe.com/t5/illustrator-discussions/moving-objects-with-spot-color-to-a-new-layer-javascript/td-p/13584610
//*******//
//Did you find this useful? Would you like to buy me a cup of coffee to say thanks?
//paypal.me/illustratordev
//<3
//*******//
//Move Spot Color Items to New Layer
//
// pass the name of the spot color as a string
// and this script will move all objects with that spot color to a new layer
//arguments
//
//mySpotColorName : string. The name of the spot color you want to move to a new layer
//Dependencies
//
//none
function moveSpotColorItemsToNewLayer ( mySpotColorName )
{
var doc = app.activeDocument;
var mySpotSwatch;
for ( var i = 0; i < doc.swatches.length && !mySpotSwatch; i++ )
{
if ( doc.swatches[ i ].name.match( mySpotColorName ) )
{
mySpotSwatch = doc.swatches[ i ];
}
}
if ( !mySpotSwatch )
{
alert( "Spot color \"" + mySpotColorName + "\" not found" );
return;
}
var myLayer = doc.layers.add();
myLayer.name = mySpotColorName + " Objects";
doc.selection = null;
doc.defaultFillColor = mySpotSwatch.color;
//get filled items matching the spot color
app.executeMenuCommand( "Find Fill Color menu item" );
for ( var s = 0; s < doc.selection.length; s++ )
{
doc.selection[ s ].moveToBeginning( myLayer );
}
doc.selection = null;
app.redraw();
doc.defaultStrokeColor = mySpotSwatch.color;
//get stroked items matching the spot color
app.executeMenuCommand( "Find Stroke Color menu item" );
for ( var s = 0; s < doc.selection.length; s++ )
{
doc.selection[ s ].moveToBeginning( myLayer );
}
doc.selection = null;
alert( "All Done." );
}
moveSpotColorItemsToNewLayer( "mySpotColorName" );
Copy link to clipboard
Copied
Hello
It doesn't work well
I opened a new document with spot color:
mySpotColorName
There is an error message. Situation.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Apologies. I made a typo in the code. I've edited my previous reply and tested it on your example file with success.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
From this post, yes. But I don't know if we know each other previously.
Are you waiting for something from me? I just edited my other post to fix the typo. Is that updated code not working for you?
Copy link to clipboard
Copied
Hey William, this isn't working for me.
The reason seems to be that the stroke is the same color, even though the fills are different...
I'm not sure how to isolate the selection of the stroke so it doesn't pick up the stroke from the fill selection.
Copy link to clipboard
Copied
How about changing this
doc.selection = null;
doc.defaultFillColor = mySpotSwatch.color;
doc.defaultStrokeColor = mySpotSwatch.color;
//get filled items matching the spot color
app.executeMenuCommand( "Find Fill Color menu item" );
for ( var s = 0; s < doc.selection.length; s++ )
{
doc.selection[ s ].moveToBeginning( myLayer );
}
//get stroked items matching the spot color
doc.selection = null;
app.executeMenuCommand( "Find Stroke Color menu item" );
for ( var s = 0; s < doc.selection.length; s++ )
{
doc.selection[ s ].moveToBeginning( myLayer );
}
doc.selection = null;
to this
doc.selection = null;
doc.defaultFillColor = mySpotSwatch.color;
app.executeMenuCommand( "Find Fill Color menu item" );
doc.defaultStrokeColor = mySpotSwatch.color;
app.executeMenuCommand( "Find Stroke Color menu item" );
for ( var s = 0; s < doc.selection.length; s++ ) {
doc.selection[ s ].moveToEnd( myLayer );
}
Copy link to clipboard
Copied
Thanks Femke, that certainly separates the fills, but now the stroke is the same color as the fill, mySpotColorName. I guess that's the work around to separate the strokes from one another.
I'm not asking for a solution, I'm not the OP, I just noticed on William's original that it didn't (necessarily) work.
Copy link to clipboard
Copied
I'm not really sure what you meant in your first reply.
"I'm not sure how to isolate the selection of the stroke so it doesn't pick up the stroke from the fill selection."
Are you saying that the stroke of the filled items changes? like they either start with no stroke, or a different stroke and then the mySpotSwatch gets applied to the stroke?
I didn't see that on my end, but i also didn't test extensively. It probably needs an app.redraw() in between the stroke/fill processing to ensure the selection is what it should be.. Sometimes executeMenuCommands don't update the dom right away so the next loop still includes the previously selected items.
Copy link to clipboard
Copied
this solution will change the stroke of some items in the document. because it selects the filled items and then sets the default document stroke color, it will change the stroke of all selected items. I processed them separately to avoid changing any of the artwork that's being moved.