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

Swatch Color From ART

Community Beginner ,
Aug 02, 2020 Aug 02, 2020

Copy link to clipboard

Copied

I need to get the swatch color from art using Visual Studio.

Please guide me, how to get the swatch color from Art?

TOPICS
SDK

Views

230

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
Adobe
Community Expert ,
Aug 02, 2020 Aug 02, 2020

Copy link to clipboard

Copied

This is "only" a "Javascript-answer".

Don't know if that really helps.

 

 

// required: one selected path item 
// regards pixxxelschubser
var aDoc = app.activeDocument;
if (aDoc.selection.length ==1 && aDoc.selection[0].typename == "PathItem") {
var pI = aDoc.selection[0];
var selSwatch = aDoc.swatches.getSelected();
if (selSwatch.length == 1) {
    alert("Swatch name: " + selSwatch[0].name);
    //alert("Swatch color: " + selSwatch[0].color);
    } else {
        alert("no swatch in use");
        }
    } else {
        alert("wrong selection");
        }

 

 

 

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

Copy link to clipboard

Copied

VB.net

Dim strColorName="Black"

Dim oColor = oDocument.Swatches(strColorName).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 ,
Aug 04, 2020 Aug 04, 2020

Copy link to clipboard

Copied

Hmmh?

@daitranthanhoa,

you get the color from the swatch.

 

But I think the OP wants to know the "swatch color from Art".

 

Or am I wrong?

 

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 ,
Aug 06, 2020 Aug 06, 2020

Copy link to clipboard

Copied

LATEST

I suppose you want fill color, not stroke color. Please have in mind that one art can contain more than one fill, and that fill can be pattern or gradient.

 

Here is quick example to get selected fill color in appearance panel, you will get AIColor, you can later check wether is it cmyk, rgb, gradient etc...

 

 

 

AIErr error;
AIPathStyle style;

error = sAIPathStyle->GetPathStyle(art, &style, NULL);

// check for errors here it should be kNoError (0)

if(style.fillPaint){

	// here you got AIColor struct, see SDK documentation for more detailed explanation 
	AIColor color = style.fill.color;

	// Example if it is CMYK
	if(color.kind == kFourColor){

		AIReal cyan = color.c.f.cyan;
		AIReal magenta = color.c.f.magenta;
		AIReal yellow = color.c.f.yellow;
		AIReal black = color.c.f.black;

	}

}

 

 

 

 

To get all fills and strokes you need to parse style using AI Style Parser and AI Style suites, iterate through paint fields and get color values. This is more complex option.

 

To find out swatch color you can use AISwatchListSuite::GetSwatchByColor()

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