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

is it possible to move each color on its own layer?

Participant ,
Dec 30, 2019 Dec 30, 2019

Copy link to clipboard

Copied

hi all

I'm in search of a way (or script) that can seperate each object with the same fill color on its own layer.

The aim/scope is so that when I trace an image and limit the amount of colors I would like to have them in seperate layers for later processing in another app. Right now im doing it manually and its ok, but since I have plenty of artworks to do this manner it would help to have some automation/script/easier method of doing it.

 

thnks in advance

 

TOPICS
Draw and design , Scripting , Third party plugins , Tools

Views

5.8K

Translate

Translate

Report

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

correct answers 1 Correct answer

Community Expert , Jan 04, 2020 Jan 04, 2020

You can find many Compound Patths after Image Trace.

Just check the Document Info Panel on Objects.

Votes

Translate

Translate
Adobe
Enthusiast ,
Dec 30, 2019 Dec 30, 2019

Copy link to clipboard

Copied

yes it is possible. but it will also depend on your artworks appearance layers. scripting has no way of cycling through appearance fills, and strokes to determine what is the top fill. it will also get tricky to determine the fill color of a group vs the fill color of each group member if you have any. 

Votes

Translate

Translate

Report

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 ,
Dec 30, 2019 Dec 30, 2019

Copy link to clipboard

Copied

When you say you are "doing it manually", you don't mean one object at a time--do you? Are you using the Select>Same>Fill Color menu? If you combine that with the Collect in New Layer menu option, you should be able to make an Action.

David Creamer: Community Expert (ACI and ACE 1995-2023)

Votes

Translate

Translate

Report

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
Participant ,
Dec 30, 2019 Dec 30, 2019

Copy link to clipboard

Copied

yes I use the same fill color  option, then when all that particular color is highlighted i just drag it to a new layer. Unfortunately everytime I tried the collect to new layer it doesnt work since it just make a duplicate of the whole layer into a sub layer (despite only 1 color is selected)

 

Votes

Translate

Translate

Report

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 ,
Dec 30, 2019 Dec 30, 2019

Copy link to clipboard

Copied

Actions will get you a long way.

You can start by opening an image in Illustrator, this has the advantage that the Swatches panel is empty.

Unfortunately Image Trace cannot be recorded with a preset, so you need to select one manually.

The rest can be semi automated:

An action to expand the Image Trace and adding the colors to the Swatches Panel

When a swatch is selected, an action can select the same fill colors, cut the selection, create a new Layer (recorded by clicking the New Layer Icon with the Cmd (or Ctrl for Win) key depressed to avoid recording naming the layer) and paste the result. You need to play this action for every color.

Actions.png

Votes

Translate

Translate

Report

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
Participant ,
Dec 30, 2019 Dec 30, 2019

Copy link to clipboard

Copied

never thought about using this method and record it into an action. It's not far off from my manual method, however this might help speed up the things a bit more. Will have to play around with it to see how well will I manage. I'll get back to you if you dont mind if i get stuck

thnks

Votes

Translate

Translate

Report

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 ,
Dec 31, 2019 Dec 31, 2019

Copy link to clipboard

Copied

Hope you will get it working. I forgot to mention one thing:

To make it work, turn OFF "Paste Remembers Layers" in the Layers Panel menu.

Votes

Translate

Translate

Report

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
LEGEND ,
Dec 31, 2019 Dec 31, 2019

Copy link to clipboard

Copied

We've worked around the inability of AI Actions to record an Image Trace preset by editing the "Vectorizing Presets" in Preferences so the "Default" preset has the settings we want to use in the Action. If this would help in your process I can document the process. 
But a script is the best route since any Tracing preset can be used. 

Votes

Translate

Translate

Report

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
Enthusiast ,
Jan 01, 2020 Jan 01, 2020

Copy link to clipboard

Copied

Hi, here's a simple script that will arrange all pathItems of a specific color into separate layers:

 

function deliminateColors() {
    var doc = app.activeDocument, items = [];
    for (var i = doc.pathItems.length - 1; i >= 0; i--)
        doc.pathItems[i].filled ? items.push(doc.pathItems[i]) : null;
    items.forEach(function (item) {
        checkForLayer(rgbToHex(item.fillColor)) ? addToLayer(item) : createLayer(item);
    });
}
function checkForLayer(name) {
    var doc = app.activeDocument, found = false;
    for (var i = 0; i < doc.layers.length; i++)
        if (new RegExp("^" + name + "$").test(doc.layers[i].name))
            found = true;
    return found;
}
function createLayer(item) {
    var layer = app.activeDocument.layers.add();
    layer.name = rgbToHex(item.fillColor);
    layer.color = item.fillColor;
    addToLayer(item);
}
function addToLayer(item) {
    var layer = app.activeDocument.layers.getByName(rgbToHex(item.fillColor));
    item.move(layer, ElementPlacement.PLACEATEND);
}
function rgbToHex(color) {
    return "#" + [color.red, color.green, color.blue]
        .map(function (c) {
            c = c < 256 ? Math.abs(c).toString(16) : 0;
            return c.length < 2 ? "0" + c : c;
        }).join("");
}
Array.prototype.forEach = function (callback) {
    for (var i = 0; i < this.length; i++)
        callback(this[i], i, this);
};
Array.prototype.map = function (callback) {
    var mappedParam = [];
    for (var i = 0; i < this.length; i++)
        mappedParam.push(callback(this[i], i, this));
    return mappedParam;
};
deliminateColors();

 

Results in Layers panel on the left with a 16-color image trace for simplicity:

 

ice_screenshot_20200101-115616.png

 

Since you're using Image Trace and didn't give too much detail, I assumed you only wanted fills to be checked, item names intact, layer names to be the specified color in hexadecimal form, the layer label to be equal to this color (though this would make selection hard, comment out the layer.color line in createLayer() to remove), and didn't touch the original layers just in case there's more to the document than these items.

Votes

Translate

Translate

Report

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 ,
Jan 02, 2020 Jan 02, 2020

Copy link to clipboard

Copied

I somehow do not get the script working, it gives the following error:

Screenshot 2020-01-02 at 14.08.35.png

Votes

Translate

Translate

Report

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 ,
Jan 02, 2020 Jan 02, 2020

Copy link to clipboard

Copied

I got that error too.

David Creamer: Community Expert (ACI and ACE 1995-2023)

Votes

Translate

Translate

Report

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
Enthusiast ,
Jan 02, 2020 Jan 02, 2020

Copy link to clipboard

Copied

Looks like the prototype calls weren't being auto-executed in standalone files. Fixed by placing the function invocation at the bottom of the script and updated the original post, tested it outside my IDE as well. Should work now.

Votes

Translate

Translate

Report

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 ,
Jan 02, 2020 Jan 02, 2020

Copy link to clipboard

Copied

Inventsable--Thank you for your hard work. Did  you edit the script on the original post? 

David Creamer: Community Expert (ACI and ACE 1995-2023)

Votes

Translate

Translate

Report

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
Enthusiast ,
Jan 02, 2020 Jan 02, 2020

Copy link to clipboard

Copied

No worries. Yes I did, but it'd be nice to have someone else verify just in case I missed something again. Thanks!

Votes

Translate

Translate

Report

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 ,
Jan 02, 2020 Jan 02, 2020

Copy link to clipboard

Copied

No errors this time, but it seems the script changes the colors of some objects.

Script vs actions.png

Votes

Translate

Translate

Report

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
Enthusiast ,
Jan 02, 2020 Jan 02, 2020

Copy link to clipboard

Copied

Hi Ton, the script should never assign to PathItem.fillColor and only read  from it. Can you provide this file?

Votes

Translate

Translate

Report

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 ,
Jan 02, 2020 Jan 02, 2020

Copy link to clipboard

Copied

Votes

Translate

Translate

Report

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
Enthusiast ,
Jan 02, 2020 Jan 02, 2020

Copy link to clipboard

Copied

Hi Ton, the issue for this file is that the layers are created in the order which colors are detected, and there is no way to stack these 3 final layers in such a way that it completely preserves the all original path zIndex positions since overlaps exist within this sample. I may be wrong and can try flipping the stacking order to place objects at the bottom as they move to the layer, but I assume this is the problem. For example, in the script output when you rearrange the layer order:

 

ice_screenshot_20200102-164905.png

 

As you can see, nothing was actually removed or recolored but rather the stacking order was changed since the request was to put them in separate layers and layers must exist below or above one another. If a setting for Image Trace which had no overlap were used this would not be a problem, and I could solve this in a few different ways but it wasn't technically in scope of the original question so I didn't know that I had to, also without knowing what settings OP is using or anything about their desired output I'd only be making further assumptions that might not be what they'd intended.

 

If it's needed I can add it in

Votes

Translate

Translate

Report

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
Enthusiast ,
Jan 02, 2020 Jan 02, 2020

Copy link to clipboard

Copied

So just to clarify:

 

  • The script inevitably rearranges your artwork
  • In the event of overlaps, the color more recently found will always be placed on top
  • In most instances, Traces with larger color profiles will work better than lower, as seen in the 16 color capture below:

 

ice_screenshot_20200102-171733.png

 

In the above, the stacking order doesn't matter nearly as much so the inevitable rearranging tends to impact less because Curve Fitting for higher profiles seems to avoid overlapping (so when you toggle visibility of a color off, you don't see anything below except canvas/transparent) whereas 3 - 6 colors seem to prefer overlap. I did switch the color detection order in the original script and that produces the above result, which I think is 98% indistinguisable from the original and certainly pretty good.

 

But again, without knowing the actual requirements of the OP, it's not easy to create a script that has a perfect result.

Votes

Translate

Translate

Report

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
Enthusiast ,
Jan 02, 2020 Jan 02, 2020

Copy link to clipboard

Copied

It looks as if a single color is missing rather than it assigning new fills. Are these layers within layers or items which are not default PathItems? Is the Fill assigned to the object or group/layer Appearance?

Votes

Translate

Translate

Report

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 ,
Jan 03, 2020 Jan 03, 2020

Copy link to clipboard

Copied

As far as I can see the script removes all compound paths, resulting in flat areas where holes should be.

Votes

Translate

Translate

Report

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 ,
Jan 04, 2020 Jan 04, 2020

Copy link to clipboard

Copied

I did a simple testt, the script does not select and move compound paths, but selects and moves the individual paths that make the compound paths (and have the same color).

Before after.jpg

Votes

Translate

Translate

Report

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
Enthusiast ,
Jan 04, 2020 Jan 04, 2020

Copy link to clipboard

Copied

Does Image Trace ever produce CompoundPathItems? I thought it only produced
PathItems

Votes

Translate

Translate

Report

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 ,
Jan 04, 2020 Jan 04, 2020

Copy link to clipboard

Copied

You can find many Compound Patths after Image Trace.

Just check the Document Info Panel on Objects.

Votes

Translate

Translate

Report

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
Participant ,
Jan 03, 2020 Jan 03, 2020

Copy link to clipboard

Copied

sorry for delay in replying, so much input from you all i'm flattered 🙂 thanks!

i'm gonna read all replies and check the script, and will also give an example of my workload/flow to have an idea what I meant and what I was looking for. Will get back to you all later today since i'm currently at work.

 

thanks once again for now and will get back to you all shortly

Votes

Translate

Translate

Report

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