Skip to main content
Participant
September 6, 2024
Question

PS scripting problem, script making bleed's

  • September 6, 2024
  • 1 reply
  • 262 views

Hello i want to have a script takat creates bleeds,

Usually when im dong this by hand I do this:
1. create naew layer and mae it "bleed", fill it witch bucket tool

2.Expand canvas s

3.Select bleed layer with CMD, clear it, reverse the selection an fill it with color

 

But i cant figure out how to do step 3. I can ony select the whole layer and not the only filed part

 

This is my code:

 

 

var bleedLayer = app.activeDocument.artLayers.add();
bleedLayer.name = "bleed";

bleedLayer.move(app.activeDocument.artLayers[0], ElementPlacement.PLACEBEFORE);

app.activeDocument.selection.selectAll();
app.activeDocument.selection.fill(app.foregroundColor);
app.activeDocument.selection.deselect();

var doc = app.activeDocument;
var originalWidth = doc.width;
var originalHeight = doc.height;
var newWidth = originalWidth + 10;
var newHeight = originalHeight + 10;
doc.resizeCanvas(newWidth, newHeight, AnchorPosition.MIDDLECENTER);

doc.activeLayer = bleedLayer;
doc.activeLayer = doc.artLayers.getByName("bleed");
doc.selection.load(doc.activeLayer.channels["Transparency"], SelectionType.REPLACE);
doc.selection.clear();
doc.selection.invert();
doc.selection.fill(app.foregroundColor);
doc.selection.deselect();
This topic has been closed for replies.

1 reply

c.pfaffenbichler
Community Expert
Community Expert
September 6, 2024

Could you please post screenshots with the pertinent Panels (Toolbar, Layers, Options Bar, …) visible to illustrate the process? 

 

loadTransparency (false);
////// load transparency //////
function loadTransparency (theInvert) {
// =======================================================
var idsetd = charIDToTypeID( "setd" );
    var desc3 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
        var ref2 = new ActionReference();
        var idChnl = charIDToTypeID( "Chnl" );
        var idfsel = charIDToTypeID( "fsel" );
        ref2.putProperty( idChnl, idfsel );
    desc3.putReference( idnull, ref2 );
    var idT = charIDToTypeID( "T   " );
        var ref3 = new ActionReference();
        var idChnl = charIDToTypeID( "Chnl" );
        var idChnl = charIDToTypeID( "Chnl" );
        var idTrsp = charIDToTypeID( "Trsp" );
        ref3.putEnumerated( idChnl, idChnl, idTrsp );
    desc3.putReference( idT, ref3 );
    desc3.putBoolean(charIDToTypeID("Invr"), theInvert);
executeAction( idsetd, desc3, DialogModes.NO );
};
Participant
September 9, 2024

Hello! Thank you very much it works witch your metchod!

I'm coping my code here so if anyone in the future needs something similar there's an answer

// Funkcja do ładowania przezroczystości jako zaznaczenia
function loadTransparency(theInvert) {
    var idsetd = charIDToTypeID("setd");
    var desc3 = new ActionDescriptor();
    var idnull = charIDToTypeID("null");
    var ref2 = new ActionReference();
    var idChnl = charIDToTypeID("Chnl");
    var idfsel = charIDToTypeID("fsel");
    ref2.putProperty(idChnl, idfsel);
    desc3.putReference(idnull, ref2);
    var idT = charIDToTypeID("T   ");
    var ref3 = new ActionReference();
    var idChnl = charIDToTypeID("Chnl");
    var idTrsp = charIDToTypeID("Trsp");
    ref3.putEnumerated(idChnl, idChnl, idTrsp);
    desc3.putReference(idT, ref3);
    desc3.putBoolean(charIDToTypeID("Invr"), theInvert);
    executeAction(idsetd, desc3, DialogModes.NO);
}

// Tworzenie nowej warstwy i nadanie jej nazwy "bleed"
var bleedLayer = app.activeDocument.artLayers.add();
bleedLayer.name = "bleed";

// Przeniesienie warstwy "bleed" na samą górę
bleedLayer.move(app.activeDocument.artLayers[0], ElementPlacement.PLACEBEFORE);

// Wypełnienie warstwy "bleed" za pomocą narzędzia Paint Bucket Tool
app.activeDocument.selection.selectAll();
app.activeDocument.selection.fill(app.foregroundColor);
app.activeDocument.selection.deselect();

// Powiększenie rozmiaru canvasu o 10 mm z każdej strony
var doc = app.activeDocument;
var originalWidth = doc.width;
var originalHeight = doc.height;
var newWidth = originalWidth + 10; // 10mm to pixele
var newHeight = originalHeight + 10;
doc.resizeCanvas(newWidth, newHeight, AnchorPosition.MIDDLECENTER);

// Zaznaczenie widocznych elementów na warstwie "bleed"
doc.activeLayer = bleedLayer;
loadTransparency(false); // Załaduj nieprzezroczyste piksele jako zaznaczenie

// Wyczyszczenie zaznaczonych pikseli na warstwie "bleed"
doc.selection.clear(); 

// Odwrócenie zaznaczenia, aby zaznaczyć resztę
doc.selection.invert(); 

// Wypełnienie zaznaczenia kolorem pierwszego planu
doc.selection.fill(app.foregroundColor);

// Odznaczenie zaznaczenia
doc.selection.deselect();