Color conversion script?

I am looking for a way to print the CMYK, RGB, HEX easily, in the text, and possibly another representation of certain colors, I thought I'd write a quick script... easy, right? Apparently not.

Although I have never used, it seems that Photoshop has the 'SolidColor' object, which has properties for 'cmyk', 'rgb', 'gray' etc... exactly what I need, except I want to do that in Illustrator. Illustrator has the "CMYKColor', 'RGBColor" etc. objects with, from what I can tell, no way to convert any other color mode.

Then. am I missing something obvious? Or y at - it no way to easily get representations of different a color in artificial intelligence object color mode? I know that the conversion will be different according to the profiles of boards etc., but the UI color picker has the right values that already and, apparently, Photoshop can do it without problem so I'm hoping that I'm missing just something obvious!

I tried to change the "TypeName" of the Color object, I've seen suggested, but it made no difference (the docs say it is read only).

The only other options I can think is to create a new document in color mode I want to convert, to create a new color from the existing (which from reading the reference sounds like it will be auto-convertir it in this color mode) read the values of the new color and close the newly created document. But that seems to be a horrible workaround. Or, set up my own conversion function, which seems so horrible (since I thought it would be easy to write quick script!)

Any input would be appreciated!

Your code has been very useful Silly-V, convertSampleColor(), it was exactly what I was looking for! If you or anyone is interested, now is my script. Havn't tried a lot and it could probably be cleaned up a bit, but it should work (it does for me with CS6 on OS X).

It takes all your selected samples and print the CMYK, RGB and HEX (and name if it is a spot color) all these samples selected in a txt file. The txt file is saved with the same name and in the same folder as your Illustrator file. If your Illustrator file is unregistered, it records the txt file in your home directory.

// Color Modes To Text
// ===================

// Prints CMYK values, RGB values and HEX value of all selected swatches to a .txt file
// The .txt file is saved with the same file name and inc the same folder as the .ai file
// If the .ai file hasn't been saved, the .txt file is saved in the users home directory

main();
function main()
{
    var doc = app.activeDocument;
    var selectedSwatches = doc.swatches.getSelected();

    if (selectedSwatches.length > 0)
    {
        var text = "";

        for (var i = 0; i < selectedSwatches.length; i++)
        {
            var swatch = selectedSwatches[i]
            var color = swatch.color;

            // Spot
            if (color.typename == "SpotColor") {
                text += color.spot.name + "\n";
                color = color.spot.color;
            }

            // CMYK Source
            if (color.typename == "CMYKColor")
            {
                // CMYK Values
                text += "C=" + Math.round(color.cyan) + " M=" + Math.round(color.magenta) + " Y=" + Math.round(color.yellow) + " K=" + Math.round(color.black) + "\n";

                // RGB Values
                var rgb = convertColor("CMYK", "RGB", [Math.round(color.cyan), Math.round(color.magenta), Math.round(color.yellow), Math.round(color.black)]);
                text += "R=" + Math.floor(rgb[0]) + " G=" + Math.floor(rgb[1]) + " B=" + Math.floor(rgb[2]) + "\n";

                // HEX Values
                text += rgbToHex(Math.floor(rgb[0]), Math.floor(rgb[1]), Math.floor(rgb[2])) + "\n";
                text += "\n";
            }
            // RGB Source
            else if (color.typename == "RGBColor")
            {
                // CMYK Values
                var cmyk = convertColor("RGB", "CMYK", [Math.round(color.red), Math.round(color.green), Math.round(color.blue)]);
                text += "C=" + Math.round(cmyk[0]) + " M=" + Math.round(cmyk[1]) + " Y=" + Math.round(cmyk[2]) + " K=" + Math.round(cmyk[3]) + "\n";

                // RGB Values
                text += "R=" + Math.floor(color.red) + " G=" + Math.floor(color.green) + " B=" + Math.floor(color.blue) + "\n";

                // HEX Values
                text += rgbToHex(Math.floor(color.red), Math.floor(color.green), Math.floor(color.blue)) + "\n";
                text += "\n";
            }
        }
        saveTxt(text);
    }
    else {
        alert("No Swatches Selected.");
    }
}

function convertColor(src, dest, clrArr)
{
    return app.convertSampleColor(ImageColorSpace[src], clrArr, ImageColorSpace[dest], ColorConvertPurpose.defaultpurpose);
}

function componentToHex(c)
{
    var hex = c.toString(16);
    return hex.length == 1 ? "0" + hex : hex;
}

function rgbToHex(r, g, b)
{
    return "#" + componentToHex(r) + componentToHex(g) + componentToHex(b);
}

function saveTxt(txt)
{
    var name = app.activeDocument.name.replace(/\.[^\.]+$/, '');
    var path = (app.activeDocument.path != "") ? app.activeDocument.path : "~";

    var saveFile = new File(path + "/" + name + ".txt");

    if(saveFile.exists)
        saveFile.remove();

    saveFile.encoding = "UTF8";
    saveFile.open("e", "TEXT");
    saveFile.writeln(txt);
    saveFile.close();

    alert("Saved to File:\n" + saveFile.fullName)
}

Tags: Illustrator

Similar Questions

  • Export of the correct Hex colors via script

    Hi all

    I need to export the fillColor of a paragraph via script style.

    I can get the fillColor of the paragraph style property and can also convert CMYK Hex. However, I realize that color in InDesign values in some color space of the document uses.

    My question is, is there a native API to convert the values of color for a web safe color value? If this is not the case, how can I go on the correspondences between colors?

    In addition, I see that Adobe knows internally to convert it to a good hex color (attached screenshot - note the color property in the export marking side). If I can't use some native API, is there a way to access the text in this pane?

    Screen Shot 2014-12-15 at 7.25.20 PM.png

    Thank you all in advance!

    Win! It worked!

    Here is the complete solution-

    Assuming that the original color is stored in a variable named color :

    var color = passedInColor; //the original color that we wish to convert.
    
    // Create a temporary color instance that we'll use to extract updated colorValues.
    var scratchColor = workingDoc.colors.add({
                             model: color.model,
                             space: color.space,
                             colorValue: color.colorValue
                        });
    
    // Now, we force adobe's internal color conversion mechanism to trigger by changing the scratchColor's color space.
    scratchColor.space = ColorSpace.RGB;
    var updatedValues = scratchColor.colorValue; // Updated values now has the properly mapped and converted RGB values.
    // You may need to round off the R, G and B values in the updatedValues array.
    // And that's it!
    

    Why am I not surprised that she should be a hacky autour work? * sigh *. It was so so so frustrating to work on this platform! I hope adobe gets his act together!

  • Chaning color Illustrator script?

    Hello community! I have about 600 files that I need to change the colors of pale green/dark green to light blue/dark blue, and I need a script for this. Here are a few simple letters divided in two and everything I need is the upper part to be dark blue instead of dark green and the lower part to be light blue instead of the original light green. Is this possible? I use windows 10 as my operating system. Any help is very appreciated!

    Kind regards

    David.

    This code should you select a folder and then loop through all files with. EPS file extensions.
    Note that this script assumes that all colors are exactly the same two Greens as in this sample file you sent.

    You will need to replace the RGB values of the above colors in the marking lines.<- here"="" with="" the="" values="" for="" the="" new="" blue="">

    function ConvertColors() {
    
        /* REPLACE THESE RGB VALUES */
        var topColor = new RGBColor();
    
        topColor.red = 0;    // <- HERE
        topColor.green = 0;    // <- HERE
        topColor.blue = 255;   // <-HERE
    
        var bottomColor = new RGBColor();
    
        bottomColor.red = 255;   // <- HERE
        bottomColor.green = 0;   // <- HERE
        bottomColor.blue = 0;  // <- HERE
    
        /* ~~~~~~~~~~~~~~~~~~~ */
    
        // we'll just use the Red value of the top to identify which color we have
        var oldTopColor = 140;
    
        var dir = Folder.selectDialog("Where?");
        var files = dir.getFiles("*.eps");
    
        // loop through all the files in the selected directory
        for(var f = 0; f < files.length; f++){
            var doc = app.open(files[f]);
    
            // loop through all paths and change the colors based on current fill
            var paths = doc.pathItems;
            for( var i = 0, ii = paths.length; i < ii; i++ ) {
                var curPath = paths[i];
    
                // check the fill color to see if it has the same Red value as the old top color
                if( curPath.fillColor.red == oldTopColor ) {
                    curPath.fillColor = topColor;
                }
                // if not it must be the bottom color
                else {
                    curPath.fillColor = bottomColor;
                }
            }
    
            // close and save the changes
            doc.close(SaveOptions.SAVECHANGES);
        }
    }
    
    ConvertColors();
    

    I hope this helps!

  • How to remove colors custom Script UI control?

    Dear forum,

    I am writing a script for batch renaming links in InDesign.

    1.jpg

    If the user types the text edit field the new name which coincides with name of the original link (1st static text in the Group), the script gives a warning and he painted red.

    2.jpg

    3.jpg

    When the user solves the problem by making the new different name, the script he painted black.

    15-11-2015 20-30-37.jpg

    Here's where I got so far:

    g.et.onChange = function() {
        if (this.parent.children[0].text.replace(/\.[^\.]+$/, '') == this.text) {
            alert("\"" + this.text + "\" - the new name is the same as the old one! The file won't be renamed.", "Error", true);
            this.graphics.foregroundColor = this.graphics.newPen(this.graphics.PenType.SOLID_COLOR, [1, 0, 0], 1);
        }
        else {
            if (this.graphics.foregroundColor != undefined) {
                $.writeln("Names are different: change the name from red to black.");                        
                this.graphics.foregroundColor = this.graphics.newPen(this.graphics.PenType.SOLID_COLOR, [0, 0, 0], 1);
            }
        }
    }
    

    "g" is the text in a group.

    I wonder, is there a way to reset the color to the default text instead of repainting it?

    Currently, it checks if foregroundColor of graph is not undefined - which is painted with "newPen" - and if it is true, he painted black. But I guess it is a clumsy workaround and there should be a good way to do this.

    Kind regards

    Kasyan

    Hi Kasyan

    Pre CC could set the color to null, CC, this causes an accident.

    PS there are other options (color theme), but not on ID so paint is the only option I know.

    The challenge is dealing with default colors that depend on the setting. To change the text in the foreground is always black background colors you can either take the approach here Re: Re: Re: Re: ScriptUI: element of change to the default color

    Or a longer but more effective approach would be to go pass 100 values possible topic and get the associated rgb values.

    Probably not interesting put in a lot of effort as the way things are going THAT SUI will not support editing text in a few years.

    Concerning

    Trevor

  • HTML in PDF format ready to print with the CMYK color conversion

    How can I convert a webpage (html) as a PDF ready to print, including a RGB to CMYK conversion?

    I use a free trial of Acrobat DC. What I tried, is to use the browser button to convert HTML to PDF. I then open the document and go to the menu "Print Production. I expected to find the option "Convert colors", but he's not here. Help documentation indicates that this option is available only if you export your PDF file to a device "high-end". What is a high-end device? I use my laptop.

    (1) under the Production of printing tools, in the right pane, you will find the convert colors tool. That's what you're looking for. Its availability has nothing to do with what type of device you send the PDF file.

    (2) that said, converting the PDF to CMYK color space is not necessarily required to print. You certainly can print an RGB and/or the PDF to grayscale for a local or network PostScript laser printer, for example. What makes you think that you absolutely need CMYK for printing any other type? Each RIP/DFE these days can directly manipulate the RGB content.

    -Dov

  • Model by unwanted color change script

    I defined a model I intend using as a filling. After that I selected scripted brick and model of the pop box filling up I noticed that it is by changing the colors of my boss. I put the cursor of random color to 0 but the colors of my original pattern are different.

    I don't want my pattern color to change. Is this possible?

    I thought about it.

    If your color RGB mode the colors remain the same. Is it your CMYK color mode as it was for me, the colors change.

    You must change it back between RGB and CMYK

  • Menu color by Script

    Hi Experts,

    I'm trying to create a Menu ID that contains submenus, and I want to apply the color for this menu. It can be done manually by Edit-> Menus...-> by selecting the menu, next to this menu, we can change the color, is to enter into the menu. But I did not have to do with Automation by using google Javascript.I a lot to achieve. But I can not find, even in this forum too. That's why I ask this question to the expert ID. And I add the menu, have submenus (view > symbol,) I can able to add colors manually. Other menu items that does not submenus, I can't able to apply colors manually too... You can guide me expert!

    I tried the codes below. But I can not find the color property.

    var menuName = app.menuActions.itemByID (6146);

    var x = NomMenu;

    Alert (x.Properties);

    var y = x.properties;

    Alert (y.toSource ());

    Output:

    error.png

    Thank you and best regards,

    Velprakash.

    I don't think it's available via the script. Submit a feature request...

  • color fusion scripts

    I need to change the RGB values (imported from the word) of specific CMYK values in Indesign (this isn't a straight swop) so I need a script or a similar plug-in that allows me the contribution of color to CMYK values, so they change automatically... the doc I work on is huge and im importing from a file word several times so I need to save time!

    Can someone help me?

    Thank you!

    Hi baby.

    Please try the JS code below.

    var myIDOc = app.activeDocument;
    var mySwatch = myIDOc.swatches;
    for (j=mySwatch.length-1; j>=0; j--){
        try{
             if(mySwatch[j].space ==ColorSpace.RGB){
                 if(mySwatch[j].name=="Word_R122_G75_B153"){
                    mySwatch[j].remove("C=48 M=72 Y=0 K=0");
                    }
                else if(mySwatch[j].name=="Word_R255_G0_B255"){
                    mySwatch[j].remove("C=0 M=100 Y=0 K=0");
                    }
                else if(mySwatch[j].name=="Word_R0_G0_B255"){
                    mySwatch[j].remove("C=100 M=0 Y=0 K=0");
                    }
                else if(mySwatch[j].name=="Word_R0_G0_B0"){
                    mySwatch[j].remove("Black");
                    }
                else if(mySwatch[j].name=="Word_R234_G229_B255"){
                    mySwatch[j].remove("C=8 M=10 Y=0 K=0");
                    }
                 }
             }catch(e){}
         }
    

    THX,

    csm_phil

  • Spot color to process color conversion

    I have a book that my boss is eager to print. This book is filled with RGB / tones. I discovered that if I go into the "ink Manager" I can check the box "All Spots to process", but the weird thing is after I check in my Swatches Panel and discover that nothing has been converted. What is happening with this? I also found a script handy to convert RGB to CMYK colours, but I still have to find a script to convert all the spot to treat the colors in the swatches Panel. Anyone know where I can get a script for this?

    You don't want to do that, you just think you do. Redining stains as process means they will be redefined again if you need to print as spot. "Effectively" ink Manager using the redfinition fact and if you check the box use Lab Valus that it will convert even at better mixtures for any CMYK profile choose you for the output, increasing the chances of a good game (given that most of the tasks do not convert to CMYK will). The built-in CMYK values are for some unknown profile that most likely is not the same as the one you will use.

  • Calc the MDX script conversion script

    Hello

    We converted our cube BSO to ASO. so, we are now certain of our calc conversion MDX script.

    SO I'll try the figute what can I use in MDX to FIX and DIM CALC commands in Calc script?

    We use the EMP 11.1.2.

    Thank you

    You're not really converting them. There is not a procedure calc to ASO (Yes Cameron, I know that there but for the point of the question, that's irrevelent). As ASO cubes dynamically calculate the upper levels, there is no need of a Calc Dim statement. Some formaulas to work only on subsets of data, consider using a Case statement or an IIF statement. I find the case easier to read, but that's just me.

  • Color select Script needs refining

    Hello

    I've been running this simple script (created by an end PS scripter) in action:

    #target Photoshop

    main() {} function

    if(!documents.) Length) return;

    app.activeDocument.colorSamplers.removeAll ();

    var X = activeDocument.width.as('px')/2;

    var sample = activeDocument.colorSamplers.add ([new UnitValue (X, 'px'), new UnitValue (1, 'px')]);

    app.backgroundColor = sample.color;

    app.activeDocument.colorSamplers.removeAll ();

    }

    main();

    It selects the top center pixel color, sample, for the bottom point. Now I need to select a 5 x 5 moy. Second, is there a way to hide the INFORMATION pane, which opens by running the script? This appears not be called from an action, of course, and I'm not script.

    Thanks for any help.

    This should make an average...

    #target Photoshop
    function main(){
    if(!documents.length) return;
    var startRulerUnits = app.preferences.rulerUnits;
    app.preferences.rulerUnits = Units.PIXELS;
    try{
    app.activeDocument.colorSamplers.removeAll();
    var X = activeDocument.width/2;
    var LB=[];
    LB[0] = X.value;
    LB[1] = 1;
    LB[2] = X.value +5;
    LB[3] = 6;
    var tmpColour = new SolidColor();
    var savedState = activeDocument.activeHistoryState;
    activeDocument.selection.select([[LB[0],LB[1]], [LB[2],LB[1]], [LB[2],LB[3]], [LB[0], LB[3]]], SelectionType.REPLACE, 0, false);
    activeDocument.activeLayer.applyAverage();
    var sample = activeDocument.colorSamplers.add( [ new UnitValue( X+1, 'px' ), new UnitValue( 2, 'px' ) ] );
    tmpColour=sample.color;
    activeDocument.activeHistoryState = savedState;
    app.backgroundColor=tmpColour;
    app.preferences.rulerUnits = startRulerUnits;
    }catch(e){alert(e + " - " + e.line);}
    }
    main();
    

    I was not able to stop the information panel so I add to my open panels is not intrusive.

  • Access to the project color management script

    I know that you can access some color management settings in a script (i.e. bitsPerChannel), but I don't know about the others. In particular, can you get/set the workspace through a script? Thank you.

    N ° no color management controls are available in a script. bitsPerChannel and linearBlending are parameters of project that are associated with the color, but none are specific to color management.

    If you want to access the color management settings through scripts, please file a feature request.

  • Crazy color conversion prodblem

    I'm designing a package using PMS662. I have the color will be used in the process. PS, the conversion in the process I have values of C:100 M:94 Y:31 K:13. In InDesign and Illustrator but I have C:100 M:71 Y:0 values K:18. Now I know that I can simply define values in PS since it will be printed in process, so it's more a curiosity thing I think I should better understand.

    General information - color settings are synchronized between the applications and the color has been chosen among the same Pantone book named (Pantone Solid Coated) in all three applications. I've been doing this for a long time and I never notice any other color be so different between programs.

    Any idea would be appreciated. Thank you.

    MIke

    PS - I've attached a screenshot of PS implementation for reference.

    CS4 Color Settings.png

    InDesign and Illustrator use Pantone Solid to process default values.

    2 options:

    1. in Photoshop, use the solid to Process library when picking out the color.

    2. in InDesign, the swatch Panel, ink Manager, use the Lab values for spots. Illustrator, swatch, tones, use the lab values

    With option 1 you get Pantone Solid to process book numbers. With option 2 you use Lab book of numbers. These are converted to the CMYK destination. As long as the color settings and document profiles are synchronized, the lab CMYK conversion must match in three applications.

    With Illustrator and Photoshop, you should know that if the documents are RGB, that will change the result. Working with PANTONE to RGB can be somewhat difficult. Let me know if you have any questions.

  • Color Picker script or algorithm levels help

    First question is: did anyone know of a good explanation of the algorithm of levels as in how each setting affects a pixel in an image. If I change the middle point levels, how a specific pixel change in relation to this? I've experimented for hours and cannot understand one common factor other that there seems to be a relationship of binary type. The reason why I ask this question, it's because I'm trying to generate scripts that will balance the colors.

    If this method is not practical, I can go to the old method of old-fashioned trial and error, but this way also presents an obstacle for me. I made a point of color picker and the script can get the values from there exactly as it is in the Info Panel. If I put an above levels adjustment layer and adjust it, I now see the initial color and the adjusted value of color in the Info Panel, but I can't figure out how to get the value adjusted with a script. It always returns the original value. Does anyone know how to get the adjusted value?

    I hope I explained this right.

    What version of Photoshop are you using and what layer is active when you ran the script? I guess the depth of space and little color might also have.

    With CS4, 8 bit RGB I get different values, unless the adjustment layer was not visible when the script starts. Looks like maybe your adjustment layer was turned off when you ran the script becuse you see 226 (rounded) in the alert

  • ARW files are not open with ACR 9.1.1.  Color conversion/of DNG. You will need to upgrade to ACR 9.3.

    Hello world

    I bought a SONY camera that produces. ARW files.  They will not open in my Adobe Camera Raw 9.1.1.

    I use Photoshop CS6.

    I can't upgrade to Adobe Camera Raw 9.3 with CS6.

    I downloaded the DNG Converter and renders flat colors, dead.  I need bright colors.

    What must I do to get a version of Adobe Camera Raw 9.3?  I guess I have to upgrade Photoshop done

    this technically possible?

    Thanks for the help.

    Best always,

    James Whitlow Delano

    You can insert small images like screenshots directly into a forum post using the photo icon above where you type in the text:

    Dropbox is for sharing large files.

    Here are three screenshots...

    Native raw in C1:

    DNG in ACR:

    DNG in Mac preview:

    The only problem that you are experiencing is the overview of the DNG on the Mac is dull, but the images you create are ok?  I think that the DNG Converter is what creates the DNG preview, so I don't know how upgrading to a newer version ACR would change the DNG preview.

    What version of the converter DNG you used to create the the ARWs DNG?  You could try the last DNGC 9.6: http://www.adobe.com/downloads/updates/ so this isn't one you have used.

    Also made of Adobe and rendering of C1 would be different if it's not any problem.

Maybe you are looking for