验收20%
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
#target photoshop
|
||||
|
||||
app.displayDialogs = DialogModes.NO;
|
||||
|
||||
var createdDocument = null;
|
||||
var previousRulerUnits = app.preferences.rulerUnits;
|
||||
|
||||
function readJson(filePath) {
|
||||
var file = File(filePath);
|
||||
if (!file.exists) {
|
||||
throw new Error('Manifest does not exist: ' + filePath);
|
||||
}
|
||||
file.encoding = 'UTF8';
|
||||
if (!file.open('r')) {
|
||||
throw new Error('Unable to open manifest: ' + filePath);
|
||||
}
|
||||
var content = file.read();
|
||||
file.close();
|
||||
return eval('(' + content + ')');
|
||||
}
|
||||
|
||||
try {
|
||||
app.preferences.rulerUnits = Units.PIXELS;
|
||||
var manifest = readJson(JIAPU_A01_MANIFEST);
|
||||
var psdFile = File(JIAPU_A01_PSD);
|
||||
|
||||
if (psdFile.exists) {
|
||||
throw new Error('Refusing to overwrite existing PSD: ' + psdFile.fsName);
|
||||
}
|
||||
|
||||
createdDocument = app.documents.add(
|
||||
manifest.canvas.width,
|
||||
manifest.canvas.height,
|
||||
manifest.canvas.resolution,
|
||||
'JIAPU_A01_SCRIPT_SOURCE',
|
||||
NewDocumentMode.RGB,
|
||||
DocumentFill.TRANSPARENT
|
||||
);
|
||||
|
||||
for (var groupIndex = manifest.groups.length - 1; groupIndex >= 0; groupIndex--) {
|
||||
var groupSpec = manifest.groups[groupIndex];
|
||||
var group = createdDocument.layerSets.add();
|
||||
group.name = groupSpec.name;
|
||||
group.visible = groupSpec.visible;
|
||||
}
|
||||
|
||||
if (createdDocument.artLayers.length > 0) {
|
||||
createdDocument.artLayers[0].remove();
|
||||
}
|
||||
|
||||
var saveOptions = new PhotoshopSaveOptions();
|
||||
saveOptions.layers = true;
|
||||
createdDocument.saveAs(psdFile, saveOptions, true, Extension.LOWERCASE);
|
||||
createdDocument.close(SaveOptions.DONOTSAVECHANGES);
|
||||
createdDocument = null;
|
||||
} catch (error) {
|
||||
if (createdDocument !== null) {
|
||||
createdDocument.close(SaveOptions.DONOTSAVECHANGES);
|
||||
}
|
||||
throw error;
|
||||
} finally {
|
||||
app.preferences.rulerUnits = previousRulerUnits;
|
||||
}
|
||||
Reference in New Issue
Block a user