Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Script to select the Items by color and move to the respective layer

Explorer ,
Apr 23, 2022 Apr 23, 2022

Hello All,

I was trying to write the script to select the Items (GroupItems, CompoundPathItems, text, and PathItems) based on the color  in a particular layer and also to move the selected items to the defiened layer. But I am not unable to figure out the script, i am not getting the exact concept to do this.

 

For Example:

1. I have a document "Sample.eps", in that there are two layers namely "FPO" and "Artwork". 

2. Also only two spot colors are used in the document namely "PANTONE Black C" and "Keyline Blue".

3. Both text and path items are there in those two layers.

 

My aim is to move the "Keyline Blue" colored Items and Text from the Artwork layer to FPO Layer.

Also to move the "PANTONE Black C" colored Items and Text from the FPO layer to Artwork Layer.

 

I am attaching the sample file too.

 

This Activity, I need to do for multiple files repeatedly. Please help me to overcome this scenario.

 

 

TOPICS
Scripting
1.1K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Community Expert ,
Apr 23, 2022 Apr 23, 2022

we can write the script for you but it seems you want to learn how to write your own scripts.

 

please post your script, point out what you're struggling with and we will give you feedback, how's that?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 26, 2022 Apr 26, 2022

Apologize for not placing my drafted script. I forgot to add along with question. From next time onwards, I will place the whatever i have drafted.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 27, 2022 Apr 27, 2022
LATEST

yeah no problem, no need to apologize but it's appreciated.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 23, 2022 Apr 23, 2022

Hi,

Below is the simple version of your requirement, not efficient.

//Moving Keyline Blue to FPO
var swatch = app.activeDocument.swatches.getByName('Keyline Blue');
var temp = app.documents[0].pathItems.rectangle(10, 10, 150, 150);
temp.fillColor = swatch.color;
app.executeMenuCommand('Find Fill Color menu item');
temp.remove();
moveItems(app.selection, 'FPO');
app.executeMenuCommand('deselectall');
app.redraw();

//Moving PANTONE Black C to Artwork
var swatch = app.activeDocument.swatches.getByName('PANTONE Black C');
var temp = app.documents[0].pathItems.rectangle(10, 10, 150, 150);
temp.fillColor = swatch.color;
app.executeMenuCommand('Find Fill Color menu item');
temp.remove();
moveItems(app.selection, 'Artwork');
app.executeMenuCommand('deselectall');
app.redraw();


function moveItems(selectedItems, layerName) {
    var doc = app.activeDocument;
    var _layer = doc.layers[layerName];
    for (var i = selectedItems.length - 1; i >= 0; i--) {
        if(selectedItems[i].layer != _layer)
            selectedItems[i].move(_layer, ElementPlacement.PLACEATEND);
        selectedItems[i].selected = false;
    }
}

 

I am sure you need to modify it based on your other requirement, but it will give you a start. Also, you can read it the documentation

https://www.indesignjs.de/extendscriptAPI/illustrator-latest/#Document.html#d1e52093__d1e53157

Best regards
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 26, 2022 Apr 26, 2022

Thank you so much @Charu Rajput , I have modified based on my needs. Thanks for the concept.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines