Highlighted

Swatch Color From ART

Community Beginner ,
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

92

Likes

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

Swatch Color From ART

Community Beginner ,
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

93

Likes

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
Aug 02, 2020 0
Most Valuable Participant ,
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");
        }

 

 

 

Likes

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
Reply
Loading...
Aug 02, 2020 0
Enthusiast ,
Aug 03, 2020

Copy link to clipboard

Copied

VB.net

Dim strColorName="Black"

Dim oColor = oDocument.Swatches(strColorName).Color

Likes

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
Reply
Loading...
Aug 03, 2020 0
Most Valuable Participant ,
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?

 

Likes

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
Reply
Loading...
Aug 04, 2020 0
MilosR LATEST
Participant ,
Aug 06, 2020

Copy link to clipboard

Copied

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()

Likes

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
Reply
Loading...
Aug 06, 2020 0
Resources