Copy link to clipboard
Copied
That may or may not have made sense in terms of a title, but let me explain. I am working on a project that has a component of which that deals with HEX color. Let's say I have 100 images. The vector I am using has only 2 layers. One of those layers I need to change the color to a random HEX color, and put it on a gradient background. I initially thought maybe a photoshop action but it has an issue with the random nature of the color. I also search and found scripts that will randomly change the color of multiple pieces of an image (like dots, shapes etc,) but nothing that comes close to what I am trying to accomplish. There is a possibility I am thinking beyond the capabilities of the software at this point, but I figured I would try one last avenue to see if anyone had any other ideas I haven't googled yet. My apoligies if I am not asking this question the right way. Basically I need a script of workflow that completes this for over 100 images. Thank you.
There is a beautiful script called "Randomus", provided by Alexander Ladygin. Among other things it may do exactly what you are looking for.
See: Randomus
Copy link to clipboard
Copied
can you share a sample file?
Copy link to clipboard
Copied
Each on of these images has two layers. The mouth/eyes (1), and the body (2). Instead of going through hundreds of them I am looking of way to randomly generate a unique HEX color for the entire batch. Just changing the body (2) to a random HEX.
Copy link to clipboard
Copied
It sounds doable, but there are ambiguities. (1) You presumably mean vector graphics, not "images". Are these 100 vector graphics in one file or 100 files? (2) You presumably mean path, not "layer". To clarify this, and to see the anatomy of your vector graphic, can you show your fully expanded Layers panel (this is the reason a sample file was ask for)? And (3) about colors: Do you want the script to select a random color form a pre-defined swatch? Or do you want the script to generate a completely random RGB color?
Copy link to clipboard
Copied
exactly, that's why it's always important to include sample ai files,
Copy link to clipboard
Copied
My apoligies. I do mean vector graphics, not "images," and I am referring to paths not "layers." I'm not as familar with Illustrator as you and I appreciate your patience. The layer term came from the fact that it literally says layers, but I stand corrected. When you asked for a sample file, I was unaware that it was and .ai that was needed but I understand now. Thank you. As to your last two questions, either selecting from a predefined swatch, or some kind of script would be amazing, and considering I am learning all kinds of lessons on here today, it sounds like you may have an idea. I included the file as well as a screenshot of layer's panel. Seems like I'm getting closer to knowing what it is I am actually asking. I appreciate your knowledge.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Unfortunately, I can't open your eps file, because I'm using an older version of Illustrator. But your screenshot is helpful. Your Layers panel has one layer called "Layer 1", in which there are two groups. Can you expand these groups and any items within them (by clicking the right arrow heads to the left of the items, so that no right arrow heads are left)?
Copy link to clipboard
Copied
Thank you for looking at my post. I am going to try posting the .ai file as well. As I am not familiar with Illustrator as much as Photoshop if this upload fails maybe you can point me to why. The file I am uploading is from my library says
Unfortunately, I can't open your eps file, because I'm using an older version of Illustrator. But your screenshot is helpful. Your Layers panel has one layer called "Layer 1", in which there are two groups. Can you expand these groups and any items within them (by clicking the right arrow heads to the left of the items, so that no right arrow heads are left)?
By @femkeblanco
. Ill try to do that anyway. I have included the layers expanded in the screenshot provided. I appreciate your help.
Copy link to clipboard
Copied
Sorry it says this instead of quoting your post lol
Correct the highlighted errors and try again.
The attachment's ad310b_58412cbf-7d93-4b50-82e3-5b7f1ead910b.ai content type (application/postscript) does not match its file extension and has been removed.
Copy link to clipboard
Copied
There is a beautiful script called "Randomus", provided by Alexander Ladygin. Among other things it may do exactly what you are looking for.
See: Randomus
Copy link to clipboard
Copied
Thank you I'll have to check that out. I saw it in my initial research but assumed it was for something other than what it is I am trying to do. Reading the docs there may be a way to configure it to my liking. Appreciate the resource my friend
Copy link to clipboard
Copied
You may want to trust me. Alexander's script will do what you are going to do.
You may have to experiment a bit with it.
Copy link to clipboard
Copied
Do it as we speak my friend. Hopefully I'm not as dense as I think I am. Really appreciate the link
Copy link to clipboard
Copied
This is amazing my friend. It is exactly what I was looking for. You are right! It's not that I didn't "trust" you, it was a simple matter of whether I could use the tools you provided. Interface is easy and simple to use, and the instructions on Github were easy to follow. Since you seem to be the guy on here, the overall reason I wanted this type of script was to build assets quickly. Now that I have the random color generator of my dreams, do you know of a way to export quickly using the hex color as the filename? Like if I wanted to export to .png but have it automatically name the file the hexcolor. Either exporting it to a folder or my library. Thank you again.
Copy link to clipboard
Copied
Well, that may be possible by creating another script.
I don't know if there is already one that can do it. Sorry.
Copy link to clipboard
Copied
Is that what you want?
Copy link to clipboard
Copied
That is exactly what I need. As of now I'm doing it by just painstaking labor. How do I learn this export.js? Is there a git for it?
Copy link to clipboard
Copied
https://gist.github.com/creold/44b75fead3602545510ffc22c270cbbd
/*
Separate export of selected paths or text to PNG with HEX color name
Author: Sergey Osokin, email: hi@sergosokin.ru
Check other author's scripts: https://github.com/creold
https://community.adobe.com/t5/illustrator-discussions/workflow-is-there-a-faster-way-to-change-the-color-of-a-layer-on-multiple-images-randomly/td-p/12872250
*/
//@target illustrator
app.preferences.setBooleanPreference('ShowExternalJSXWarning', false); // Fix drag and drop a .jsx file
// Main function
function main() {
if (!documents.length) return;
if (selection.length == 0 || selection.typename == 'TextRange') return;
var doc = activeDocument,
docSel = selection,
docFolder = Folder(doc.path).exists ? doc.path : Folder.desktop,
isReplaceFile = false; // Replace when names match
var exportOptions = new ExportOptionsPNG24();
exportOptions.antiAliasing = true;
exportOptions.transparency = true;
selection = null;
for (var i = 0, len = docSel.length; i < len; i++) {
exportAsPNG(docSel[i], docFolder, isReplaceFile, exportOptions);
}
}
// Export single item
function exportAsPNG(item, folder, isReplace, exportOptions) {
var rgb = {};
if (item.typename == 'CompoundPathItem' && item.pathItems) {
rgb = item.pathItems[0].fillColor;
} else if (item.typename == 'PathItem') {
rgb = item.fillColor;
} else if (item.typename == 'TextFrame') {
rgb = item.textRange.fillColor;
} else {
return;
}
if (rgb == undefined || rgb.typename !== 'RGBColor') return;
var hex = rgb2Hex(rgb.red, rgb.green, rgb.blue).toUpperCase(),
fileName = folder + '/' + hex,
file = File(fileName + '.png');
if (file.exists && !isReplace) {
var counter = 2;
do {
var newName = fileName + '_' + counter++;
file = File(newName + '.png');
} while (file.exists)
}
item.selected = true;
app.activeDocument.exportSelectionAsPNG(file, exportOptions);
selection = null;
}
// https://stackoverflow.com/questions/5623838/rgb-to-hex-and-hex-to-rgb
function rgb2Hex(r, g, b) {
return componentToHex(r) + componentToHex(g) + componentToHex(b);
}
function componentToHex(c) {
var hex = c.toString(16);
return hex.length == 1 ? '0' + hex : hex;
}
// Run script
try {
main();
} catch (e) {}
Copy link to clipboard
Copied
Let's give it a shot. I'll let you know how it goes. Thank you for all your help
Copy link to clipboard
Copied
Did not come back soon enough to say you have changed my life with this
Copy link to clipboard
Copied
I'm glad to hear that. Batch processes should make life better for designers.