, ну, ну, сценарий < /p> < /p> < /p> < /p> < /p> < /p> < /p> < /P> < /p> < /p> < /p> < /p> < /p> < /p>
< /pript < /pript < /pript < /p> < /pript < /pript < /pript.#target photoshop
// === MAIN FUNCTION ===
function main() {
// === Step 1: Select the PSD ===
var docFile = File.openDialog("Select your PSD file", "*.psd");
if (!docFile) {
alert("No PSD file selected. Script cancelled.");
return;
}
// Open PSD and save reference
var psd = app.open(docFile);
// === Step 2: Select the PNG ===
var imgFile = File.openDialog("Select ONE PNG image", "*.png");
if (!imgFile) {
alert("No PNG image selected. Script cancelled.");
psd.close(SaveOptions.DONOTSAVECHANGES);
return;
}
// === Step 3: Process image ===
try {
// Save current preferences
var startRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
// Open image and unlock layer
var imgDoc = app.open(imgFile);
var layer = imgDoc.artLayers[0];
if (layer.isBackgroundLayer) {
layer.isBackgroundLayer = false;
layer.name = "Layer 0";
}
// === CRITICAL FIX: Duplicate and position BEFORE alert ===
var newLayer = layer.duplicate(psd, ElementPlacement.PLACEATBEGINNING);
// Calculate position (100px, 100px)
var xPos = 100;
var yPos = 100;
var xOffset = xPos - newLayer.bounds[0].value;
var yOffset = yPos - newLayer.bounds[1].value;
newLayer.translate(xOffset, yOffset);
// Force UI update
app.activeDocument = psd;
psd.activeLayer = newLayer;
app.refresh();
// Close source image
imgDoc.close(SaveOptions.DONOTSAVECHANGES);
// Restore preferences
app.preferences.rulerUnits = startRulerUnits;
// === Modified alert: Shows position and layer info ===
var result = confirm(
"
"Layer: " + newLayer.name + "\n\n" +
"Click OK to continue or Cancel to undo",
false,
"Placement Successful"
);
if (!result) {
// Undo if user cancels
executeAction(charIDToTypeID("Undo"), undefined, DialogModes.NO);
}
} catch(e) {
alert(" Error: " + e.message);
}
}
// Execute
main();
Подробнее здесь: https://stackoverflow.com/questions/796 ... t-document