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

Script or Action: Possible to do this complex task??

Explorer ,
Jan 25, 2023 Jan 25, 2023

Copy link to clipboard

Copied

Ok, I'll do my best to describe this

 

1. Greyscale photographic file is vectorized in Illustrator into 100 levels (1-100%)

2. I now need to assign 1 very specific/exact spot color name (NEON_X) to all these 100% levels of grey.

HOWEVER

3. I'm using the spot color's (NEON_X) opacity in 1% increments.    So, a greyscale value of 20, gets it's color changed into the (NEON_X) spot color, but now with a 20 opacity. 

greyscale value 50 -->(NEON_X) with 50 opacity

greyscale value 88--> (NEON_X) with 88 opacity

etc etc etc

 

repeat this process for each 100 level of grey, each getting this spot color (NEON_X) assigned to it, BUT with different levels of that spot color's opacity.

 

I need to automate a way for Illustrator to recognize each level of grey, then change to my chosen spot color with different opacities of that spot color.    I'm stumped on how one would approach this... I'm way more fluent in Actions, but I hit many snags and run errors.    Not sure if Illustrator Scripting would be the way to do this...

 

Any light one could shed on this, or point me into the appropriate direction to look into??

I think I still have my AdobeScript book (ugh it wasn't fun)    AdobeScript??

 

Currently trying to do this all on Illustrator CS6

 

many thanks in advance

Andre

TOPICS
Performance , Scripting , Tools

Views

485

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 2 Correct answers

Explorer , Jan 26, 2023 Jan 26, 2023

Here's the script that's been modified

 

/*
GrayscaleToOpacity.jsx for Adobe Illustrator
Description: Convert selection colors to Grayscale and set identical Opacity value
Date: February, 2019
Author: Sergey Osokin, email: hi@sergosokin.ru
Donate (optional):
If you find this script helpful, you can buy me a coffee
- via FanTalks https://fantalks.io/r/sergey
- via DonatePay https://new.donatepay.ru/en/@osokin
- via Donatty https://donatty.com/sergosokin
- via YooMoney https://yoomoney.ru/to/410011149615582
-

...

Votes

Translate

Translate
Guide , Jan 26, 2023 Jan 26, 2023

Try this instead.  If this doesn't work, then we need to see your fully-expanded layers panel. 

 

var doc = app.activeDocument;
var items = doc.pathItems;
for (var i = 0; i < items.length; i++) {
    if (items[i].fillColor.typename == "GrayColor") {
        var value = items[i].fillColor.gray;
        items[i].fillColor = doc.swatches["NEON_X"].color;
        items[i].opacity = value.toFixed(0);
    }
}

 

(Copy and paste the above in a jsx file.  You can create a txt file and change the extension to

...

Votes

Translate

Translate
Adobe
Community Expert ,
Jan 25, 2023 Jan 25, 2023

Copy link to clipboard

Copied

There is this script: GrayscaleToOpacity.jsx for Adobe Illustrator by Sergey Osokin
Description: Convert selection colors to Grayscale and set identical Opacity value

Looks like that is what you want.

https://github.com/creold/illustrator-scripts/blob/master/jsx/GrayscaleToOpacity.jsx

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
Explorer ,
Jan 25, 2023 Jan 25, 2023

Copy link to clipboard

Copied

HI Ton

 

Thanks for that link.   I'm looking at the script now... how would I then assign each of these opacities, the specific SpotColor name + opacity?

 

 

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
Guide ,
Jan 25, 2023 Jan 25, 2023

Copy link to clipboard

Copied

Add the following line

selArray[i].fillColor = app.activeDocument.swatches["NEON_X"].color;

between these two lines

    var value = selArray[i].fillColor.gray;
    
    selArray[i].opacity = value.toFixed(0);

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
Explorer ,
Jan 25, 2023 Jan 25, 2023

Copy link to clipboard

Copied

Thank you Femke

 

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
Explorer ,
Jan 25, 2023 Jan 25, 2023

Copy link to clipboard

Copied

Hmmm not sure how to proceed. 

 

I've altered the GrayscaleToOpacity.jsx with Femke's suggestion. 

I've installed the script

When I execute the script I"m not seeing any action 

 

Where in the script does it show that my greyscale file, will be altered to the appropriate spot color (swatch I've made, with specific name) ,and all the appropriate opacities/spot color assignment executes.

As I look at the script lines, I don't think it currently has the code to change each greyscale value, into the appropriate color swatch/spot color value.  


or am I missing something ?

 

thank you!!

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
Explorer ,
Jan 25, 2023 Jan 25, 2023

Copy link to clipboard

Copied

I guess I'll add the following. 

-Make a black to white gradient in Photoshop, posterize to 100 levels. 

-Bring this raster file into Illustrator

-Vectorize with 100 levels and expand.

 

NOW

choose a slice of the linear gradient (let's say 40% grey)

Assign a spot color from the swatches panel.  (Neon_X swatch)

Reduce the spot color to 40% opacity.  

 

Now do this for every single slice of 1 - 100%

 

This is what I'm trying to achieve with the script.  

Single spot color, with 1 - 100% opacities, based on the greyscale it was originally

 

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
Guide ,
Jan 25, 2023 Jan 25, 2023

Copy link to clipboard

Copied

Sergey Osokin's script requires you to select the targeted items before running it.  Did you do that? 

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 26, 2023 Jan 26, 2023

Copy link to clipboard

Copied

I tried this:

I made sure that the objects were grayscale: Edit > Edit Colors > Convert to Grayscale

Made sure that compound paths were released and ungrouped the selection.

Applied the script which converted grayscale to transparency.

Used Edit > Edit Colors > Recolor Artwork to convert it to the single color.

 

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 26, 2023 Jan 26, 2023

Copy link to clipboard

Copied

I think you may also just use an inverted opacity mask to get what you want.

 

Possibly done with an action.

 

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
Explorer ,
Jan 26, 2023 Jan 26, 2023

Copy link to clipboard

Copied

Femke,

yes, I've 'run' the script   File>Scripts>GrayscaletoOpacity

Should I execute another way?

 

Ton,

The file is greyscale.

No compound paths

Is Ungrouped

What version of Illustrator are you using? Can you see if CS6 works the same?

 

running the script doesn't seem to  do anything (I don't see errors, nothing changes in my file, etc)

Just... nothing happens...every slice of the gradient is still at 100% opacity

 

Running on CS6

 

Much appreciation this guys, just not sure why it's still not running/executing as you all describe. 

 

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
Explorer ,
Jan 26, 2023 Jan 26, 2023

Copy link to clipboard

Copied

Here's the script that's been modified

 

/*
GrayscaleToOpacity.jsx for Adobe Illustrator
Description: Convert selection colors to Grayscale and set identical Opacity value
Date: February, 2019
Author: Sergey Osokin, email: hi@sergosokin.ru
Donate (optional):
If you find this script helpful, you can buy me a coffee
- via FanTalks https://fantalks.io/r/sergey
- via DonatePay https://new.donatepay.ru/en/@osokin
- via Donatty https://donatty.com/sergosokin
- via YooMoney https://yoomoney.ru/to/410011149615582
- via QIWI https://qiwi.com/n/OSOKIN
NOTICE:
Tested with Adobe Illustrator CC 2018-2021 (Mac), 2021 (Win).
This script is provided "as is" without warranty of any kind.
Free to use, not for sale
Released under the MIT license
http://opensource.org/licenses/mit-license.php
Check my other scripts: https://github.com/creold
*/

//@target illustrator
app.preferences.setBooleanPreference('ShowExternalJSXWarning', false); // Fix drag and drop a .jsx file

// Main function
function main() {
if (!documents.length) return;

var doc = activeDocument,
selArray = [];

app.executeMenuCommand('Colors7');

getPaths(selection, selArray);

for (var i = 0, selLen = selArray.length; i < selLen; i++) {
var value = selArray[i].fillColor.gray;
selArray[i].fillColor = app.activeDocument.swatches["NEON_X"].color;
selArray[i].opacity = value.toFixed(0);
}

// Get paths from selection
function getPaths(item, arr) {
for (var i = 0, iLen = item.length; i < iLen; i++) {
var currItem = item[i];
try {
switch (currItem.typename) {
case 'GroupItem':
getPaths(currItem.pageItems, arr);
break;
case 'PathItem':
arr.push(currItem);
break;
case 'CompoundPathItem':
getPaths(currItem.pathItems, arr);
break;
default:
currItem.selected = false;
break;
}
} catch (e) {}
}
}
}

// Run script
try {
main();
} catch (e) {}

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 26, 2023 Jan 26, 2023

Copy link to clipboard

Copied

I cannot check CS6 (does not work anymore on my system).

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
Explorer ,
Jan 26, 2023 Jan 26, 2023

Copy link to clipboard

Copied

gradiant.jpg

Here's a screenshot of the gradient file.  All selected, ungrouped, no compound paths.  Run script. Nothing happens, each slice of density still at 100% opacity       

??????

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
Guide ,
Jan 26, 2023 Jan 26, 2023

Copy link to clipboard

Copied

Try this instead.  If this doesn't work, then we need to see your fully-expanded layers panel. 

 

var doc = app.activeDocument;
var items = doc.pathItems;
for (var i = 0; i < items.length; i++) {
    if (items[i].fillColor.typename == "GrayColor") {
        var value = items[i].fillColor.gray;
        items[i].fillColor = doc.swatches["NEON_X"].color;
        items[i].opacity = value.toFixed(0);
    }
}

 

(Copy and paste the above in a jsx file.  You can create a txt file and change the extension to jsx.  Then, while your document is open in Illustrator, go to File > Scripts > Other Script (Ctrl+F12). Find your script and open it.)

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
Explorer ,
Jan 26, 2023 Jan 26, 2023

Copy link to clipboard

Copied

Ok, created this new script (changed the swatch name from NEON_X, to RDG_WHITE)

ran the script

error.jpg

swatch.jpg

layers.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
Explorer ,
Jan 26, 2023 Jan 26, 2023

Copy link to clipboard

Copied

Found the problem

Swatch wasn't put in properly

swatch.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
Explorer ,
Jan 26, 2023 Jan 26, 2023

Copy link to clipboard

Copied

Everything runs perfect.  Thanks everyone!!!

 

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 26, 2023 Jan 26, 2023

Copy link to clipboard

Copied

Good to hear that you've got it working.

Kurt's suggestion of using the greyscale objects as an opacity mask for a colored object would have been an easy alternative.

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
Explorer ,
Jan 26, 2023 Jan 26, 2023

Copy link to clipboard

Copied

LATEST

I may try that too, thanks for sticking with this to the end

 

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