Hi~
I am a developer focus on cep and extendscript for times. I found a bug in CC2022 when exporting layers.
I want to export a layer with gradient fill from PS in scripts, sample as below:
my steps in scrip are:
1. duplicate the layer to a new document
2. trim the transparent pixels in the new document
3. save the doucument with app.activeDocument.exportDocument api
and below are my script:
function duplicate() {
var desc1 = new ActionDescriptor();
var ref1 = new ActionReference();
ref1.putClass(app.stringIDToTypeID("document"));
desc1.putReference(app.stringIDToTypeID("null"), ref1);
var ref2 = new ActionReference();
ref2.putEnumerated(app.stringIDToTypeID("layer"), app.stringIDToTypeID("ordinal"), app.stringIDToTypeID("targetEnum"));
desc1.putReference(app.stringIDToTypeID("using"), ref2);
desc1.putInteger(app.stringIDToTypeID("version"), 5);
app.executeAction(app.stringIDToTypeID("make"), desc1, DialogModes.NO);
}
function trim() {
var desc1 = new ActionDescriptor();
desc1.putEnumerated( stringIDToTypeID( "trimBasedOn" ), stringIDToTypeID( "trimBasedOn" ), stringIDToTypeID( "transparency" ) );
desc1.putBoolean( stringIDToTypeID( "top" ), true );
desc1.putBoolean( stringIDToTypeID( "bottom" ), true );
desc1.putBoolean( stringIDToTypeID( "left" ), true );
desc1.putBoolean( stringIDToTypeID( "right" ), true );
executeAction( stringIDToTypeID( "trim" ), desc1, DialogModes.NO );
}
function output() {
var options = new ExportOptionsSaveForWeb();
options.format = SaveDocumentType.PNG;
options.PNG8 = false;
options.transparency = true;
options.interlaced = false;
app.activeDocument.exportDocument(new File(Folder.desktop.absoluteURI + "/demo.png"), ExportType.SAVEFORWEB, options);}
// run those actions
duplicate();
trim();
output();
these codes works all these years from CC2014 to CC2021, but breaks when in CC2022, layer contains gradient fills, lost it's effect, the output image is blank
I took all my efforts to make things right but have no success.
I have tried these ways:
1. replace app.activeDocument.exportDocument . api with AM executeAction( stringIDToTypeID( "export" ), desc1, DialogModes.NO ); no success.
2. do not trim the new document, the output layer shows right. but with transparent pixesl in it.
3. if I run those step functions isolately, it works fine.
4. I tried $.sleep(1000) to slow the process, no success.
I want to know if this is a bug or not, does anyone encounter with this issue and have an answer?
Please help...
I attach the script file and the sample psd, please have a try in you CC2022 to see the result
Archive.zip