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?
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");
}
Copy link to clipboard
Copied
VB.net
Dim strColorName="Black"
Dim oColor = oDocument.Swatches(strColorName).Color
Copy link to clipboard
Copied
Hmmh?
you get the color from the swatch.
But I think the OP wants to know the "swatch color from Art".
Or am I wrong?
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()