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

Cannot change fill color via scripted UI button?!

Explorer ,
Sep 19, 2014 Sep 19, 2014

I have simple scriptUI where is button that calls simple function. Function works properly if I call it normally out of button, but when I try to change color after button clicked, nothing happened.

I tried change colors with simple RGB way and now I tested out this CMYK version that found from forum. Nothing seems to be working via that button. Function itself lauches, but colors doesn't affect. Am I miss something about scriptUIs...

Please, anyone know where is the problem?

#target illustrator

//changeColor();

function changeColor() {

    var docRef = app.activeDocument;

    var  col;

    

    var col = new CMYKColor();

    col.cyan = 2;

    col.magenta = 3;

    col.yellow = 15;

    col.black = 0;

    

    // Create the new swatch using the above color

    var swatch = docRef.swatches.add();

    swatch.color = col;

    swatch.name = "col";

    

    // Apply the swatch to a new path item

    var pathRef = docRef.pathItems[0];

    pathRef.filled = true;

    pathRef.fillColor = swatch.color;

}

createGUI ();

function createGUI() {

    var win = new Window("palette", "Test", [150, 150, 460, 455]); // bounds = [left, top, right, bottom] 

    windowRef = win;

   

    win.increaseColorBtn = win.add("button", [110,50,200,150], "Change");

   

    win.increaseColorBtn.onClick = function () {

        changeColor ();       

    }; 

    // Create quit button and trigger for it

    win.quitBtn = win.add("button", [110,275,200,295], "Close");

    win.quitBtn.onClick = function() {  

        win.close();  

    }

    win.show(); 

}

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

correct answers 1 Correct answer

Valorous Hero , Sep 19, 2014 Sep 19, 2014

Sorry, but you will need to use the BridgeTalk object when working with palettes.  The way to make your current script work is to make the window type "dialog" and to put redraw(); into your changeColor(); function to see instant changes.  But you cannot access rest of the AI UI due to modal dialog.

Translate
Adobe
Valorous Hero ,
Sep 19, 2014 Sep 19, 2014

Sorry, but you will need to use the BridgeTalk object when working with palettes.  The way to make your current script work is to make the window type "dialog" and to put redraw(); into your changeColor(); function to see instant changes.  But you cannot access rest of the AI UI due to modal dialog.

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 ,
Sep 20, 2014 Sep 20, 2014

Hey thanks Silly-V! You save my day That was solution fot that at the moment. I guess there is no simple way to get access rest of AI UI with this method.

Uhm, about the colors. Is there any conversion function to change CMYK values to RGB values. Now If I try to change CMYK color while I'm in document RGB space I got a problem. So like in AI's own Color Picker window -> If I change CMYK or RGB values they updated to others values too automatically. How do this from script side, so I can just use/convert RGB values in CMYK document space?

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
Valorous Hero ,
Sep 20, 2014 Sep 20, 2014

Oh yes, most certainly there is a way to solve your problem:

I  used the below function in my own function which goes something like this:

    function convertAppColor(src,dest,clrArr){

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

    }


Where strings "RGB" and "CMYK" are passed in as variables src and dest, and clrArr is the array of the color values. It returns a new array which you use to construct a new appropriate color for your colorspace.

_____________________________________________________________________________________

Application.convertSampleColor (sourceColorSpace: ImageColorSpace , sourceColor: Array of number , destColorSpace: ImageColorSpace , colorConvertPurpose: ColorConvertPurpose , sourceHasAlpha: Boolean , destHasAlpha: Boolean ):Array of number

Adobe Illustrator CS5 Type Library

Converts a sample-component color from one color space to another.

sourceColorSpace: Data Type: ImageColorSpace

The source color space.

sourceColor: Data Type: Array of number

The color to convert, an array of color components. First location of the array should contain alpha if source-has-alpha is true.

destColorSpace: Data Type: ImageColorSpace

The destination color space.

colorConvertPurpose: Data Type: ColorConvertPurpose

The parameter which passes the purpose of conversion.

sourceHasAlpha (optional): Data Type: Boolean , Default Value: false

True if alpha channel is present in source color.

destHasAlpha (optional): Data Type: Boolean , Default Value: false

True if alpha channel is present in destination color.

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 ,
Sep 21, 2014 Sep 21, 2014
LATEST

Thanks Silly-V again for this answer. I got everything work now as I wanted with your help! Cheers!

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