Updated to handle »No Color«.
// switch shape layer’s fill and stroke colors;
// 2024, use at your own risk;
if (app.documents.length > 0) {
var myDocument = activeDocument;
try {
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
var layerDesc = executeActionGet(ref);
var theFillColor = layerDesc.getList(stringIDToTypeID("adjustment")).getObjectValue(0).getObjectValue(stringIDToTypeID("color"));
var theStroke = layerDesc.getObjectValue(stringIDToTypeID("AGMStrokeStyleInfo"));
var fillEnabled = theStroke.getBoolean(stringIDToTypeID("fillEnabled"));
var strokeEnabled = theStroke.getBoolean(stringIDToTypeID("strokeEnabled"));
var theStrokeColor = theStroke.getObjectValue(stringIDToTypeID("strokeStyleContent")).getObjectValue(stringIDToTypeID("color"));
////////////////////////////////////
if (strokeEnabled == true) {
var desc19 = new ActionDescriptor();
var ref3 = new ActionReference();
ref3.putEnumerated( stringIDToTypeID( "contentLayer" ), stringIDToTypeID( "ordinal" ), stringIDToTypeID( "targetEnum" ) );
desc19.putReference( stringIDToTypeID( "null" ), ref3 );
var desc20 = new ActionDescriptor();
var idfillContents = stringIDToTypeID( "fillContents" );
var desc21 = new ActionDescriptor();
desc21.putObject( stringIDToTypeID( "color" ), stringIDToTypeID( "RGBColor" ), theStrokeColor/*desc22*/ );
var idsolidColorLayer = stringIDToTypeID( "solidColorLayer" );
desc20.putObject( idfillContents, idsolidColorLayer, desc21 );
var idstrokeStyle = stringIDToTypeID( "strokeStyle" );
var desc23 = new ActionDescriptor();
desc23.putInteger( stringIDToTypeID( "strokeStyleVersion" ), theStroke.getInteger(stringIDToTypeID( "strokeStyleVersion" )) );
desc23.putBoolean( stringIDToTypeID( "fillEnabled" ), true );
desc20.putObject( idstrokeStyle, idstrokeStyle, desc23 );
desc19.putObject( stringIDToTypeID( "to" ), stringIDToTypeID( "shapeStyle" ), desc20 );
executeAction( stringIDToTypeID( "set" ), desc19, DialogModes.NO );
} else {
var desc12 = new ActionDescriptor();
var ref3 = new ActionReference();
ref3.putEnumerated( stringIDToTypeID( "contentLayer" ), stringIDToTypeID( "ordinal" ), stringIDToTypeID( "targetEnum" ) );
desc12.putReference( stringIDToTypeID( "null" ), ref3 );
var desc13 = new ActionDescriptor();
var desc14 = new ActionDescriptor();
desc14.putInteger( stringIDToTypeID( "strokeStyleVersion" ), 2 );
desc14.putBoolean( stringIDToTypeID( "fillEnabled" ), false );
desc13.putObject( stringIDToTypeID( "strokeStyle" ), stringIDToTypeID( "strokeStyle" ), desc14 );
desc12.putObject( stringIDToTypeID( "to" ), stringIDToTypeID( "shapeStyle" ), desc13 );
executeAction( stringIDToTypeID( "set" ), desc12, DialogModes.NO );
};
////////////////////////////////////
if (fillEnabled == true) {
var desc8 = new ActionDescriptor();
var ref4 = new ActionReference();
ref4.putEnumerated( stringIDToTypeID( "contentLayer" ), stringIDToTypeID( "ordinal" ), stringIDToTypeID( "targetEnum" ) );
desc8.putReference( stringIDToTypeID( "null" ), ref4 );
var desc9 = new ActionDescriptor();
var desc10 = new ActionDescriptor();
var desc11 = new ActionDescriptor();
desc11.putObject( stringIDToTypeID( "color" ), stringIDToTypeID( "RGBColor" ), theFillColor );
desc10.putObject( stringIDToTypeID( "strokeStyleContent" ), stringIDToTypeID( "solidColorLayer" ), desc11 );
var idstrokeStyleVersion = stringIDToTypeID( "strokeStyleVersion" );
desc10.putInteger( idstrokeStyleVersion, 2 );
desc10.putBoolean( stringIDToTypeID( "strokeEnabled" ), true );
desc9.putObject( stringIDToTypeID( "strokeStyle" ), stringIDToTypeID( "strokeStyle" ), desc10 );
desc8.putObject( stringIDToTypeID( "to" ), stringIDToTypeID( "shapeStyle" ), desc9 );
executeAction( stringIDToTypeID( "set" ), desc8, DialogModes.NO );
} else {
// =======================================================
var desc10 = new ActionDescriptor();
var ref1 = new ActionReference();
ref1.putEnumerated( stringIDToTypeID( "contentLayer" ), stringIDToTypeID( "ordinal" ), stringIDToTypeID( "targetEnum" ) );
desc10.putReference( stringIDToTypeID( "null" ), ref1 );
var desc11 = new ActionDescriptor();
var idstrokeStyle = stringIDToTypeID( "strokeStyle" );
var desc12 = new ActionDescriptor();
desc12.putInteger( stringIDToTypeID( "strokeStyleVersion" ), 2 );
desc12.putBoolean( stringIDToTypeID( "strokeEnabled" ), false );
desc11.putObject( idstrokeStyle, idstrokeStyle, desc12 );
var idshapeStyle = stringIDToTypeID( "shapeStyle" );
desc10.putObject( stringIDToTypeID( "to" ), idshapeStyle, desc11 );
executeAction( stringIDToTypeID( "set" ), desc10, DialogModes.NO );
};
} catch (e) {alert ("no")}
};
... View more